|
-
Jan 12th, 2000, 08:56 AM
#1
Thread Starter
Frenzied Member
I am making a program to help my friends and I study for science, but this won't work. It won't clear the text box, so if you get one right, all you have to do is press OK again and it says "Correct". AND THE TEXT BOX WON'T CLEAR, I'VE TRIED EVERYTHING!
Randomize
MyValue = Int((14 * Rnd) + 1)
If MyValue = "1" Then Label2.Caption = "Scandium"
If Text1.Text = "Sc" Then Text1.Text = ""
If Text1.Text = "Sc" Then MsgBox "Correct"
If MyValue = "2" Then Label2.Caption = "Titanium"
If Text1.Text = "Ti" Then Text1.Text = ""
If Text1.Text = "Ti" Then MsgBox "Correct"
If MyValue = "3" Then Label2.Caption = "Vanadium"
If Text1.Text = "V" Then Text1.Text = ""
If Text1.Text = "V" Then MsgBox "Correct"
If MyValue = "4" Then Label2.Caption = "Chromium"
If Text1.Text = "Cr" Then Text1.Text = ""
If Text1.Text = "Cr" Then MsgBox "Correct"
If MyValue = "5" Then Label2.Caption = "Manganese"
If Text1.Text = "Mn" Then Text1.Text = ""
If Text1.Text = "Mn" Then MsgBox "Correct"
If MyValue = "6" Then Label2.Caption = "Iron"
If Text1.Text = "Fe" Then Text1.Text = ""
If Text1.Text = "Fe" Then MsgBox "Correct"
If MyValue = "7" Then Label2.Caption = "Cobalt"
If Text1.Text = "Co" Then Text1.Text = ""
If Text1.Text = "Co" Then MsgBox "Correct"
If MyValue = "8" Then Label2.Caption = "Nickel"
If Text1.Text = "Ni" Then Text1.Text = ""
If Text1.Text = "Ni" Then MsgBox "Correct"
If MyValue = "9" Then Label2.Caption = "Copper"
If Text1.Text = "Cu" Then Text1.Text = ""
If Text1.Text = "Cu" Then MsgBox "Correct"
If MyValue = "10" Then Label2.Caption = "Zinc"
If Text1.Text = "Zn" Then Text1.Text = ""
If Text1.Text = "Zn" Then MsgBox "Correct"
If MyValue = "11" Then Label2.Caption = "Gallium"
If Text1.Text = "Ga" Then Text1.Text = ""
If Text1.Text = "Ga" Then MsgBox "Correct"
If MyValue = "12" Then Label2.Caption = "Germanium"
If Text1.Text = "Ge" Then Text1.Text = ""
If Text1.Text = "Ge" Then MsgBox "Correct"
If MyValue = "13" Then Label2.Caption = "Arsenic"
If Text1.Text = "As" Then Text1.Text = ""
If Text1.Text = "As" Then MsgBox "Correct"
If MyValue = "14" Then Label2.Caption = "Selenium"
If Text1.Text = "Se" Then Text1.Text = ""
If Text1.Text = "Se" Then MsgBox "Correct"
I'm Sorry The Code Is So Long, But We Need To Study 14 Elements.
Please Help. I don't like text books, this way I can study while at my computer 
Steve
-
Jan 12th, 2000, 09:48 AM
#2
Addicted Member
Private Sub Text1_LostFocus()
Text1 = ""
End Sub
-
Jan 12th, 2000, 10:06 AM
#3
Hyperactive Member
You got wrong sequence of code:
If MyValue = "1" Then Label2.Caption = "Scandium"
If Text1.Text = "Sc" Then MsgBox "Correct"
If Text1.Text = "Sc" Then Text1.Text = ""
-
Jan 12th, 2000, 10:19 AM
#4
Thread Starter
Frenzied Member
LG, I tried that, but it still won't clear the text box. 
Steve
-
Jan 12th, 2000, 10:54 AM
#5
PowerPoster
I should think VB is getting confused because both lines have the same condition but differing outcomes...look...
If Text1.Text = "Sc" Then Text1.Text = ""
If Text1.Text = "Sc" Then MsgBox "Correct"
You are effectively saying "If Text1 is Sc, then make it blank BUT If Text1 is Sc (same IF condition!!) then show Correct Message".
You want to put:
If Text1.Text = "Sc" Then
MsgBox "Correct"
Else
Text1.Text=""
End if
Hope this helps
Regards,
------------------
- Chris
[email protected]
If it ain't broke - don't fix it 
-
Jan 12th, 2000, 12:20 PM
#6
Hyperactive Member
Or, to make the program a little fancier,
Code:
If MyValue = "#" Then Label2.Caption = "XXXXXX"
If Text1.Text = "XX" Then
correct = MsgBox ("Correct", vbOKOnly, "Correct")
Text1.Text = ""
Else
wrong = MsgBox ("Incorrect", vbOKOnly, "Incorrect")
Text1.Text = ""
End If
also, you might consider using Select Case for each of the MyValue parts rather than If Then.
bob
-
Jan 13th, 2000, 04:21 AM
#7
Thread Starter
Frenzied Member
Bob, the code still won't clear the text box. And if you get it right, you only have to keep pressing ok and it says correct. I can send you the Exe if you want to see what I mean.
Steve
-
Jan 13th, 2000, 11:36 AM
#8
PowerPoster
-
Jan 13th, 2000, 12:07 PM
#9
PowerPoster
-
Jan 13th, 2000, 12:15 PM
#10
Lively Member
if the suggestions here still don't work, try stepping one line at a time through your code by pressing F8.
-
Jan 13th, 2000, 12:48 PM
#11
Hyperactive Member
Hi,Steve.
This should work:
If Text1.Text = "Se" Then
MsgBox "Correct"
Text1 = ""
End If
Larisa
-
Jan 14th, 2000, 02:40 AM
#12
How about a bit more structured approach?
Code:
Option Explicit
Private Type Element
Name As String
Code As String
End Type
Private Elements(1 To 14) As Element
Private MyValue As Integer
Sub NewPoser()
Randomize Timer
MyValue = Int((14 * Rnd) + 1)
Label2.Caption = Elements(MyValue).Name
Text1.Text = ""
End Sub
Private Sub Command1_Click()
If Text1.Text = Elements(MyValue).Code Then
MsgBox "Correct"
NewPoser
Else
Text1.Text = ""
End If
Text1.SetFocus
End Sub
Private Sub Form_Load()
Call LoadElements
Call NewPoser
End Sub
Private Sub LoadElements()
Elements(1).Code = "Sc"
Elements(1).Name = "Scandium"
Elements(2).Code = "Ti"
Elements(2).Name = "Titanium"
Elements(3).Code = "V"
Elements(3).Name = "Vanadium"
Elements(4).Code = "Cr"
Elements(4).Name = "Chromium"
Elements(5).Code = "Mn"
Elements(5).Name = "Manganese"
Elements(6).Code = "Fe"
Elements(6).Name = "Iron"
Elements(7).Code = "Co"
Elements(7).Name = "Cobalt"
Elements(8).Code = "Ni"
Elements(8).Name = "Nickel"
Elements(9).Code = "Cu"
Elements(9).Name = "Copper"
Elements(10).Code = "Zn"
Elements(10).Name = "Zinc"
Elements(11).Code = "Ga"
Elements(11).Name = "Gallium"
Elements(12).Code = "Ge"
Elements(12).Name = "Germanium"
Elements(13).Code = "As"
Elements(13).Name = "Arsenic"
Elements(14).Code = "Se"
Elements(14).Name = "Selenium"
End Sub
-
Jan 14th, 2000, 05:21 AM
#13
Thread Starter
Frenzied Member
Thank you all for helping me on this problem. I hate looking in books to study. I thought this was an interresting approach. Thanks to Chris, it did work, thanks for taking the time this. I'm using Chris's code, but thank you Frans, yours worked also. Now to study. If I get 100% on this, my grade for the morking period will be 90.09%!!!!!!!!!!! Whish me luck!
Steve
-
Jan 15th, 2000, 01:43 AM
#14
-
Jan 16th, 2000, 06:15 AM
#15
Thread Starter
Frenzied Member
Thanks Guys I'm Done! If you want to see it email me. [email protected] Sorry it isn't too graphical, the test is tuesday so I didn't have much time
Steve
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|