INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Identify string within array item

Identify string within array item

(OP)
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.

RE: Identify string within array item

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

RE: Identify string within array item

(OP)
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.

RE: Identify string within array item

(OP)
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 

RE: Identify string within array item

(OP)
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

RE: Identify string within array item

Quote:

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.

http://www.4guysfromrolla.com/webtech/102898-1.sht...

Chris.

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

RE: Identify string within array item

(OP)
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...

RE: Identify string within array item

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 (http://www.devguru.com/technologies/VBScript/14177) 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

RE: Identify string within array item

(OP)
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

RE: Identify string within array item

(OP)
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 

%> 

RE: Identify string within array item

(OP)
I think I have managed to get it working using a filter.

RE: Identify string within array item

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 --> vbscript

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 --> vbscript

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

RE: Identify string within array item

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close