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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify string within array item

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
GB
Hello. On my website I receive an array of payment data.

The following code:

Code:
For Each queryStringItem in queryStringData
Response.Write queryStringItem
Response.Write "<br />"
Next

Produces the following (fake payment info):
Code:
VendorTxCode=83029
VPSTxId={20CED47D}
Status=OK
StatusDetail=Successful.
TxAuthNo=13981
AVSCV2=DATA NOT CHECKED
AddressResult=NOTPROVIDED
PostCodeResult=NOTPROVIDED
CV2Result=NOTPROVIDED
GiftAid=0
3DSecureStatus=NOTCHECKED
CardType=MC
Last4Digits=1954
Surcharge=0.05
DeclineCode=00
Amount=1.05
BankAuthCode=035892

I'm also able to display indidividual items from within this array. They are numbered upwards from 0.

So:

Response.Write queryStringData(0) writes: VendorTxCode=83029

Response.Write queryStringData(3) writes: StatusDetail=Successful.

e.t.c

What I need to do however is search the array and find out which item contains a particular string. The items within the array are not always received in the same order so I cannot simply always choose item 5 for example.

If we take BankAuthCode it is currently in position 16. Sometimes however it appears in position 15.

Am I able to search the array for the string BankAuthCode and then identify which item that string is in?

If I'm able to identify the string in item 15 I can then set it as my new variable:

e.g.

Code:
***Find "BankAuthCode" in Array
NewVariable = queryStringData(15)

I hope that is clear. Appreciate any responses.
 
Request.QueryString("NameOfKey")

Where it appears in the Request Collection does not matter.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris

I have tried

NewVar = Request.queryStringData("VendorTxCode")

I have also tried

NewVar = Request.QueryString("VendorTxCode")

to try and grab VendorTxCode=83029 from the query string but it just appears blank.
 
I should also mention that the data is encrypted and in order to display the data I use the following:

Code:
If Request.QueryString("crypt") <> "" Then
Dim decryptedData
decryptedData = DecodeAndDecrypt(Request.QueryString("crypt"))
Dim queryStringData
queryStringData = Split(decryptedData, "&")
End If

For Each queryStringItem in queryStringData
Response.Write queryStringItem
Response.Write "<br />"
Next
 
Yes I definitely cannot use your simple method because:

Request.QueryString is a very long encrypted line of code.

I can only locate the name of the item after it has been decrypted
 
is a very long encrypted line of code.

Okay, So you are decrypting the data into an array not just using the query string as a associative array. (known as a dictionary object) THAT just might have been worth mentioning explicitly in the first post then.

In that case, you simply loop through the array, test the key name and pass the corresponding value to your variable when you get a match.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Chris I think I understand but would this require me to add all the decrypted items to the 'dictionary' first and then loop through the dictionary to find which worded key I want?

If that's the case I wouldn't know how to do that...
 
Your code must already be loading the data into a dictionary (queryStringData) and you ARE already looping through it with the

for each [item] in [object]


it's simply a matter of having a Select ... Case ... End Case ( or a If ... Then ... Elseif ... End if (see the first link) in the loop to set the variables you need to.

Select Case is a much neater and extensible construct should you need to add more values in the future.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Chris I'm really trying to get this working but am struggling.
After numerous attempts I'm left with:

Code:
If Request.QueryString("crypt") <> "" Then
Dim decryptedData
decryptedData = DecodeAndDecrypt(Request.QueryString("crypt"))
Dim queryStringData
queryStringData = Split(decryptedData, "&")
End If

For Each queryStringItem in queryStringData
Response.Write queryStringItem
Response.Write "<br />"
Next

Select Case queryStringItem
Case "VendorTxCode" = NewVariable
End Select

Response.Write NewVariable

the code complies but NewVariable is empty

 
I'm now just trying to locate VendorTxCode within my array.

The code complies with no errors but Helloooo doesn't display so I'm obvsiously doing something wrong:

Code:
<%

If Request.QueryString("crypt") <> "" Then
Dim decryptedData
decryptedData = DecodeAndDecrypt(Request.QueryString("crypt"))
Dim queryStringData
queryStringData = Split(decryptedData, "&")
End If

For Each queryStringItem in queryStringData
Response.Write queryStringItem
Response.Write "<br />"
Next

Set queryStringData = CreateObject("Scripting.Dictionary")

If queryStringData.Exists ("VendorTxCode") Then
Response.Write "Hellooooo"
End If 

%>
 
I think I have managed to get it working using a filter.
 
Ok I probably misinterpreted what your decode was doing,

So after a "proper" look, it seems to throw out a series of strings with the key/value separated by the '=' sign, so if yes is the answer a "Split()" is needed to extract the key from the value into a

So;
Code:
For Each queryStringItem in queryStringData
keyval = split(queryStringItem,'=')
	select case keyval(0)
		case = "VendorTxCode"
			'set your variable from keyval(1)
		case = "BankAuthCode"
			' set another variable from keyval(1)
		case else
			' do whatever you want as a not matched event
	end select
Next
or as a function

Code:
function getQueryValue(p_item, p_valrequired)
keyval= split(p_item,'=')
	if keyval(0) = p_valrequired
		getQueryValue = keyval(1)
	else
		getQueryValue = false
	end if
Not actually tested because I don't run any Windows machines to test on.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Looks good Chris, I was along the right lines (sheepish grin)...

What I ended up doing was something like this:

Code:
var1= "VendorTxCode"
filter1 = Filter(queryStringData,var1)
For Each item In filter1
VendorTxCode = item
Next

This gave me a similar result and allowed me to use the Vendor Transaction Code as a variable VendorTxCode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top