[thelist] asp/vb - array problem

Ken Schaefer ken at adOpenStatic.com
Thu Dec 18 18:04:15 CST 2003


Why aren't you storing these things in some kind of collection (eg a
hashtable)?
Then, you can use looping/iteration constructs to change things.

<%
For Each Item in myCollectionThingie
    If Item.Value = 'on' then
        Item.Value = -1
    Else
        Item.Value = 0
    End If
Next
%>

In answer to your question (why isn't this working as I expect), your code
is currently creating an array, and the *values* of the variables are being
passed into the array as the elements *not* the original variables. So, it's
a ByVal copy, not a ByRef copy (the values are copied, not a reference to
the original type).

Cheers
Ken

Microsoft MVP - Windows Server (IIS)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Dunstan Orchard" <dunstan at 1976design.com>
Subject: [thelist] asp/vb - array problem


: Can anyone help me out with  a bit of ASP/VB please?
:
: I have a bunch of variables (somtimes 30 or more), with values of either
: 'on' or ''. I need to take those values, and change them into '-1' and
'0's.
:
: I thought the best way was to smack them all into an array and then loop
: through the array altering them one at a time.
:
: However, I'm confused as to how to do this. The code below seems to
: work, in that the values get checked and altered, but the values are
: only altered for the variables _inside_ the array. If I check, say
: 's4ACE' later on in the page, then it still has its original value.
:
: ***************************************
: Dim aCheckboxes
: aCheckboxes = Array(s4ACE, s4ACSM, s4AFAA, s4APTA, s4NATA, s4Other,
: s5AAHPERD, s5ACSM, s5AFAA, s5APTA, s5IHRSA, s5NATA, s5Other,
: s7ADMINISTRATION, s7AT, s7EDUCATOR, s7EXPHYS, s7HLTHCLUB, s7PERSTRAIN,
: s7PTHER, s7RESRCH, s7SPRTCOACH, s7SnCCOACH, s7STUDENT, s7Other, s10AFQ,
: s10AJSM, s10ATHBUS, s10BFS, s10CLUBUSINT, s10CLBIND, s10FITMGMT,
: s10IDEA, s10JRNLAT, s10JOSPT, s10MSSE, s10NATA, s10NCAA, s10PnSPTS,
: s10SCHOLCH, s10TnC, s10Other)
:
: Dim i
: For i = 0 To UBound(aCheckboxes)
:   If aCheckboxes(i) = "on" Then
:    aCheckboxes(i) = -1
:   ElseIf aCheckboxes(i) = "" Then
:    aCheckboxes(i) = 0
:   End If
:
: ' AS THIS FINISHES I NEED THE VALUE OF THE VARIABLE TO BE ALTERED SO I
: CAN USE IT LATER ON, WITHOUT HAVING TO CALL IT FROM WITHIN THE ARRAY
: Next
: ***************************************
:
: Does anyone have any ideas as to how I can do what I want?
:
: Thanks very much,
:
: - Dunstan



More information about the thelist mailing list