Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Visual basic help

oscarp16oscarp16 Posts: 1Member
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.

[b]Here's my main code.[/b]

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 & "
ewdetails3.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

[b]This is the module I have[/b]

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?


Sign In or Register to comment.