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.

Tuesday, July 2, 2013

Create the following interface by utilizing the simple concepts discussed by your instructor.


Graphical User Interface:


Source Code:


Private Sub cmdClose_Click()
If MsgBox("Are you sure you want to end this program?", vbQuestion + vbYesNo, "Hello World Application") = vbYes Then
    End
End If
End Sub

Private Sub cmdPrint_Click()
If cmdPrint.Caption = "&Print" Then
    txtPrint.Text = "Hello World!"
    cmdPrint.Caption = "&Clear"
Else
    txtPrint.Text = ""
    cmdPrint.Caption = "&Print"
End If
End Sub

Private Sub Form_Load()
'Setting off the form on the center of the monitor.
    Me.Top = (Screen.Height - Me.Height) / 3
    Me.Left = (Screen.Width - Me.Width) / 2
End Sub

Download the Full Project by clicking here.