Hi. I'm new to the VB language but I'm familiar with programming/scripting.
I'm also new to these forums so please forgive me if this post is in the wrong board.
I started playing with Visual Basic when I realized my tech school had it installed on the network computers, and became a bit addicted (within a few days) of the possibilities it contains.
I've started writing something basic.. a number guessing game in a Windows Application. The layout may not be optimal/strategically formed, because I'm not familiar with the language yet.
Here's the code:
vb Code:
Public Class Form1 Public Rand As Integer = 0 Public Attempts As Integer = 5 Public Function DoFail() MsgBox("You failed. The number was: " + Rand) Attempts = 0 Return 1 End Function Private Sub Button1_Click() Handles Button1.Click If Rand < 1 Then Randomize() Rand = Int(Rnd() * 11) If Rand = 0 Then Rand += 1 End If End If If GuessBox.Text = 0 Then MsgBox("You must enter a guess!", MsgBoxStyle.Exclamation, "Guess") Else Dim Guess As Integer = GuessBox.Text If Guess > Rand Then Attempts -= 1 If Attempts = 0 Then DoFail() End If StatusStrip1.Text = "Remaining attempts: " + Attempts OutputBox.Text = "Lower!" End If If Guess < Rand Then Attempts -= 1 If Attempts = 0 Then DoFail() End If StatusStrip1.Text = "Remaining attempts: " + Attempts OutputBox.Text = "Higher!" End If If Guess = Rand Then StatusStrip1.Text = "Winner!" MsgBox("You've got it! The number was: " + Rand, MsgBoxStyle.Information, "Winner!") Me.Close() End If End If End Sub End Class
When I attempt to run this, the dialog opens fine. Until I click the "Guess" (Button1) button, which sort of freezes the dialog, returning me to the Visual Basic editor debugger. If the guessed number matches the random number (or if its lower or higher) then it returns the related code (involving the integers 'Rand' and 'Guess'):
If Guess > Rand:
vb Code:
StatusStrip1.Text = "Remaining attempts: " + Attempts 'This line is highlighted with this message: 'Conversion from string "Remaining attempts: " to type 'Double' is not valid.
If Guess < Rand:
(same as above)
If Guess = Rand:
vb Code:
MsgBox("You've got it! The number was: " + Rand, MsgBoxStyle.Information, "Winner!") 'This line is highlighted with this message: 'Conversion from string "You've got it! The number was: " to type 'Double' is not valid.
What am I doing wrong?
Thanks in advanced.




Reply With Quote