| This module will let you read & write URL files (or Internet website shortcuts): Option Explicit 'Declare all variables Public Function WriteURL(ByVal Filename As String, ByVal URL As String) On Error GoTo ErrorHandler Dim FileNumber As Integer 'Take out any spaces Filename = Trim(Filename) 'Add .URL if it is not there If Right(Filename, 4) <> ".URL" Then Filename = Filename & ".URL" 'Find a free file number FileNumber = FreeFile 'Open the file Open Filename For Output As #FileNumber 'Output the shortcut Print #FileNumber, "[InternetShortcut]" Print #FileNumber, "URL = " & URL 'Close the file Close #FileNumber Exit Function ErrorHandler: Close #FileNumber End Function 'Gets the URL from a *.URL file Public Function GetURL(ByVal Filename As String) As String On Error GoTo ErrorHandler Dim TempVar As String Dim Found As Integer Dim FileNumber As Integer 'Take out any spaces Filename = Trim(Filename) 'Add .URL if it is not there If Right(Filename, 4) <> ".URL" Then Filename = Filename & ".URL" FileNumber = FreeFile Open Filename For Input As #FileNumber 'Get all the text in the file Input(LOF(FileNumber), TempVar) Close #FileNumber 'Find the URL = bit Found = InStr(1, TempVar, "URL =", vbTextCompare) 'If it is found If Found > 0 Then 'Remove the URL = GetURL = Mid(TempVar, Found + 5) 'If it isn't found Else 'Try finding it without the space between URL & = Found = InStr(1, TempVar, "URL=", vbTextCompare) 'If it is found Remove the URL= before it If Found > 0 Then GetURL = Mid(TempVar, Found + 4) End If 'Take out any spaces in the URL GetURL = Trim(GetURL) Exit Function ErrorHandler: Close #FileNumber End Function 'Find a free file number FileNumber = FreeFile 'Open the file for input Open Filename For Input As #FileNumber 'Return the file's contents OpenText = Input(LOF(FileNumber), FileNumber) 'Close the file Close #FileNumber To use type something like: Call WriteURL("C:\Windows\Desktop\www.My WebSite.url", "http://www.rickmusic.co.uk") Or: Label1.Caption = GetURL("C:\Windows\Desktop\www.My WebSite.url") Etc. |
Reading & Writing URLs |
Express News India | Freelance ecommerce web development India