Session Variables and Array problem

Results 1 to 2 of 2

Thread: Session Variables and Array problem

  1. #1
    Join Date
    Dec 1969

    Default Session Variables and Array problem

    Hi there...I&#039;m a beginner and having a problem with session variables which are arrays. <BR><BR>I gave myself an exercise to create an application that will allow a user to choose a team of PGA golfers in order to predict who will do the best...The code I am having a problem with is a page in which I iterate through until I hit a session counter variable of 10. (I know that session variables might not be the best solution for this...but it was to give me practice). <BR><BR>The problem is when I assign the player ID to the array which I have made a session variable. I then try and loop at it, but the isArray code seems to always be false..even though the value initially gets assigned....I must be missing somthing stupid...any help would be appreciated....Thanks...Jonathan <BR><BR>Here a watered version of the code... <BR><BR>&#060;% <BR> dim playernum <BR> dim iCounter <BR> iCounter = Session("iCount") <BR><BR>&#039; Request the Player ID Number <BR> playernum = Request.Form("pgaplayers") <BR><BR> If Not isNumeric(Session("iCount")) OR isNull(Session("iCount")) OR isEmpty(Session("iCount")) Then <BR> Session("iCount") = 1 <BR> Else <BR>&#039; Increment the counter to the next player choice <BR> Session("iCount") = Session("iCount") + 1 <BR> End If <BR><BR> If isNumeric(playernum) Then <BR> Response.Write "Adding Player" <BR> Response.Write "Player Num -" & playernum <BR> Response.Write "iCounter" & iCounter <BR> Session("player(iCounter)") = playernum <BR><BR> Dim iLoop <BR><BR>&#039; THIS IS THE PROBLEM <BR> If isArray(Session("player")) Then <BR> Response.Write "Begin Loop" <BR> For iLoop = LBound(Session("player")) _ <BR> to UBound(Session ("player")) <BR> Response.Write Session("player(iLoop)") <BR> Next <BR> Response.Write "End Loop" <BR> End If <BR><BR> End If <BR><BR>%&#062; <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Session Variables and Array problem

    OK, even though you posted above, I am gonna answer anyway. First why is your counter starting at 1, all arrays must start with a zero value. Second I dont see you adding anything to the array. It looks as if you are only adding 1 value<BR>Try this<BR>count = 0<BR>dim namesadded()<BR>WHILE count &#060;= amountofglofers<BR> namesadded(count) = request.Form("whatever") &#039; add a golfer to the array<BR> count = count + 1<BR>WEND<BR>&#039;Now you got the array get the values<BR>count = 0 &#039; set count back to zero<BR>Response.Write "You chose<BR>"<BR>WHILE count &#060;= uBound(namesadded)<BR> Response.Write namesadded(count)&"<BR>"<BR> count = count + 1<BR>WEND<BR><BR>This is quick so not sure if syntax is correct but hope this least something to qwork off of

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts