dan Edwards - 4 months ago 21

Vb.net Question

im a total noob in programing but i really need help

anyway i have to do a 10 question program in school and it allways counts wrong like 5/10 when they are all corect but here is the code

Public Class Form1

`Dim score As Integer = 0`

Dim varname As String

Private Sub cmdsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsubmit.Click

varname = txtname.Text

If txtbox1.Text = 18 Then

score = score + 1

End If

If txtbox1.Text <= 18 Then

score = score - 1

End If

If txtbox1.Text >= 18 Then

score = score + 0

End If

If txtbox2.Text = 10 Then

score = score + 1

End If

If txtbox2.Text <= 10 Then

score = score + 0

End If

If txtbox2.Text >= 10 Then

score = score + 0

End If

If rb11.Checked = True Then

score = score + 1

End If

If rb2q3.Checked = True Then

score = score + 0

End If

If cmboxq4.Text = "windows xp" Then

score = score + 1

End If

If rbq5.Checked = True Then

score = score + 1

End If

If score = 0 Then

MsgBox("you have scored 0 out of 10" & varname)

End If

If score = 1 Then

MsgBox("you have scored 1 out of 10 " & varname)

End If

If score = 2 Then

MsgBox("you have scored 2 out of 10" & varname)

End If

If score = 3 Then

MsgBox("you have scored 3 out of 10" & varname)

End If

If score = 4 Then

MsgBox("you have scored 4 out of 10" & varname)

End If

If score = 5 Then

MsgBox("you have scored 5 out of 10" & varname)

End If

If score = 6 Then

MsgBox("you have scored 6 out of 10" & varname)

If score = 7 Then

MsgBox("you have scored 7 out of 10" & varname)

If score = 8 Then

MsgBox("you have scored 8 out of 10" & varname)

If score = 9 Then

MsgBox("you have scored 9 out of 10" & varname)

End If

End If

End If

End If

End Sub

End Class

Answer

Your comparisons (at the start at least) are meaningless.

You go =18, <=18, >=18

If the value is 18 the first two comparisons are ignored, you repeat the error for comparing with 10.

Without knowing exactly what you are wanting to do I would say they should be =18, <18, >18