|
Tutorials:
Creating
Your Interface
Create
a new program called Variables2. Add a TextBox called MyTextBox. Set its
PasswordChar property to " * ".
This will make all text that appears there to be in password format. Create a
Button called MyButton and set its text property to "Check!"
Bonus: Another thing you can do (to make it look more like XP) is set the
textbox font to Wingdings and set the PasswordChar property to "l"
(The letter l - lowercase). This makes a dot appear instead of an asterisk.
This makes it look more "XP style".
Coding your
Program
Go
to your code. Create a new variable called MyString.
Dim
MyString As String
Make
sure you type it in, in the Declarations area, after Inherits
System.Windows.Forms.Form.
For
our program, we are going to display an InputBox when the program loads. The
value of what you type in will be stored into MyString. The TextBox will check
whether the text you entered in the InputBox matches the textbox (case
sensitive).
In order to display an event when the Program loads, Select MyBase in the
objects list and select Load in the events list..
Under MyBase.Load
type
in:
MyString
= InputBox("Type in your password here!")
An
InputBox is a prompt that asks you to type in some text. Remember when working
with variables, the value of the right side is stored in into the left
side. In this case, the right side is the InputBox prompt. So whatever you
type in into the InputBox, will be stored into MyString.
Under
MyButton.Click Type in:
If
MyTextBox.Text = MyString Then
MessageBox.Show("The password
you typed in is correct!")
Else
MessageBox.Show("The password
is incorrect")
End If
This
checks if the Text in MyTextbox matches MyString (what you typed in inside the
InputBox). The block statement above is called an If statement. It checks
whether one value matches another.
Run Your Program and see what happens! If both values are the same then it
will say, "The Password you typed in is correct" If otherwise, it
will say, "The Password you typed in is incorrect"
The If Statement can check if values are = , < , or >. If you want to
check whether the values are not equal, type in <>. Another way of
writing <>, which is more traditional is writing the Not
keyword
after the word If. We will go into If Statements in detail in a different
tutorial.
You have just learned how to write an If statement! One important aspect in
VB.NET!
The Source Code
for this tutorial is located here:
You can also
locate this by logging in to vbProgramming Forums and going to:
Tutorials > Tutorial Source Code > Source Code
|
|