[VBS] Decomposition of a URL address
Posted: Thu Oct 03, 2013 1:18 am
Hi
I want to make a decomposition of a URL
So I have this Vbscript below :
My problem is when I type eg URL = "http://www.google.com" ==> the script returns me an error in line N ° 18 "incorrect procedure or argument"
However, when I type this URL = "http://www.laltruiste.com:8080/coursasp ... tml#anchor" ==> then it works 5/5
So I'm looking how to get around this error ?
I want to make a decomposition of a URL
So I have this Vbscript below :
My problem is when I type eg URL = "http://www.google.com" ==> the script returns me an error in line N ° 18 "incorrect procedure or argument"
However, when I type this URL = "http://www.laltruiste.com:8080/coursasp ... tml#anchor" ==> then it works 5/5
So I'm looking how to get around this error ?
VBScript Code
Double-click the code block to select all.Option Explicit Dim adress,result,Title '***************************************************************** 'Fonction pour ajouter des guillemets dans une variable Function DblQuote(Str) DblQuote = Chr(34) & Str & Chr(34) End Function '***************************************************************** Function Search(Pattern,MyString) Dim objet Dim correspondance Dim collection Set objet = New RegExp objet.Pattern = Pattern objet.IgnoreCase = True objet.Global = True Set collection = objet.Execute(MyString) Set correspondance = collection(0) result = "Protocol = " & DblQuote(correspondance.SubMatches(0)) & VbCRLF & vbCrLf _ & "Domain = " & DblQuote(correspondance.SubMatches(1)) & VbCRLF & vbCrLf _ & "Port = " & DblQuote(correspondance.SubMatches(2)) & vbCrLf & vbCrLf _ & "Folder = " & DblQuote(correspondance.SubMatches(3)) & VbCRLF& vbCrLf _ & "File = " & DblQuote(correspondance.SubMatches(4)) & VbCRLF& vbCrLf _ & "Anchor = "& DblQuote(correspondance.SubMatches(5)) Search = result End Function '***************************************************************** 'adress = "http://www.laltruiste.com:8080/coursasp ... html#ancre" adress = InputBox( "Please input the http or the https address.", " What makes up a Url?","http://www.laltruiste.com:8080/coursasp ... html#ancre") result = Search("(\w+):\/\/([^/:]+):?(\d*)?\/(.*[^.])\/(\w+.\w+)#?(\w+)?",adress) Title = "Decomposition of a URL address" MsgBox Title & "(Uniform Resource Locator ) ==> URL : " & DblQuote(adress) & vbCrLf & vbCrLf _ & result,64,TitleThnak you !