Navigation: home » code » geturlinfo
Table of Contents

GetURLInfo() (VB Function)

This is a function that takes a URL and returns various information about it, such as the hostname, port, requested file etc. This code needs to go into a module as it is a Public Function that returns a user-defined type. The code doesn’t attempt to do any sort of checking on the URL that is passed, it assumes it is valid.

Thanks to Richard Smith for noticing that the code didn’t include support for anchors (#fragment) that can appear in a URL. This was corrected on 05/02/03.

Usage:

MsgBox GetURLInfo("http://edeca.net").Hostname
' Returns "edeca.net"
 
MsgBox GetURLInfo("ftp://ftp.domain.com:21/myfile.exe").Port
' Returns "21"

Screenshots

Download

The files available for this release are below.

File Description
modURLInfo.basGetURLInfo Module - The Visual Basic module file containing the function.
URLInfo.zipExample project - A zipfile containing a sample project using the above code, and a compiled demo exe.