Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Visual basic help

$
0
0
Hi, wondered if anyone can help me with this programme. I've just started programming and I'm not sure what I'm doing wrong.
Basically you generate numbers, put a plus, subtract or multiply sign in the box then enter the answer in the corresponding text box. The user is allowed five tries, then a messaged will be displayed, but my programme won't do this.

Here's my main code.

Dim num1 As Integer 'variables
Dim num2 As Integer







Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click



Dim temp As Integer


Dim random As New Random()

num1 = random.Next(0, 9) 'generate random numbers
num2 = random.Next(0, 9)

If num1 < num2 Then 'swaps numbers
temp = num2
num2 = num1
num1 = temp


End If


lblNum1.Text = num1.ToString 'display numbers
lblNum2.Text = num2.ToString

tries = tries + 1
If tries = 6 Then
MessageBox.Show("You scored " & wins & " Out of 5 ", "Result", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
btnGenerate.Enabled = False
End If

picRight.Visible = False
picWrong.Visible = False



tries = 0






End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


mskNum1.Mask = "##" 'amount of characters in mask
mskNum1.BeepOnError = True

Me.ToolTip1.IsBalloon = True 'display tool tip as balloon









End Sub

Private Sub mskNum1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles mskNum1.MaskInputRejected
ToolTip1.ToolTipTitle = "Invalid Input" 'message to be displayed in tooltip
ToolTip1.Show("Only two digits allowed", mskNum1, 5000)

End Sub

Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click

Dim index As Integer
Try
Dim appPath As String
Dim fileName As String
appPath = Application.StartupPath
fileName = appPath & "\newdetails3.txt"
Dim sWriter As New System.IO.StreamWriter(fileName)

For index = 0 To numPeople - 1
sWriter.Write(names(index))
sWriter.Write(",")
sWriter.Write(passwords(index))
sWriter.Write(",")
sWriter.WriteLine(scores(index))

Next
sWriter.Close()
MessageBox.Show("Writing file to disk")
Me.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub








Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click


Dim total As Decimal


Select Case txtOption.Text

Case "+"
total = num1 + num2

Case "-"
total = num1 - num2

Case "*"
total = num1 * num2


Case Else
MessageBox.Show("Only +, - or * available")

End Select
If mskNum1.Text = total Then
picRight.Visible = True
Else
picWrong.Visible = True

End If




If mskNum1.Text = total Then


lblAnswer.Text = ("Correct")
Else
lblAnswer.Text = ("Incorrect. The correct answer is " & total)

End If

If mskNum1.Text = total Then
wins = wins + 1
End If




End Sub

Private Sub txtOption_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOption.TextChanged

End Sub



End Class

This is the module I have

odule Module1
Public tries As Integer
Public wins As Integer = 0


Const MAX As Integer = 10
Public names(0 To MAX - 1) As String
Public numPeople As Integer
Public passwords(0 To MAX - 1) As String
Public scores(0 To MAX - 1) As Integer



Public position As Integer




End Module






Any ideas?



Viewing all articles
Browse latest Browse all 2703

Trending Articles