ecommerce web developer development freelance website designer India
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

901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

Express News India | Freelance ecommerce web development India