Solved

ARRAY trouble shooting

Posted on 2011-03-24
3
372 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 200 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 300 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

I was asked if I could set up a fax machine so that incoming faxes were delivered to people's Exchange inboxes and so that they could send faxes from their desktops without needing to print the document first.  I knew it was possible but I had no id…
You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now