Enable VB 6 via the Start button.
Identify the types of components (control) which is in the Toolbox:
In Window Form UI make it like this :
How to make:
Click Label components in the Toolbox and then "picture" object Label1 in Form by
drag-drop. Perform the same steps for object Label2. Text1 object is "image" using
TextBox component, while the object Command1 and Command2 use the Command Button component.
1.2 Setting Object Property
Identify the parts in the Properties window:
Through the Properties Window set the properties of each object as follows:
object | properties | value |
Form1 | Caption StartUpPosition | Property test 2-centerScreen |
Label1 | Caption | Tuliskan nama anda : |
Text1 | - | - |
Label2 | Alignment BackColor Font | 2 – Center Palette: <putih> Size : 24 |
Command1 | Caption | Ok |
Command2 | Caption | Selesai |
UI so that it becomes like this:
1.3 Writing Program Code: Property Test
Open the Code window and identify the parts in it :
Windows-based programs are event-driven, meaning that the program works based on events that
occurred on the object in the program. For example, if a user clicks a button
then the program will provide a "reaction" to the click event. The program will provide
"Reaction" in accordance with program codes are created for an event on a particular object.
Select the Command1 object in the Object Selector. Automatically in the Code Editor will
block of code appears following program:
Private Sub Command1_Click ()
end Sub
Event Click event is the default (standard) of the Command1 object, you can view other events
at the Event Selector.
In the Code Editor type the code is as follows:
Private Sub Command1_Click ()
Label2.Caption = Text1.Text
end Sub
Private Sub Command2_Click ()
end
end Sub
Save Project1 (file name: Latihan.vbp) and Form1 (file name: Lat1.frm). VB 6 will save
program that you created into several files that are linked, among others: the project file (*. vbp), file
form (*. frm) and module files (*. bas).
Try running Project1 by clicking the Start button on the toolbar or press the
F5 on the keyboard. Type "Salman" in the TextBox and then click the OK button. Then it will appear
the following results:
If you want to exit click the Done button.
Explanation of code:
The following explanation is given how the program works on a simple
Private Sub Command1_Click ()
Label2.Caption = Text1.Text
end Sub
When a user clicks on the OK button (Command1 object) then the contents of the writing on the object Label2 will
together with the contents written in object Text1. Label2 Caption property on the object used to
displays certain text in the object.
Next to exit the program is written the following code:
Private Sub Command2_Click ()
end
end Sub
When a user clicks on the Done button (object Command2) then the program will stop.
End command is used to close the program.
Showing posts is one of the properties owned by the Label component. property contents
writing on label component is Caption, whereas in Textbox is a Text component.
Way of writing (syntax) program code to set an object property is as follows:
nama_object.property = value
Note, after you type a period (dot) nama_object behind the VB 6 will
displays a list of properties and methods that are owned by nama_object:
This facility is called Intellisense, and really help you to avoid mis-typed nama_object
or her property.
1.4 Modification Program Code
Change the appearance of its UI looks like this:
(Add a Frame component, OptionButton and CheckBox)
Set additional property objects as follows:
Object | Properties | Text |
Frame1 | Caption | Pilihan : |
Option1 | Caption | biru |
Option2 | Caption | merah |
Check1 | Caption | tebal |
Check2 | Caption | miring |
Frame1 object must be made in advance the form, and thereafter the object Option and Check made in in these Frame1. The purpose of making the various options is to introduce to you facilities and CheckBox Option is used to make a choice in the application. Add the code is as follows:
Private Sub Option1_Click()
Label2.ForeColor = vbBlue
End Sub
Private Sub Option2_Click()
Label2.ForeColor = vbRed
End Sub
Private Sub Check1_Click()
Label2.FontBold = Check1.Value
End Sub
Private Sub Check2_Click()
Label2.FontItalic = Check2.Value
End Sub
Save back to Form1, and then try to run Project1 and see the results:
Tidak ada komentar:
Posting Komentar