Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two dimension all array going awry

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
0
0
GB
A dynamic two dimension all array not quite working out.....



dim arrNewChoice

While Not RS.EOF

Select Case iChoice

Case 1
Response.Write(strChoice)
Case 2
Response.Write(strChoice)
Case 3
Response.Write(strChoice)

Case Else

Redim arrNewChoice(1,d)

arrNewChoice(0,d) = RS("choicePath")
arrNewChoice(1,d) = RS("choiceName")

Redim Preserve arrNewChoice(1,d)

d = clng(d)+1

End Select

RS.MoveNext
Wend

'writing out

Dim a

For a = 0 to UBound(arrNewChoice,2)

Response.Write(arrNewChoice(0,a) & arrNewChoice(1,a))

Next



If there were two 'case else' choices these appear as:

elsechoice 1 = --blank--
elsechoice 2 = new choice two

if three

elsechoice 1 = --blank--
elsechoice 2 = --blank--
elsechoice 3 = new choice three

So only the last array variable is being preserved. Where am I going wrong?


TIA

"Away from the actual ... everything is virtual"
 
Tried that but if I preserve the first redim it just gives me an error

"Away from the actual ... everything is virtual"
 
>[tt]dim arrNewChoice[/tt]
Dynamic?
dim arrNewChoice[red]()[/red]


 
Tried putting the redim before the initial loop entry but again it just gave me errors including 'out of range'

The arrNewChoice() made no difference to performance.

By the way, thanks for all your input.

"Away from the actual ... everything is virtual"
 
>The arrNewChoice() made no difference to performance
You're arguing against language definition.
 
>You're arguing against language definition.<
oops no sorry that came out wrong. Quite right - amended my script but it didn't make it work as I hoped.

>Just a guess but it's probably because you redim twice in the loop, one without preserve<
Found the way to make it work with just one redim preserve.


dim arrNewChoice()
dim d
d=0

While Not RS.EOF

Select Case iChoice

Case 1
Response.Write(strChoice)
Case 2
Response.Write(strChoice)
Case 3
Response.Write(strChoice)

Case Else

d = clng(d)+1

Redim arrNewChoice(1,d)

arrNewChoice(0,d-1) = RS("choicePath")
arrNewChoice(1,d-1) = RS("choiceName")


End Select

RS.MoveNext
Wend

'writing out

Dim a

For a = 0 to (UBound(arrNewChoice,2)-)

Response.Write(arrNewChoice(0,a) & arrNewChoice(1,a))

Next

Now works perfectly

again thanks.

&quot;Away from the actual ... everything is virtual&quot;
 
sorry should have read ...

Dim a

For a = 0 to (UBound(arrNewChoice,2)-1)

Response.Write(arrNewChoice(0,a) & arrNewChoice(1,a))

Next

&quot;Away from the actual ... everything is virtual&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top