Solved

ARRAY trouble shooting

Posted on 2011-03-24
3
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
Suggested Courses

623 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