Money Dreamer Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
Homei use portalGalleryLatest imagesSearchRegisterLog in

 

 [TU] Visual Basic

Go down 
AuthorMessage
jay20
Bronze Marketer
Bronze Marketer



Posts : 37
Reputation : 0
Join date : 2012-06-26

[TU] Visual Basic Empty
PostSubject: [TU] Visual Basic   [TU] Visual Basic Icon_minitimeWed Jul 18, 2012 8:09 am

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 [You must be registered and logged in to see this link.]

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
        'displays a message box greeting to the user
        MessageBox.Show("Hello, " & txtName.Text & "! Welcome to VB 2010")
    End Sub

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
        Me.Close()
    End Sub

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
Back to top Go down
 
[TU] Visual Basic
Back to top 
Page 1 of 1
 Similar topics
-
» [TUT] Basic SEO practices for newbies
» Writing a basic XML file with C# (ELEMENT)
»  Boost Your Adsense Revenue, Tell few basic steps through which people can boost your earnings.

Permissions in this forum:You cannot reply to topics in this forum
Money Dreamer Forum :: Programming, Computing and Graphics :: Programming-
Jump to: