Select Case End Select - VB6 Sample Program Part 1

Saturday, August 22, 2009 ·

VB Select Case Sample Program
In this posting I'll write a sample of simple VB6 program that using Select Case..End Select control structure. However this program also using several VB6 functions like Val() (to convert text into number so can be calculated), Len() (to get the length of a text) and Left() (to pick up a part from the left side of a text).

The scenario of the program is as the following:

  • This program is Bonus Calculation (Sales System).
  • Here it is the bonus percentage table:
      Sales Quantity = 1 - 2 -> Bonus = 2%
    Sales Quantity = 3 - 4 -> Bonus = 3%
    Sales Quantity = 5 - 6 -> Bonus = 4.5%
    Sales Quantity = 7 - 8 -> Bonus = 6.5%
    Sales Quantity = 9 -> Bonus = 10%
    Sales Quantity = 10 or more -> Bonus = 15%
  • Bonus Amount = Sales Quantity X Price Unit X Bonus

    The screen design of the program is like below screenshot.
    Secect Case End Select VB6 Sample Program

    Now, let's design the program first (create screen interface).
  • Open your Visual Basic 6 software
  • Select a standard type project
  • Create 5 Labels
  • Create 4 Textboxes
  • Create a Command button
  • Arrange the controls on your Form like the picture above
  • Click first Label (Label1)
  • Rename the caption of Label1 into Bonus calculation
  • Change the font size into 24
  • Change the caption of Label2, Label3, Label4 and Label5 into Your Sales Quantity, Price Unit (USD), Percentage of Bonus, and Amount of Bonus (USD)

  • Click first Textbox (Text1), clear it's Text, and rename into txtSalQty
  • Click second Textbox (Text2), clear it's Text, and rename into txtPriceUnit
  • Click third Textbox (Text3), clear it's Text, and rename into txtBonus
  • Click fourth Textbox (Text4), clear it's Text, and rename into txtBonusAmt
  • Click Command1 button, change the caption into Calculate Bonus, and rename into cmdCalBonus

  • Click anywhere in Form1 area, and rename into frmCalBonus (look at properties window)
  • Click Project1 file (in Project explorer window)
  • Click cell next to (Name) in Properties Window, and change the Name into prjCalBonus

    Look at image above, your screen design should like that.
    Ok, now the time to save your work (your program) in order you can edit it next time (this program will be used in the next posting). Here it is tips to save your VB6 program:
  • Click File menu on your menu bar
  • Click Save Project As... menu
  • On Save File As window, type frmCalBonus on the cell with label File name:
  • Select the folder you want to save in, then click Save button
  • Then on Save Project As window, Type prjBonus on the cell with label File name:
  • Then click Save button

    Note: The extention .vbp and .frm will automatically given by the system.
    Ok, now your program has been saved. You have 2 files in your project: prjBonus.vbp and frmCalBonus.frm and you can close your VB program. I'll continue to write the program coding in the next posting.


  • 0 comments:

    Post a Comment