Friday, July 5, 2013

IF Statement Syntax

If logicalcondition Then
Compound Statement
End If

Sample Program that best illustrate the use of IF Statement in Visual Basic 6.0.

Interface

Object Properties

Source Code 


Private Sub cmdclose_Click()
If MsgBox("Are you sure you want to end this program?", vbQuestion + vbYesNo, "Comparing Two Numbers using IF Statement") = vbYes Then
    End
End If
End Sub

Private Sub cmdIF_Click()
If cmdIF.Caption = "Co&mpare" Then
    If Val(txtnum1.Text) > Val(txtnum2.Text) Then
        MsgBox "The highest number is Num1: " & txtnum1.Text & """", vbInformation + vbOKOnly, "Comparing Two Numbers using IF Statement"
    End If
    If Val(txtnum1.Text) = Val(txtnum2.Text) Then
        MsgBox "The inputted numbers are equal."
    End If
    If Val(txtnum1.Text) < Val(txtnum2.Text) Then
        MsgBox "The highest number is Num2: " & txtnum2.Text & """", vbInformation + vbOKOnly, "Comparing Two Numbers using IF Statement"
    End If
    cmdIF.Caption = "Cle&ar"
Else
    txtnum1.Text = ""
    txtnum2.Text = ""
    cmdIF.Caption = "Co&mpare"
End If
End Sub

Private Sub Form_Load()
    Me.Top = (Screen.Height - Me.Height) / 3
    Me.Left = (Screen.Width - Me.Width) / 2
End Sub


Download the Full Project by clicking here.

0 comments :

Post a Comment