I just made some changes to my code for this app, but for some reason it is still not working. My restart button is not restarting the form, my score numbers are not showing up, the outcome results are not showing up, the dice are not rolling.
Here is the link to my GUI: https://imageshack.com/i/kpdOTIAQp
Basically, a human player is playing against a COMPUTER using VB's built in random number generator. The objective of the game is for either opponent to have a higher score than the other to win the game in a best of an odd number of matches format from 1 up to 99 ( like 1, 3, 5, 7, 9, 11, 13 and so forth).
The problem is that the dice images do not show up when you click the button.
Public Class DiceBattleForm
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
Dim RESPONSE As MsgBoxResult
RESPONSE = MsgBox("Do you want to exit?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
If RESPONSE = MsgBoxResult.Yes Then
Me.Dispose()
End If
End Sub
Private Sub RollButton_Click(sender As Object, e As EventArgs) Handles RollButton.Click
If GameTextBox.Text <= "0" Then
MsgBox("Number of Games > 0", MsgBoxStyle.Critical)
Application.Restart()
End If
If GameTextBox.Text > "0" Then
GameTextBox = Convert.ToInt32(GameTextBox.Text)
End If
DisplayDie(PCDice1)
DisplayDie(PCDice2)
DisplayDie(PCDice3)
DisplayDie(YouDice1)
DisplayDie(YouDice2)
DisplayDie(YouDice3)
End Sub
Sub DisplayDie(diePictureBox As PictureBox)
'GENERATE random integer in range 1 to 6
Dim face As Integer = randomObject.Next(1, 7)
'retrieve specific die image from resources
Dim pictureResource = My.Resources.ResourceManager.GetObject(String.Format("die{0}", face))
'Convert pictureResource to type Image and display in ImageBox
diePictureBox.Image = CType(pictureResource, Image)
End Sub ' DisplaDie
Private Sub GameTextBox_Validating(sender As Object, e As EventArgs) Handles GameTextBox.TextChanged
If GameTextBox.Text > "0" Then
Do
MsgBox(GameTextBox.Text + " round(s) will be played enjoy!")
Loop While GameTextBox.Text = "STOP"
End If
GameTextBox.Enabled = False
End Sub
Private Sub RestartButton_Click(sender As Object, e As EventArgs) Handles RestartButton.Click
' Reset or clear any controls (recommended)
DiceBattleForm.Clear()
' NOT recommended:
' Application.Restart()
End Sub
End Class
well, for the restart button, instead of
Form1.Clear()
Try
and so on that should clear the textboxes, and as for the. But really, I don't see what's wrong with the
Application.Restart()