Banner Ad

Thursday, October 10, 2013

VB.Net : A Word about “Nothing”!

By Francis   Posted at   2:14 PM   VB.Net Tips and Tricks No comments


                              It’s a common misunderstand of a new programmer in vb.net about the keyword “Nothing”. The main purpose of this keyword is set the default value for an variable type. For example,the default value  for  the  Boolean type variable is “False”. In some cases, we may want to set the default value of that type of the variable. At that time, Nothing keyword comes into picture.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strString As String = "Sample String"
        Dim intVar As Integer = 100
        Dim decVar As Decimal = 100.01
        Dim dblVar As Double = 100.233
        Dim blnVar As Boolean = True
        ' Set the variable's Default value by using Nothing 
        strString = Nothing
        intVar = Nothing
        decVar = Nothing
        dblVar = Nothing
        blnVar = Nothing
        lblResult.Text = "Default value of String variable: " & strString & vbCrLf & _
                        "Default value of Integer variable: " & intVar & vbCrLf & _
                        "Default value of Decimal variable: " & decVar & vbCrLf & _
                        "Default value of Double variable: " & dblVar & vbCrLf & _
                        "Default value of Boolean variable: " & blnVar & vbCrLf

    End Sub

Just copy the above code under the Button's click event. Hope this hepls a bit!

About Francis

Francis, an Associate at Cognizant. Having 7+ Years of experience in Microsoft web technologies.

0 comments :

Please give your valuable comments to improve the contents

Connect with Us