Saturday, 12 October 2013

Sample Program

Example program:

     First add a BUTTON to the FORM As Shown above.
     Select the button and then go to Property window and change the button name as ADD 2 NUMBERS.

     how to change the name of the button?
     refer this link.
        
            To get our first look at the code window, double click your Button control. The code 
      window will appear.




As shown in the above figure we need to write our code where the cursor blinks.. here we need to concentrate on our code for our program. The cursor will be blinks in between Private sub and End sub.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_ Handles Button1.Click                                                                                                                             
                                                                                                                                                                  
End Sub                                                                                                                                                

                     
Private
Private means that no other part of the program can see this code except for our button.
Sub
Short for Subroutine. The "Sub" word tells VB that some code follows, and that it needs to be executed.
Button1
This is the name of our button. You might think that we've just erased the word "Button1" when we changed the Text property, so why does VB insist that it's still called Button1? We'll, the Name property of the control is the important one. If you change the Name property, VB will change this button name for you.
_Click ( )
This is something called an Event. In other words, when the button is clicked, the Click Event will fire, and the code we're going to write will be executed.
End Sub
The subroutine ends right here. This signifies the end of our code.

Now we are going to write our code in between Private sub and end sub.


        Dim var1 As Integer
        Dim var2 As Integer
        Dim result As Integer
      
        var1 = 13
        var2 = 15
       
        result = var1 + var2
        MsgBox(result)



Then save our project and then run it.
Goto debug menu ----> start Debugging.
Then click on button.
Then the result will be displayed in MESSAGE BOX.



                                             

<---- Previous page                                                 Next Page ---->

VB.NET HOME PAGE