Today I will tell you about using the Option Explicit statement. The Option Explicit has two modes. On and Off mode. If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration
By default the Option Explicit Statement is always On.
Option Explicit Off
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
someVariable = "Option Explicit ON"
MsgBox(someVariable)
End Sub
End Class
Here "someVariable" is not declared , because the Option Explicit Of , without any compiler error you can continue the program.
Wednesday, May 15, 2013
Saturday, May 4, 2013
Using Nothing Syntax in VB.NET
When coding in VB.NET you will sometimes want to declare a variable or a string as Nothing. There is a really way to do this and it takes about 1 line of code. Here is how you can do it.
Sub Main2() Dim sString As String = Nothing If sString = Nothing Then Msgbox("You've got nothing") End If
You can also ofcourse combine Nothing with an If-else statement which will help you test to see if the string is actually Nothing.
Subscribe to:
Posts (Atom)