TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jordan
NA
7
11.1k
Hello User
Aug 30 2010 1:24 PM
Most people are used to the basic one button click "Hello World" tutorial. But today I am going to show you the little bit more advanced version called "
Hello User
"
First open up
Visual Basic
, I use the 2010 Express version which you can download at http://www.microsoft.com/express/downloads/
Go to File > New Project > Windows Forms Application and at the bottom name it "Hello User"
You should now have a blank "Form1" application. Click the grey area and in the bottom right corner you should see the properties box. Scroll to the text property and change it to what ever you want, probably "Hello User". Press enter and you will see the name of your form has changed, that is what the text property does.
Now, add a label control to your form from the toolbox.
Note: If you can't see the toolbox click Ctrl+Alt+X
Click the label and change the text property to "Enter your name"
Add a textbox control and move it under the label. This is where the user will enter their name into. Change the "Name" property to txtName.
Note: The name property is used to reference to the control in your code.
Add two button controls
1. Change the text property to "Ok" and the name property to "btnOk"
2.Change the text property to "Exit" and the name property to "btnExit"
Double click the Ok button and add the bolded code.
[code]Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
[b] 'displays a message box greeting to the user
MessageBox.Show("Hello, " & txtName.Text & "! Welcome to VB 2010")[/b]
End Sub[/code]
Messagebox.show = Pops up a message box with whatever is in the parenthesis.
("Hello, " & txtName.Text & "! Welcome to VB 2010") = Will show as exactly what it says. txtName.text will get the text from your textbox control.
Ampersands(&) = connect what is in between the quotation marks and your code. There must be a blank space preceding it.
Return to your Design editor and double click the exit button
Once again, add the bolded code
[code]Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
[b]Me.Close()[/b]
End Sub[/code]
Me = tells the program it will act upon itself
close = obviously close
Now go to File > Save All and browse to the folder you want to save it to. Then hit "F5" or the green button that says start debugging to start your program. Type a name and hit "ok" and tada, you get a lovely greeting to visual basic 2010. Now hit exit and it closes. If you want to get an exe file for your program go to Debug > Build. This will build it into the same place you saved it. It will be found in Bin > Release > Program.exe
Enjoy Everyone,
Zer[o]
Reply
Answers (
1
)
Coding Practice
String Lengths