Arrays?

macca

Member
Joined
Mar 3, 2005
Messages
7
Programming Experience
Beginner
I have a variable "nextnum", nextnum could have a value of 1,2,3,4,5,6, or 7 all the way to 50.
Depending on the value of nextnum I want to give a certain outout, i have it partially done using IF..Else

If NextNum =1 Then
DeptName = "Bloggs"
ElseIF NextNum = 2 Then
DeptName = "joe"
Else
.........................

I don't want to have 50 Else..If's to achieve this. I suspect I should try to use an array to hold the values.
Has anyone a better way of achieving this, if they do can they supply some sample code for it.

Thanks.
 
this will make a string array of 50

VB.NET:
[size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] s(49) [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2]s(0) = [/size][size=2][color=#800000]"Jon"

[/color][/size][size=2]s(1) = [/size][size=2][color=#800000]"Frank"

[/color][/size][size=2][/size][size=2][color=#008000]'.... all the way to s(49)

[/color][/size]
 
Thanks for the reply.

But how do I output what the value of s(1) or s(2) is, can I do this:

value = s(1)
in order to use value for something else
 
you also need to keep in mind that arrays start at 0 and your nextnum starts at 1, so to get the correct array element you'll need

DeptName = s(nextnum - 1) after the array has been filled

another way to do this if you didnt want to get into arrays and/or still wanted to hard code it is to use the select case method:
VB.NET:
Select Case NextNum
  Case 1
	DeptName = "Bloggs"
  Case 2
	DeptName = "joe"
Case 3
	DeptName = "Frank"
End Select
 
Last edited:
Back
Top