Tuesday, July 21, 2015

Inserting The Code on VS.net



After you have inserted some visual object items onto the program. But the program does nothing when you click a button, simply because you haven’t inserted any codes into the program.
Codes are the logics behind the program. You are commanding the program to act using the codes you write. What you can do using codes can be very diverse. From just as simple as displaying alert message via a messagebox, until createing reports or database operations.
Codes in vbnet are event-drive codes, that is codes will be called/activated only if the event related to the codes triggered.
Here are steps to insert the code into the program:
1.   We use button from the previous example, Double click the button.
2.   A Code editor window will be displayed. You’ll see a procedure initiated with “Private Sub” and Ended with “End Sub”. Between them, you can insert the code. 
3.   The codes will be like this, this will with the object’s name properties.
Public Class Form1


    Private Sub btnClickMe_Click(sender As Object, e As EventArgs) Handles btnClickMe.Click

    End Sub
End Class
4.   In the middle of the codes, you can insert new lines of codes. This time with ‘ character that means texts after that is comments and will not be processed by vb.net compiler.
5.   For example, you can insert a messagebox by clicking MsgBox. During writing M S G you may see a listbox appears, this is called intellisense to help you type the codes to minimize errors.
6.   Then insert the codes. You may change the codes’ texts
    Private Sub btnClickMe_Click(sender As Object, e As EventArgs) Handles btnClickMe.Click
        'you can write any codes here
        ' these texts are comments, will not compile
        MsgBox("Let's Learn VB.NET", MsgBoxStyle.Information, "Information")

    End Sub      
7.   Save the project using CTRL + S in your keyboard. This will save your codes into your project. If you haven’t saved the codes, an asterisk (*) will emerge on the right of your tab name. If you save the project, this asterisk character will disappear.
8.   You can now run the program by clicking F5 button on your keyboard or click Debugging button. A window will appear.
9.   A messagebox will emerge with the text corresponds to the codes you inserted before.
10. Click the Stop Debugging button to stops the running of the program.
intellisense, autocomplete, visual studio, visual basic.net

No comments: