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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select case statement syntax with multiple choises, is it possible? 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
GR
Hello everyone.

I have a select case statement about a randnum integer variable
Select Case randNum1
Case 1
pb1.Image = My.Resources.dice1
Case 2
pb1.Image = My.Resources.dice2
Case 3
pb1.Image = My.Resources.dice3
Case 4
pb1.Image = My.Resources.dice4
Case 5
pb1.Image = My.Resources.dice5
Case 6
pb1.Image = My.Resources.dice6
End Select

And I want this statement to use it for multiple variables so that not to write too much code... like the following example. Is it possible and how??? Any help will be much appreciated.

Select Case randNum1, randNum2, randNum3, randNum4, randNum5, randNum6 etc
case randNum1 = 1
pb1.image=My.Resources.dice1
case randNum2 = 1
pb2.image = My.Resources.dice1
case randNum1 = 2
pb1.image = My.Resources.dice2
case RandNum2 = 2
pb2.image = My.Resources.dice
.
.
.
end case

 
You could create a function that you can use for each image. Something like this.

Code:
    Private Function GetImage(ByVal RandomNum As Int32) As Image
        Dim returnImage As Image
        Select Case RandomNum
            Case 1
                returnImage = My.Resources.dice1
            Case 2
                returnImage = My.Resources.dice2
            Case 3
                returnImage = My.Resources.dice3
            Case 4
                returnImage = My.Resources.dice4
            Case 5
                returnImage = My.Resources.dice5
            Case 6
                returnImage = My.Resources.dice6
        End Select
        Return returnImage
    End Function

Then call it like:

Code:
pb1.Image = GetImage(MyRandomNumber)
pb2.Image = GetImage(MyRandomNumber)

Hope this helps.
 
I looked at the same problem because you can have multiple criteria in VFP. Couldn't find a way to do it with Select case so went to
If then
else if
else if
else if
else
end if

That works and I have the same flexibility as I had in VFP.
 
SBTBILL, it's the best way Randy suggested. Because everytime I want to I pass the arguments without writting too much code.
I don't know if you can do the same in Fox Pro. But if yes, it would be the best solution. Not at all if then else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top