ARTICLE

How to define variables inside the if statement in Vb.Net

Posted by Manish Tewatia Articles | Visual Basic Language July 26, 2010
In this article I am trying to explain all of you that how you define variables also inside the if statement in Vb.Net
 
Reader Level:

As all of you now what is the variables and how to declare or define the variables and as also you now that the if statement  means the simple If...Else is very common across many programming languages. But the syntax is different in mostly languages like in Vb.Net the syntax is:

IF
    (predicate or Consequent)
Else
    (alternative)

When an interpreter finds an If it evaluates that condition with the given parameters by through variables, functions etc.

Through a simple example I shows you that how to define a variable inside the If statement the example is given below:

Example

    Module Module1
        Public Class Test
            Public Shared Sub Main()
                Dim value As Boolean = True
                    If
value Then Dim txt As String = "Mamish" : Console.WriteLine(txt) Else _
                    Dim txt As String = "Harish" : Console.WriteLine(txt)
                Console.ReadLine()
            End Sub
        End
Class
    End
Module

OUTPUT

1.gif

CONCLUSION

I hope this short article helps you to learn that how to define variables inside the if statement.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor