Function IToR(i As Integer) As String
Dim s As String
s = "I II III IV V VI VII VIIIIX X XI XII "
IToR = Mid(s, (i - 1) * 4 + 1, 4)
End Function Private Sub cmdConvert_Click()
txtRomNum.Text = IToR(Val(txtMonth.Text))
End Sub
To create a number of letters we often use roman numerals to indicate the month of making the letter.For example, the letter number is '001/Int/III/2010' where the symbol 'III' indicates that the letter was made in March 2010.
For this we need a function that can convert an integer number from 1 to 12 into roman numerals. In the Visual Basic programming, we can easily create such a function. Well, here we'll show an example program to create such functions, as well as examples of how to use it.
So your Screen design will look like the image below:
Okay, you have completed the program
Now it's time to test
Consider the results
Creating a Function to Convert Numbers into Roman Numerals
What's an Event in Visual Basic?
An event is an action that recognized by a control or a form. For examples moving mouse over a control, clicking a mouse, pressing a key, etc. You can write code in an event that runs when the event occurs.
Every object in Visual Basic has a set of event that it recognizes. Each object has specific events. Here are list of some events than owned by each object:
Object name: CommnandButton
Events owned: Click, DragDrop, DragOver, GotFocus, KeyDown, KeyPress, KeyUp, LostFocus, MouseDown, MouseMove, MouseUp, OLECompleteDrag, OLEDragDrop, OLEDragOver, OLEGiveFeedback, OLESetData and OLEStartDrag.
Object name: TextBox
Events owned: Change, Click, DblClick, DragDrop, DragOver, GotFocus,
When You Should Set the Name Property in VB6 Programming?
One of the important thing is setting the Name of object property when you developing VB6 applications. And in the previous posting I've written that you should set the name with adopting the Standard Naming Convensions in order easier for other developer in understanding your program. And also you should give the descriptive name that according to the purpose of the object.
Now, the question is "when you should set the name property?". The recommended time to set the Name property is as soon as after you create the object. Why this time? Because if you set the name (change the name) property after you write coding for the object, it makes the code in your applications will loss its association with the control.
When you change a name property of an object, the sub procedure that associated with the object won't be changed automatically, so code seems lost. For example: You have a TextBox named Text1, and you have written some codes in Sub Text1_Change() and Sub Text1_LostFocus(). When you change the name to other name (for example txtFirstName), the name of Sub Text1_Change() and Sub Text1_LostFocus() won't be changed to new name automatically. So the association between the object and the code is lost.
Now, what you should do if you have to change the object name after you write your code that associated with the object?
How to Return Property Value in VB6 Programming?
It is often needed to return property value of an object to perform a calculation or some other task in your Visual Basic Application. And in the most previous sample program I've written use this way to perform some calculations, and also some other tasks. For example in the sample program of How to Convert Degree from Celcius to Another in VB 6 Programming? also returning property value to be calculated, and then the result of calculation to set the property value of other object.
To return the value of an object property, you can use below syntax:
Variable = Object.Property
Or
Object2.Property = Object1.Property
Note:
You can use the first syntax if you want to return the value of an object property into a variable, so the value will be kept in the variable.
You should use the second syntax if you want to return the value to set another object property value.
In the most sample program I've written in the previous postings use the second syntax to return value of an object property and perform the calculation, then the result kept as value of another object property.
Notice below sample code:
Text2.Text = Val(Text1.Text) * 1.8 + 32
The value of Text1.Text is returned and used as an operand in the calcuation phrase and the result of calculation then used as value of Text2.Text. In this example you don't need a variable to keep the calculation result.
Another example code:
strName = txtName.Text
lblName.Caption = txtName.Text
Any comment? Please leave it in the below comment box.
Setting Properties of Object at Run Time - Sample Code
In this posting I'll write a sample program of VB6 that demonstrates how to set object properties at run time. However some of property must be set at design time. Okay, follow below instructions:
Your design maybe look like the image on the top of this posting.
'setting Form1 caption Form1.Caption = "New Member's Registration Form" 'setting the properties of Title (Label1) With Label1 .Caption = "New Member's Registration Form" .FontSize = 18 .FontUnderline = True .Left = 360 .Top = 120 .Width = 5775 .Height = 495 End With 'setting the properties of Full Name label (Label2) With Label2 .Caption = "Full Name" .FontSize = 10 .Top = 960 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of Gender label (Label3) With Label3 .Caption = "Gender" .FontSize = 10 .Top = 1320 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of Address1 label (Label4) With Label4 .Caption = "Adress1" .FontSize = 10 .Top = 1680 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of Address2 label (Label5) With Label5 .Caption = "Adress2" .FontSize = 10 .Top = 2040 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of City label (Label6) With Label6 .Caption = "City" .FontSize = 10 .Top = 2400 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of Province label (Label7) With Label7 .Caption = "Province" .FontSize = 10 .Top = 2760 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of Country label (Label8) With Label8 .Caption = "Country" .FontSize = 10 .Top = 3120 .Left = 480 .Height = 375 .Width = 1215 End With 'setting the properties of txtFName TextBox With txtFName .Text = "" .FontSize = 10 .Top = 960 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of cboGender ComboBox With cboGender .Text = "" .FontSize = 10 .Top = 1320 .Left = 1680 ' .Height = 330 .Width = 1575 .AddItem "Female" .AddItem "Male" End With 'setting the properties of txtAddr1 TextBox With txtAddr1 .Text = "" .FontSize = 10 .Top = 1680 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of txtAddr2 TextBox With txtAddr2 .Text = "" .FontSize = 10 .Top = 2040 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of txtCity TextBox With txtCity .Text = "" .FontSize = 10 .Top = 2400 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of txtProvince TextBox With txtProvince .Text = "" .FontSize = 10 .Top = 2760 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of txtCountry TextBox With txtCountry .Text = "" .FontSize = 10 .Top = 3120 .Left = 1680 .Height = 330 .Width = 4335 End With 'setting the properties of cmdRegister CommandButton With cmdRegister .Caption = "Register" .FontSize = 14 .Top = 3720 .Left = 2880 .Height = 495 .Width = 1695 End With
Your program should like below screenshot.
How to Convert Degree from Celcius to Another in VB 6 Programming?
In this posting I will tell you a simple VB programming tips "How to convert degree / temperature from Celcius to another one", so the base temperature is Celcius. The temperature will be converted into Fahrenheit, Rheamur and Kelvin. As we know that we have three conversion formulas are (in Celcius base):
Fahrenheit = ( Celcius X 1.8 ) + 32
Rheamur = Celcius X 0.8
Kelvin = Celcius + 273.15
How to apply these three formulas in simple VB6 programming? It's just an easy thing to do! You can do it just with a simple VB program. Please follow below instructions for your tips!
So your screen design will look like below image:
Now, let's write the program coding.
Double click any where in Form1 area to create a Sub Form_Load()
Write down below program coding in the Sub Form_Load() area
'to clear text boxes text Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = ""
Double click Command1 command button to create a Sub Command1_Click()
Write down below program coding in the Sub Command1_Click() area
Text2.Text = Val(Text1.Text) * 1.8 + 32 Text3.Text = Val(Text1.Text) * 0.8 Text4.Text = Val(Text1.Text) + 273.15
So your program will look like the following list:
Private Sub Command1_Click() Text2.Text = Val(Text1.Text) * 1.8 + 32 Text3.Text = Val(Text1.Text) * 0.8 Text4.Text = Val(Text1.Text) + 273.15 End Sub
Private Sub Form_Load() 'to clear text boxes text Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub
Now, you can test your program by clicking Start button on your VB toolbar to check whether your program is correct or not.
If the results are 59 in Text2 (Fahrenheit), 12 in Text3 (Rheamur), and 288.15 in Text4 (Kelvin), it means that your program is correct and running properly.
Look at below image for your illustration.
How do you think, it's an easy simple VB programming tips isn't it?
How to Convert Degree from Rheamur to Another in VB 6 Programming?
In the previous posting you have learnt a simple VB programming tips "How to convert degree from Fahrenheit into another one in VB6 programming". Now we will learn another simple VB programming tips "How to convert degree / temperature from Rheamur into another one", so the base degree is Rheamur, and will be converted into Celcius, Fahrenheit and Kelvin. We have three previous conversion formulas (Celcius base) as follow:
Fahrenheit = ( Celcius X 1.8 ) + 32
Rheamur = Celcius X 0.8
Kelvin = Celcius + 273.15
From these formulas, now we can generate new three other formulas (Rheamur base) as the following:
Celcius = Rheamur / 0.8
Fahrenheit = ( ( Rheamur / 0.8 ) X 1.8 ) + 32
Kelvin = ( Rheamur / 0.8 ) + 273.15
Now, let's implement above formulas into a simple VB6 programming. Let's go on to the following simple VB programming tips!
So your screen design should look like below image:
'to clear the content of text boxes
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
'conversion process
'Text1 represents Rheamur
'Text2 represents Celcius
'Text3 represents Fahrenheit
'Text4 represents Kelvin
Text2.Text = Val(Text1.Text) / 0.8
Text3.Text = ((Val(Text1.Text) / 0.8) * 1.8) + 32
Text4.Text = (Val(Text1.Text) / 0.8) + 273.15
So your program will look like below listing:
Private Sub Command1_Click()
'conversion process
'Text1 represents Rheamur
'Text2 represents Celcius
'Text3 represents Fahrenheit
'Text4 represents Kelvin
Text2.Text = Val(Text1.Text) / 0.8
Text3.Text = ((Val(Text1.Text) / 0.8) * 1.8) + 32
Text4.Text = (Val(Text1.Text) / 0.8) + 273.15
End Sub
Private Sub Form_Load()
'to clear the content of text boxes
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Ok, your program's finish. Test your program by clicking Start button on your VB toolbar to know whether your program working properly or not.
If the results are 100 in Text2 (Celcius), 212 in Text3 (Fahrenheit), and 373.15 in Text4 (Kelvin), it means that your program is correct and working properly.
Look at below image for your illustration.
It is very easy and very simple isn't it? Would you like to try it? Ok, in the next posting I'll write another simple tips with VB6 programming. See you in the next posting!
How to Set Object Properties at Run Time in VB6?
In the previous posting you have learnt how to set object properties at design time, by clicking the object you want, then change/set the value of property in the properties window. In this posting I'll write how to set/change property value at run time (when program running). And also I'll give you a sample program (code).
Below is the syntax how to set an object property at run time:
Object.Property = Expression
For example:
Below statement will set Caption of lblName with "John Smith" at run time.
lblName.Caption = "John Smith"
However not all object properties can be set their values at run time, because some object properties can be set just at design time. In the next posting maybe I'll write lists of which object properties that can be set just at design time, which ones that can be set just at run time, and which ones that can be set both at design time and run time.
How to Set Properties of Object at Design Time in VB6?
In the previous posting I've written that you can set the properties of an object at design time. The properties settings that you establish at design time are used as the initial settings each time your application runs. You can set the object properties by using Properties window.
Although it is not a must, because you set the properties of course according to your need. But some properties usually you set them at design time, such as:
BackStyle
BorderStyle
Caption
Enabled
FillColor
FillStyle
Name
Visible
How to set the value of property at design time, you can follow below steps:
Visual Basic will activate the form or control, and displays the property for the object.
Some property values can be selected from the list, but others must be typed.
How to Name Objects in VB6 Programming ?
When an object is created, a default name based on its object typed will be given to the object. For example Form1 will be given to object/control with type Form, Text2, Text3,... will be given to Textbox object, Command1, Command2,.... will be given to command button object. You should immediately change the name property of the object to a name that describes the purpose of the control. Changing the Name property of your object with a name that describe the purpose with the object will make the code in your application easier to read and debug.
Visual Basic has several Standard Naming Convensions. Although you can assign any name you want to an object, but it is a better to adopt a naming convension and use it ocnsistently throughout your programms. Because it will make easier for others to understand your code.
Here it is a list of Standard Naming Convensions used in Visual Basic that assign to each type object:
The prefix you should use: chk
Example name: chkDrink
The prefix you should use: cbo
Example name: cboStore
The prefix you should use: cmd
Example name: cmdSelect
The prefix you should use: dat
Example name: datSales
The prefix you should use: dir
Example name: dirImage
The prefix you should use: drv
Example name: drvSource
The prefix you should use: fil
Example name: filSource
The prefix you should use: frm
Example name: frmEntry
The prefix you should use: fra
Example name: fraOption
The prefix you should use: grd
Example name: grdItem
The prefix you should use: hsb
Example name: hsbTemperature
The prefix you should use: img
Example name: imgEmployee
The prefix you should use: lbl
Example name: lblName
The prefix you should use: lin
Example name: linHorizontal
The prefix you should use: lst
Example name: lstCustomer
The prefix you should use: mnu
Example name: mnuReport
The prefix you should use: ole
Example name: oleObject2
The prefix you should use: opt
Example name: optCountry
The prefix you should use: pic
Example name: picFlower
The prefix you should use: shp
Example name: shpSquare
The prefix you should use: txt
Example name: txtName
The prefix you should use: tmr
Example name: tmrStep
The prefix you should use: vsb
Example name: vsbRate
Project Types in Visual Basic
A Visual Basic project is made up of the forms, code modules, ActiveX controls, and environmental settings required by an application (you can identify a Visual Basic project from it's extention name ".vbp"). The project lists all the files you need in your application.
By default Visual Basic offers you several project templates designed to support the development of different kinds of applications and components. The project templates contain the basic project objects and environment settings you need to create the type of application or component you want to build. When you begin to develop an application, first you have to decide what project template you will use.
By default you can select the following templates that available in Visual Basic:
By default Standard EXE projects contain a form, and you can use this project template to develop a stand-alone application.
You can use this project template to develop an application that reads or manipulates data from data sources.
Use ActiveX EXE and ActiveX DLL project templates to develop COM components that expose functionality to other applications. You can use an ActiveX EXE project template if your component will both expose functionality programmatically and run as a stand-alone application. You can use an ActiveX DLL if your component will only be used programatically by another application.
You can use ActiveX Control project template if you want to create a component that designed to be a user interface element in a form or a dialog box.
You can use ActiveX Document EXE and ActiveX Document DLL if you want to create a component that designed for use in a document object container, such as Internet Explorer.
You can use DHTML Application project template if you want to create a component that can be used on the client side of a Web application.
You can use IIS Aplication project template if you want to create a component that can be used on the server side of a Web application.
You can create a new Visual Basic project with below steps:
The New Project dialog box appears.
Or you can follow below steps if your Visual Basic application already open:
The New Project dialog box appears.
Common Terminology in Visual Basic
Like another programming language, Visual Basic also has some common terminology that required to be understood by the developers (programmers). Here are some common terms in Visual Basic:
Design time is any time when an application being developed in Visual Basic Development Environment
Run time is any time when an application is running.
Forms are windows that can be customized by the developer (programmer)
Controls are graphic that representation of objects
Object is a general term that used to describe forms and controls that make up a program
Properties are the characteristics of objects such as size, width, height, etc
Methods are the actions that object can perform
Events are the actions that recognized by forms or controls
.......
8 Basic Steps to Create a Program in Visual Basic
Visual Basic is one of even-driven programming. Creating an even-driven programs like Visual Basic requires different approach from that used in procedural languages. The approach may seem unusual, if you are experienced with procedural programming.
Here are 8 basic steps in creating an application with Visual Basic:
1. Create a Design Plan
2. Create the user interface
3. Set the properties of interface objects
4. Write code for events
5. Save the project
6. Test and debug the application
7. Make an executable file (by compiling it)
8. Create a setup application
How to Display Images in a Folder with VB6 Program ?
In this posting I will write a Sample of Simple VB6 program to display images in a directory of your computer. To display image in VB6 programming you can use LoadPicture statement. The format of statement is:
LoadPicture (Path\FileName)
For example:
LoadPicture ("Image01.jpg") -> display image named Image01.jpg in the current folder (the folder of image and the program is the same)
LoadPicture ("d:\MyPicture\Image02.bmp") -> display image named Image02.bmp that stored in folder MyPicture in drive d:
To make a VB6 program application like the above illustration you can follow below VB6 Programming tips.
In this case assumed that you have some images file (with extention .jpg or .bmp) that stored in directory D:\MyPicture.
Now you have to create a screen design like below image:
To create the screen design, please follow below steps:
Ok, program interface already done. Now the time to write code statements to functionate the controls, so the program can work. Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path File1.Path = Dir1.Path
On Error GoTo ErrHandle
Image1.Picture = LoadPicture(File1.Path & "/" & File1.FileName)
Exit Sub
ErrHandle:
MsgBox "Invalid Image display"
Resume Next
So your Program coding will look like below listing:Private Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
End SubPrivate Sub File1_Click()
On Error GoTo ErrHandle
Image1.Picture = LoadPicture(File1.Path & "/" & File1.FileName)
Exit Sub
ErrHandle:
MsgBox "Invalid Image display"
Resume Next
End Sub
Now the time to test your program, follow below tips:
Your program should like the illustration on the top of this posting, however the image you display depend on the image you have and select.
Visual Basic Standard Toolbar
The Standard Toolbar is one of Visual Basic Development Environment components. The Standard Toolbar contains buttons for many of the most commands used in Visual Basic.
The button such Open Project, Save Project, Start, Break, and End contain in this toolbar.
It also contains another button, such buttons to display Project Explorer, the Properties Window, the Toolbar, and other elements of Visual asic Development environment.
By default most Visual Basic Standard Toolbar are docked (attached) on the top of your screen. However you can undock it whenever you want. To undock it, click near the double bar along the left side of a toolbar, and drag away from its docked position. To dock a toolbar, drag it to another edge of the main window.
Many buttons exist in Visual Basic Standard Toolbar that make easier to edit your VB application:
Another buttons in Visual Basic Standard Toolbar:
With..End With Statement to Set Properties of Object in VB6
In the earlier posting I have written that you can set object properties in two session, at design-time and at run-time, although some object properties can be set in both run-time and design-time, other can be set just in design-time, and onother can be set just in run time.
When you set object properties maybe you need to several properties at once, for example you want to set the properties of TextBox as following:
So you can do with the following coding:
Text1.Font.Bold = True
Text1.Font.Size = 24
Text1.Text = "Set Object Properties"
However to make it easier to read, and easier to understand, you can use With..End With statement to set several Object Properies.
You can use below code statement:With Text1
.Font.Bold = True
.Font.Size = 24
.Text = "Set Object Properties"
End With
Example:
Create a screen design like below image:
Note: Set property "Multiline" of Text1 and Text2 to "True".
Double-click command1 button.
Write below coding: Text1.Text = "One by one set object properties"
Text1.Font.Bold = True
Text1.Font.Size = 24
Text1.FontUnderline = True
Double-click command2 button.
Write below code statements:With Text2
.Text = "Using With..End With to set object properties"
.Font.Bold = True
.Font.Size = 24
.FontUnderline = True
End With
So your coding should like below listing:Private Sub Command1_Click()
Text1.Text = "One by one set object properties"
Text1.Font.Bold = True
Text1.Font.Size = 24
Text1.FontUnderline = True
End Sub
Private Sub Command2_Click()
With Text2
.Text = "Using With..End With to set object properties"
.Font.Bold = True
.Font.Size = 24
.FontUnderline = True
End With
End Sub
Now run our program, click command1 button, and then also click command2 button.
Your program sholud like screenshot in top of this posting.
Code Editor Window in Visual Basic
In the earlier posting I've told you that a VB Project maybe contains one or more files like form, module, and so on. One form usually contains one or more controls. However a form with it's control contained on it can't do anything without code statements (programming code) that associate with them. And a module also contains one or more statements.
A place in VB Development Environment where you can write your VB code statements (programming code) is called Visual Basic Code Editor Window. It's also known as the Code Window. A sparate Code Editor Window is displayed for each form or module in your project, making it easy to organize, view, and navigate.
There are two drop-down lists at the top of the Code Editor Window called Object List and Procedure List.The Object list contains a list of all the Contols that exist on the form. When you selectiong a control name from the list, the Procedure list shows all the events (actions) for the control.
Using the Object and Procedure list together, can make you easy to located and edit the code you want in your VB application. The image above (on the top of posting)illustrates the Code Editor Window.
To open the Visual Basic Code Editor Window you can follow the following steps:
Tips:
For example: You have a control called txtAmount on your form. You want to write code statements on Sub txtAmount_LostFocus(). How can you do that?
Ok, you can follow the tips below:
So, Sub txtAmount_LostFocus() appears on your screen (in the Code Editor window) and you can write your code statements you want.
Select Case...End Select - VB6 Sample Program Part 2
This posting is continuation of previous posting "Select Case...End Select - VB6 Sample Program Part 1". In the previous posting you have designed a program interface like below image, and you have saved it. Select Case Val(txtSalQty.Text) Private Sub cmdCalBonus_Click()
Now, let's writing the program coding for the above program design.
At the end, your program will look like below listing:
Case 1 To 2
txtBonus.Text = "2%"
Case 3, 4
txtBonus.Text = "3%"
Case 5 To 6
txtBonus.Text = "4.5%"
Case 7 To 8
txtBonus.Text = "6.5%"
Case 9
txtBonus.Text = "10%"
Case Else
txtBonus.Text = "15%"
End Select
txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
Val(Left(txtBonus.Text, Len(txtBonus.Text) _
- 1)) / 100
Let's test your program to check whether it's correct or not.
Select Case Val(txtSalQty.Text)
Case 1 To 2
txtBonus.Text = "2%"
Case 3, 4
txtBonus.Text = "3%"
Case 5 To 6
txtBonus.Text = "4.5%"
Case 7 To 8
txtBonus.Text = "6.5%"
Case 9
txtBonus.Text = "10%"
Case Else
txtBonus.Text = "15%"
End Select
txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
Val(Left(txtBonus.Text, Len(txtBonus.Text) _
- 1)) / 100
End Sub
According to the Bonus Table if Sales Quantity = 5, so the Bonus Percentage should equal to 4.5%. So the Bonus Amount = 5 X 100 X 4.5 / 100. And the result is 22.5. So your program should like below screenshot.
Now I'll explain how the program works. txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
Mybe you think that this is a complex statement. But in fact it's just a simple statement.
Val(Left(txtBonus.Text, Len(txtBonus.Text) _
- 1)) / 100
Val(txtSalQty.Text) convert text "5" into number 5
Val(txtPriceUnit.Text) convert text "100" into number 100
Because txtBonus.Text = "4.5%" (this is a text) so:
Len(txtBonus.Text) will return 4, and Len(txtBonus.Text) - 1 will return 3
Left(txtBonus.Text, Len(txtBonus.Text) - 1) equals to Left("4.5%",4-1) will return "4.5"
Then Val(Left(txtBonus.Text, Len(txtBonus.Text) - 1)) equal to Val("4.5") will return number 4.5
So the above formula will equal to:
txtBonusAmt.Text = Val("5")*Val("100")*Val(Left("4.5%",Len("4.5%")-1))/100
<=> txtBonusAmt.Text = 5 * 100 * 4.5 / 100
<=> txtBonusAmt.Text = 22.5
Select Case End Select - VB6 Sample Program Part 1
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: 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%
The screen design of the program is like below screenshot.
Now, let's design the program first (create screen interface).
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:
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.
How to Add Controls to Form in VB6 Programming
In the previous posting I've told you that one of Visual Basic Development Environment's element is Toolbox, that contains controls. And another element is Form Design window (Form). You can place controls into your Form to build your VB application.
Now, how to place controls from Toolbox into your Form? Ok, it's just a simple way to do that. You just click, drag and drop the control you want. Or also you can double-click the icon Toolbox of the control you want.
There are two manners to place (add) controls to a form. The first manner is double-click the Toolbox icon of the control you want to add. In instance it will place the control with default size in the centre of active form.
When you adding more than one controls with this way, they will be placed on the top of each other in the center of the form. Then you can reposition/rearrange them into new place you want in the form.
The second manner, you can follow below steps:
After you add controls to your form, you can reposition them to new location in the form, and also you can resize them according to your need. That are the way how to add / place control to your Visual Basic form.
Ok, I think you get it. And I'll write another Visual Basic tips in the next posting.
Labels
- Stop Dreaming Start Action (1)
- Table of Contents (1)
- VB6 Programming (36)
- VB6 Sample Program (16)