Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ARRAY trouble shooting

Posted on 2011-03-24
3
Medium Priority
?
378 Views
Last Modified: 2012-05-11
I have a string that is passed through a web service.

paytxncode, I use the ASP Function split , to split it up with the & sign and we always get 8 values.

Problem is if an incorrect value is based in the web service, we get back a string with only 2 items.

How do I code to make sure the page does not fail on errors.

Here is what I have written already

ptbc=Split (paytxncode,"&") ' Once Split we get 8 values in the Array

if ISNULL(ptbc(2)) then

    ' Only 2 values in the array sent back
        rspcode = ptbc(0)
        rspdesc = ptbc(1)

        rspcodetext = Split(rspcode,"=")
        'Response.Write "<p> <b>RESPONSE CODE </b>: " & rspcodetext(1) & "<p>"
        rspdesctext = Split(rspdesc,"=")
        'Response.Write "<p> <b>RESPONSE DESCRIPTION </b>: " & rspdesctext(1) & "<p>"

    else
    'Normal 8 values
        transtime = ptbc(0)
        pan = ptbc(1)
        froacc = ptbc(2)
        toacc = ptbc(3)
        paytxncode = ptbc(4)
        appamt = ptbc(5)
        rspcode = ptbc(6)
        rspdesc = ptbc(7)

End if
0
Comment
Question by:souldj
3 Comments
 
LVL 17

Assisted Solution

by:wobbled
wobbled earned 800 total points
ID: 35205278
Why don't you just use the UBound function to check the upper boundry of the number of items in an array first, remember that arrays start at 0

If UBOUND(ptbc) = 1 THEN
' repeat or error handle

Else

'rest of your code


End If
0
 
LVL 2

Expert Comment

by:khaaz
ID: 35205294
With ubound function you could be sure that you have 8 items :

if Ubound(ptbc)<> 8 then
    response.write "error !"
    else
    response.write "ok"
end if

Open in new window

0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 1200 total points
ID: 35205298
check for the arraylength which is good rather than check for null
array indices start at 0, so if UBound returns 1 there are 2 elements.

try this

uBound(myArray)
ptbc=Split (paytxncode,"&") ' Once Split we get 8 values in the Array

if (uBound(ptbc) = 1) then

    ' Only 2 values in the array sent back
        rspcode = ptbc(0)
        rspdesc = ptbc(1)

        rspcodetext = Split(rspcode,"=")
        'Response.Write "<p> <b>RESPONSE CODE </b>: " & rspcodetext(1) & "<p>"
        rspdesctext = Split(rspdesc,"=")
        'Response.Write "<p> <b>RESPONSE DESCRIPTION </b>: " & rspdesctext(1) & "<p>"

    else
    'Normal 8 values
if (uBound(ptbc) = 7) then
        transtime = ptbc(0)
        pan = ptbc(1)
        froacc = ptbc(2)
        toacc = ptbc(3)
        paytxncode = ptbc(4)
        appamt = ptbc(5)
        rspcode = ptbc(6)
        rspdesc = ptbc(7)
end if

End if
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question