Easy Programs for VB6 Learners


Number Length
The Number Length sample program determines the length of a given number using Select Case. A number is taken as input through a TextBox, and then the length is shown.


Learn about Select Case: 

Determines numeric length
             
                                                   >> DOWNLOAD
Code:

Private Sub cmdCalculate_Click()
    Dim n As Long           
    n = Val(txtNum.Text)    
  
    Select Case n
    Case 0 To 9
        lblResult.Caption = "Single digit number"
      
    Case 10 To 99
        lblResult.Caption = "two digit number"

    Case 100 To 999
        lblResult.Caption = "Three digit number"

    Case 1000 To 9999
         lblResult.Caption = "Four digit number"

    Case 10000 To 99999
        lblResult.Caption = "Five digit number"

    Case Else
        lblResult.Caption = "More than Five digit number"
    End Select

End Sub



Password Check

This is a simple password program demonstrating the Do...Loop Until statement. The loop continues until the password matches. 


Learn about Do Loop: 

InputBox to enter password
             
                                                   >> DOWNLOAD
Code:
Private Sub Form_Load()
    Do
    a = InputBox("Enter the password ")

    If a = "visual" Then
        MsgBox "Access granted !!!"
    Else
        MsgBox "Access denied... please try again"
    End If


    Loop Until a = "visual"

End Sub


OptionButton example

This is a very simple OptionButton program that has two OptionButton controls. After selecting one option, the choice is displayed in a TextBox.


Find more related information at:  

An easy program using option buttons
             
                                                   >> DOWNLOAD
Code:
Private Sub cmdConfirm_Click()
    If optFootball.Value = True Then
        Text1.Text = "YOU HAVE SELECTED FOOTBALL !"
    ElseIf optCricket.Value = True Then
        Text1.Text = "YOU HAVE SELECTED CRICKET !"
    End If
End Sub



Format Text

The Format Text sample program shows the use of a Frame control. It formats the text (changes Font size and color) in a Label control using OptionButton controls.


Learn about OptionButton and frame:  

To learn about the frame control
             
                                                   >> DOWNLOAD
Code:
Private Sub optBlue_Click()
    lblMessage.ForeColor = vbBlue
End Sub
_______________________________________________
Private Sub optGreen_Click()
    lblMessage.ForeColor = vbGreen
End Sub
_______________________________________________
Private Sub optLarge_Click()
    lblMessage.FontSize = 22
End Sub
_______________________________________________
Private Sub optMedium_Click()
    lblMessage.FontSize = 16
End Sub
_______________________________________________
Private Sub optRed_Click()
    lblMessage.ForeColor = vbRed
End Sub
_______________________________________________
Private Sub optSmall_Click()
    lblMessage.FontSize = 12
End Sub






Restaurant Order 1

This program makes some demo restaurant orders using CheckBox controls and then the total price is displayed on the form.


Learn about checkbox: 

Example of checkbox
             
                                                   >> DOWNLOAD

Code:
Private Sub cmdExit_Click()
    End
End Sub
___________________________________________________
Private Sub cmdShow_Click()
    Dim total As Integer
    total = 0
    tea = ""
    sandwitch = ""
    pizza = ""
    colddrinks = ""
    greentea = ""
    coffee = ""


    If chkTea.Value = 1 Then
        tea = " Tea,"
        total = total + 5
    End If

    If chkSandwich.Value = 1 Then
        sandwich = " Sandwich,"
        total = total + 50
    End If

    If chkPizza.Value = 1 Then
        pizza = " Pizza,"
        total = total + 50
    End If

    If chkColdDrinks.Value = 1 Then
        colddrinks = " Cold Drinks,"
        total = total + 6
    End If

    If chkGreenTea.Value = 1 Then
        greentea = " Green Tea,"
        total = total + 7
    End If

    If chkCoffee.Value = 1 Then
        coffee = " Coffee,"
        total = total + 9
    End If


    MsgBox "You have ordered " & tea & _
    sandwich & pizza & colddrinks & greentea & coffee & _
    " and the total price is $" & total, vbInformation, "Thanks"


End Sub


OS Choice

This program lets you choose one of the listed Operating Systems using the Graphical style of the OptionButton controls. The choice is shown through a MsgBox.



Graphical option button
             
                                                   >> DOWNLOAD

Code:
Private Sub Form_Load()
    Option1.Value = True
End Sub
________________________________________________
Private Sub optXp_Click()
    If optXp.Value = True Then
        MsgBox "You have chosen Windows XP", , "OS Selection"
    End If
End Sub
________________________________________________
Private Sub opt7_Click()
    If opt7.Value = True Then
        MsgBox "You have chosen Windows 7", , "OS Selection"
    End If
End Sub
________________________________________________
Private Sub optLinux_Click()
    If optLinux.Value = True Then
        MsgBox "You have chosen Linux", , "OS Selection"
    End If
End Sub
________________________________________________
Private Sub optMac_Click()
    If optMac.Value = True Then
        MsgBox "You have chosen Mac", , "OS Selection"
    End If
End Sub





Restaurant Order 2

This is the enhanced version of the sample program, Restaurant Order 1. The only change in this program is the addition of graphical-style CheckBox controls.


Learn more at: Lesson 24

             
                                                   >> DOWNLOAD




Image Show

The Image Show program teaches you about the LoadPicture method of the PictureBox control. The program takes the image path as an input and then the picture is shown in a PictureBox.


Learn about image and picture box:

Image showing with LoadPicture method
             
                                                   >> DOWNLOAD

Code:
Private Sub cmdShow_Click()
    Picture1.Picture = LoadPicture(txtPath.Text)
End Sub