Get Random Number
Hi- I have this code to generate randomly the alphabet, the letters R and L, and the numbers 3,4 ,5. You'll see that I concatenate the 3 4 and 5 with the R and L and use the letter from the alphabet alone. So I have 2 labels- one holds the alphabet letter and the other holds both the R or L and the 3,4 or 5.
The problem here is that I am not generating 3L or 5R.
Then I have a select case structure that is self explanatory but although it was working nothing is happening now.
mark
PublicClass Form1
Dim LETTER AsString
Dim checkWord AsString
Dim DIE AsString
PrivateFunction getrandomchar(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomchar = New System.Random().Next(low, high)
EndFunction
PrivateFunction getrandomdie(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomdie = New System.Random().Next(low, high)
EndFunction
PrivateFunction getrandomNumber(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomNumber = New System.Random().Next(low, high)
EndFunction
PrivateSub btnChooseletter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChooseletter.Click
Dim myAlphabet AsString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim myRandomLetter AsChar = myAlphabet.Substring(getrandomNumber(0, 26), 1)
lblCharac.Text = myRandomLetter
EndSub
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Randomize()
EndSub
PrivateSub btnDie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDie.Click
Dim myDieNum AsString = "345"
Dim myDieChar AsString = "RL"
Dim myRandomdieNum AsChar = myDieNum.Substring(getrandomdie(0, 3), 1)
Dim myRandomdieChar AsChar = myDieChar.Substring(getrandomchar(0, 2), 1)
lblDie.Text = myRandomdieNum & myRandomdieChar
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim LETTER AsString
Dim checkWord AsString
Dim DIE AsString
Dim wordLength AsInteger
LETTER = lblCharac.Text
DIE = lblDie.Text
checkWord = txtEnterWord.Text
wordLength = checkWord.Length
If checkWord.Length < 3 Then
MsgBox("Please use words that are 4 or more characters in length")
txtEnterWord.Text = ""
EndIf
SelectCase DIE
Case "3L"
If checkWord.Substring(2, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "4L"
If checkWord.Substring(3, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "5L"
If checkWord.Substring(4, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "3R"
EndSelect
EndSub
Hi- I have this code to generate randomly the alphabet, the letters R and L, and the numbers 3,4 ,5. You'll see that I concatenate the 3 4 and 5 with the R and L and use the letter from the alphabet alone. So I have 2 labels- one holds the alphabet letter and the other holds both the R or L and the 3,4 or 5.
The problem here is that I am not generating 3L or 5R.
Then I have a select case structure that is self explanatory but although it was working nothing is happening now.
mark
PublicClass Form1
Dim LETTER AsString
Dim checkWord AsString
Dim DIE AsString
PrivateFunction getrandomchar(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomchar = New System.Random().Next(low, high)
EndFunction
PrivateFunction getrandomdie(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomdie = New System.Random().Next(low, high)
EndFunction
PrivateFunction getrandomNumber(ByVal low AsInteger, ByVal high AsInteger) AsInteger
getrandomNumber = New System.Random().Next(low, high)
EndFunction
PrivateSub btnChooseletter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChooseletter.Click
Dim myAlphabet AsString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim myRandomLetter AsChar = myAlphabet.Substring(getrandomNumber(0, 26), 1)
lblCharac.Text = myRandomLetter
EndSub
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Randomize()
EndSub
PrivateSub btnDie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDie.Click
Dim myDieNum AsString = "345"
Dim myDieChar AsString = "RL"
Dim myRandomdieNum AsChar = myDieNum.Substring(getrandomdie(0, 3), 1)
Dim myRandomdieChar AsChar = myDieChar.Substring(getrandomchar(0, 2), 1)
lblDie.Text = myRandomdieNum & myRandomdieChar
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim LETTER AsString
Dim checkWord AsString
Dim DIE AsString
Dim wordLength AsInteger
LETTER = lblCharac.Text
DIE = lblDie.Text
checkWord = txtEnterWord.Text
wordLength = checkWord.Length
If checkWord.Length < 3 Then
MsgBox("Please use words that are 4 or more characters in length")
txtEnterWord.Text = ""
EndIf
SelectCase DIE
Case "3L"
If checkWord.Substring(2, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "4L"
If checkWord.Substring(3, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "5L"
If checkWord.Substring(4, 1) = LETTER Then
MsgBox("CORRECT")
lblScore.Text = lblScore.Text + checkWord.Length
checkWord = ""
EndIf
Case "3R"
EndSelect
EndSub
Last edited by a moderator: