|
Post by ~Joedagimp on Dec 21, 2008 14:06:31 GMT -5
My first tutorial on YouTube uk.youtube.com/watch?v=DFmYhcpWHq4Really simple tutorial. Just to show people how to add a simple If function to a project. The code for the button: Okay, what we have is Label1 ( which we do not need to us ), Textbox1, and Button1. We need a string, so in this case i am going to use "answer" as the string. Beginning code: Dim Answer As String Now we need to define the Answer: Second part of code ( new line ) Answer=Textbox1.text Now we can start out If code. First line: If Answer="Type your correct answer here" then msgbox("Correct!") else msgbox("Sorry, thats incorrect") end if end sub Right now, you can use something different than a message box. For example: If answer="Type your correct answer here" then Form2.Show() This is another way to use the if function. Here you can display a new form if the user gets the correct answer. And, if you want the program to close if the user guesses the answer incorrectly, you would put: Else me.close() This will close the form if the user guesses incorrectly. Full Code: Dim Answer As String Answer=Textbox1.text If answer="TYPEYOURCORRECTANSWERHERE" then Msgbox("Correct!") Else Msgbox("Sorry, that is incorrect") End if End sub You can always use a different string besides "answer", and you can also give different results besides message boxes as i showed above. Thanks www.joedagimp.co.nr
|
|
|
Post by 1ruleyou on Dec 25, 2008 21:40:53 GMT -5
I took a class on this and didnt learn a thing!!! Thank you!
|
|