VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type i

by Jef van de Molengraft (1 Submission)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 13th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type is a mailto: then return the username as

API Declarations



Global URLType As String
Global URLPort As Integer
Global URLDomainName As String
Global URLPath As String
Global URLFileName As String
Global URLUserName As String

Public T As Integer

Global URL As String

Rate Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type i



    ' This Sub routine will analize the URL given.
    ' It will set the global variables as specified above.
    ' Please send comments or improvement tips to:
    ' [email protected]

    URLType = ""
    URLPort = 0
    URLDomainName = ""
    URLPath = ""
    URLFileName = ""
    URLUserName = ""

    GetType
    
    Select Case URLType
    
        Case "HTTP", "FTP"
            GetPortNumber
            GetDomainName
            GetFileName
            GetPath
        
        Case "RELATIVE"
            URLDomainName = ""
            GetFileName
            GetPath
            
        Case "EMAIL"
            GetDomainName
        
    End Select

End Sub
Private Sub GetType()
    ' Gets the type of the URL
    
    URLType = "RELATIVE" ' By default it's a relavite link
    
    If Left$(URL, 7) = "http://" Then
        URLType = "HTTP"
        URL = Right$(URL, Len(URL) - 7)
    End If
    
    If Left$(URL, 6) = "ftp://" Then
        URLType = "FTP"
        URL = Right$(URL, Len(URL) - 6)
    End If
       
    If Left$(URL, 7) = "mailto:" Then
        URLType = "EMAIL"
        URL = Right$(URL, Len(URL) - 7)
    End If
     
End Sub
Private Sub GetPortNumber()
    ' Get the Portnumber
    
    Dim GetIt As Boolean
    Dim StringPort As String
    
    If URLType = "HTTP" Then URLPort = 80
    If URLType = "FTP" Then URLPort = 21
    
    For T = 1 To Len(URL)
        Select Case Mid$(URL, T, 1)
        
        Case "/"
            Exit For
        
        Case ":"
            GetIt = True
        
        Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
            If GetIt = True Then StringPort = StringPort + Mid$(URL, T, 1)
            
        Case Else
            StringPort = ""
        
        End Select
    Next T
    
    If StringPort <> "" Then
        URL = Replace(URL, ":" & StringPort, "")
        URLPort = CInt(StringPort)
    End If

End Sub
Private Sub GetDomainName()
    Dim Slash As Boolean
    
    Slash = False

    If URLType = "HTTP" Or URLType = "FTP" Then
        For T = 1 To Len(URL)
            If Mid$(URL, T, 1) = "/" Then
                If Slash = False Then
                    URLDomainName = Left$(URL, T - 1)
                    Slash = True
                    URL = Right$(URL, Len(URL) - T + 1)
                End If
                Exit For
            End If
        Next T
        
        If Slash = False Then
            URLDomainName = URL
            URL = ""
        End If
    End If
    
    If URLType = "EMAIL" Then
        For T = 1 To Len(URL)
            If Mid$(URL, T, 1) = "@" Then
                URLDomainName = Right$(URL, Len(URL) - T)
                URLUserName = Left$(URL, T - 1)
                URL = ""
                Exit For
            End If
        Next T
    End If
    
End Sub
Private Sub GetFileName()
    Dim filerec As Boolean
    
    If URL <> "" Then
        For T = Len(URL) To 1 Step -1
            Select Case Mid$(URL, T, 1)
    '            Case ")", "(", "?", "@", "'", "+", "[", "]", "{", "}", "%", "$", "!", "*", "#"
    '                Exit For
                Case ".", ")", "(", "?", "@", "'", "+", "[", "]", "{", "}", "%", "$", "!", "*", "#"
                    filerec = True
                Case "/"
                    If filerec = True Then
                        URLFileName = Right$(URL, Len(URL) - T)
                        URL = Left$(URL, T)
                    Else
                        URLFileName = ""
                    End If
                    Exit For
                Case Else
                    If T = 1 Then
                        If filerec = True Then
                            If Left$(URL, 1) = "/" Then
                                URLFileName = Right$(URL, Len(URL) - T)
                                URL = "/"
                            Else
                                URLFileName = URL
                                URL = ""
                            End If
                        Else
                            URLFileName = ""
                        End If
                    End If
            End Select
        Next T
    Else
        URLFileName = ""
    End If
End Sub
Private Sub GetPath()
    
    If URL <> "" Then
        URLPath = URL
    Else
        URLPath = ""
    End If
    
End Sub



Download this snippet    Add to My Saved Code

Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type i Comments

No comments have been posted about Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type i. Why not be the first to post a comment about Analize a URL and return Type, Domainname, Port, Path and File in seperate variables. If the type i.

Post your comment

Subject:
Message:
0/1000 characters