this is a simple quiz program for addtion that generates random numbers and records the attempts and correct answers that were taken.

i have a problem, i need to have the percentage of the scores. i have a text2(number of attempts) text3(number of correct answers) the text4 should automalically have a the answers for the given formula (text2/text3)*100 to get the percentage..

also is there a code that i can use to dis able the (keyascii=13) after pressing it?


Dim ctr As Integer
Dim ctr2 As Integer
Dim aa As Integer
Dim bb As Integer
Dim cc As Integer


Private Sub Command1_Click()
Dim MyValue1 As Integer
Dim MyValue2 As Integer


MyValue1 = Int((20 * Rnd) + 1)
MyValue2 = Int((20 * Rnd) + 1)

Label1.Caption = MyValue1
Label2.Caption = MyValue2

Label3.Caption = ""
Text1.Text = ""

Text2.Text = ctr
ctr = ctr + 1
Image1.Visible = False
Command1.Enabled = False

End Sub

Private Sub Form_Load()
ctr = 1
ctr2 = 1
Randomize
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

aa = Label1.Caption
bb = Label2.Caption
cc = aa + bb

If KeyAscii = 13 Then

If Text1.Text = "" Then
MsgBox ("please enter a number")

ElseIf Text1.Text = cc Then
Text3.Text = ctr2
ctr2 = ctr2 + 1
Label3.Caption = "correct"

Image1.Visible = True
Image1.Stretch = True
Image1.Picture = LoadPicture("F:\Headtrip\School\3rd year\Computer 7\Montes\Random\smile.jpg")
Command1.Enabled = True

Else
Image1.Visible = True
Label3.Caption = "wrong"
Image1.Stretch = True
Image1.Picture = LoadPicture("F:\Headtrip\School\3rd year\Computer 7\Montes\Random\sad.jpg")
Command1.Enabled = True

End If
End If

End Sub

i can't find any code for text4.

Hi,
To calculate percentage

Private Sub Command1_Click()
Dim MyValue1 As Integer
Dim MyValue2 As Integer


MyValue1 = Int((20 * Rnd) + 1)
MyValue2 = Int((20 * Rnd) + 1)

Label1.Caption = MyValue1
Label2.Caption = MyValue2

Label3.Caption = ""
Text1.Text = ""

Text2.Text = ctr
ctr = ctr + 1
Image1.Visible = False
Command1.Enabled = False
[B]If Val (Text3.Text) <> 0 Then
  Text4.Text = Int ( (Val(Text2.Text) / Val(Text3.Text)) * 100 ) & " % "
End If[/B] 
End Sub

To disable Enter key

Private Sub Text1_KeyPress(KeyAscii As Integer)

aa = Val(Label1.Caption)
bb = Val(Label2.Caption)
cc = aa + bb

If KeyAscii = 13 Then
[B][I]' Your Code[/I][/B]
   [B]KeyAscii = 0[/B]
End If
End Sub

thnks a lot... it worked...
just a lil question wht does the statement says... in lay mans trem?

If Val(Text3.Text) <> 0

is it text3 = 0?

thnks a lot... it worked...
just a lil question wht does the statement says... in lay mans trem?

If Val(Text3.Text) <> 0

is it text3 = 0?

Val is generally used when you want only numbers to be used.
So if text1 = 10 Then Val(Text1.text) will return 10
If anything except a number is entered in Text1 Then Val(Text1.text) will return 0

Val() function always return numeric.

If Val(Text3.Text) <> 0
is it text3 = 0?

No, it means to compare if value of text3 is not 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.