Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please take a look, small mistake but can't find the solution!!! 1

Status
Not open for further replies.

cm80

Technical User
May 3, 2001
85
US
Could someone please take a look at this code. I think I have a small mistake somewhere but I am not sure where:

Function:
Function GetValue(Querystring, Name)
'Querystrings are broken up into a series of name value pairs.
'The purpose of this function is to return a value corresponding to the name passed as a parameter
Dim strQueryString, strName, valueStart, valueEnd, strValue
strQueryString = QueryString
strName = Name

'starting position of the value
valueStart = InStr(1, strQuerystring, strName)+Len((strName) + 1)
'get the location of the '&' after the Value
valueEnd = InStr(valueStart, strQuerystring, "&")
'get the value
strValue = Mid(strQuerystring, valueStart, valueEnd - valueStart)

GetValue = strValue
End Function

Querystring:
deviceid=0.2268606658.587869489&zipcode=00000&Fund=FFTN&asp=modules/OH/default.asp

If I pass 'Fund' as the name parameter what I expect:
FFTN

What I am actually getting:
eviceid=0.2268606658.587869489


I think I may have the wrong syntax for using the Len statement but I have tried it loads of different ways and can't figure it out.
Any help would be appreciated,
Thank You
 
Hello, cm80.

Here is the revision script.

Option Explicit
Dim string1, string2, result

string1 = "0.2268606658.587869489&zipcode=00000&Fund=FFTN&asp=modules/OH/default.asp"
string2 ="Fund"
result = GetValue(string1,string2)
WScript.Echo result

string1 = "0.226860665de=00000&Fund=fasdfadfdfadfafFFTNWXYZABC&asp=adfadfmodules/OH/default.asp"
string2 ="Fund"
result = GetValue(string1,string2)
WScript.Echo result

WScript.Quit

'---------------------------------------
Function GetValue(Querystring, Name)
'Querystrings are broken up into a series of name value pairs.
'The purpose of this function is to return a value corresponding to the name passed as a parameter

Dim strQueryString, strName, valueStart, valueEnd, strValue
strQueryString = QueryString
strName = Name

'starting position of the value
'valueStart = InStr(1, strQuerystring, strName)+Len((strName) + 1)
valueStart = InStr(1, strQuerystring, strName) + Len(strName) + 1
'get the location of the '&' after the Value
'valueEnd = InStr(valueStart, strQuerystring, "&")
valueEnd = InStrRev(strQuerystring, "&") -1
'get the value
'strValue = Mid(strQuerystring, valueStart, valueEnd - valueStart)
strValue = Mid(strQuerystring, valueStart, valueEnd - valueStart +1)

GetValue = strValue
End Function
'---------------------------------------
 
Thanks anyway but I figured it out.
The problem was the way I was passing the parameters, I never put the 'Name' parameter in ""
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top