Solved

ARRAY trouble shooting

Posted on 2011-03-24
3
369 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

763 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

11 Experts available now in Live!

Get 1:1 Help Now