Escolar Documentos
Profissional Documentos
Cultura Documentos
Visual Basic
Programming Module
Ismail bin Shaari Sek. Raja Perempuan Taayah Ipoh BSc. Computer Science with Education, UTM H/P : 019 4636171 e-mail : ismail@taayah.com
End button to stop the running program. Also user can click close button
View Code
View Object
Form Windows
Toolbox
Properties Window. To setting object properties such as name, forecolor dan caption
Important Tips. Windows Properties Windows Project Explorer Toolbox Shortcut-Key F4 Ctrl-R Alt-VX Menu From view menu Select Properties Windows From View menu Select Project Explorer From View menu Select Toolbox Toolbar
2 2
How to start Microsoft Visual Basic 6.0 1. 2. Click the Start Button. If you see Microsoft Visual Basic 6.0 in the main Start menu, click it. If you don't see Microsoft Visual Basic 6.0 in the main Start menu, point to All Programs, Microsoft Visual Basic 6.0, and then click Microsoft Visual Basic 6.0. The Microsoft Visual Basic 6.0 window opens and a Visual Basic button appears on the taskbar. 3. 4. 5. Click Open button. Click maximize button on the container windows. Resize the form to appropriate size.
Name : txtHello
2
Name : cmdHello Caption : Hello To start coding, double click Hello button
Properties windows
Do all the steps below 1. Drag textbox and command button into the form. 2. Name the textbox and command button by entering value in the properties windows. Object Textbox1 Command1 Properties Name Name Caption Value txtHello cmdHello Hello
3.
3. Double click command button and type the statement , txtHello.Text = Hello, World 4. Click the start button to run the program and click Hello Button. 4
Save File
1. Hello.frm 1 (form file) 3
3. 1
2 4 5
4.
picOutput.Print "Thank! " ; txtName picOutput.Print "I will treat you "; txtFood 4. Click the start button to running the program.
Do all the steps below 1. Drag textbox1, combobox1, picturebox1, a command1 into the form. Setting objects properties in properties windows Object TextBox1 ComboBox1 Properties Name Name List Picturebox1 Command1 Name Name Caption 3. Value txtName cboFood Nasi Lemak Fried Rice Burger picOutput cmdPrint Print
txtName
2. cboFood
picOutput
cmdPrint
picOutput.Print "Thank! " ; txtName picOutput.Print "I will treat you " ; cboFood 7
Private Sub cmdCheck_Click() picOutput.Print "Name :"; txtName picOutput.Print "Result :"; If Val(txtBM) > 49 Then picOutput.Print "Pass" Else picOutput.Print "Failed" End If End Sub
Private Sub cmdCheck_Click() picOutput.Print "Name :"; txtName picOutput.Print "Result :"; If Val(txtBM) > 49 Then picOutput.Print "Pass" Else picOutput.Print "Failed" End If Select Case Val(txtBM) Case 80 To 100: Grade = "A" Case 70 To 79: Grade = "B" Case 60 To 69: Grade = "C" Case 50 To 59: Grade = "D" Case 0 To 49: Grade = "E" End Select picOutput.Print "Grade :" + Grade End Sub
Object Form
Command Button1
Value frmShowHide My sixth program c:\ProgramFiles\ Microsoft Visual Studio\Common\ Graphic\Icons\ Misc\eye.ico cmdShow Show cmdHide Hide cmdExit Exit imgOne c:\ProgramFiles\ Microsoft Visual Studio\Common\ Metafile\Business\ AnsMach.wmf True
Stretch
Value txt1 txt2 txtAns imgRight Right.bmp False imgWrong Wrong.bmp False cmdCheck Check cmdExit Exit
Image
Command1 Command2
End
Private Sub cmdCircle_Click() Radius = Val(txtRadius) Area = PI * Radius * Radius picResult.Print "Area of circle is "; Area End Sub Object Label1 TextBox1 Picturebox1 Command1 Command2 Command3 Properties Caption Name Name Name Caption Name Caption Name Caption Value Radius txtRadius picResult cmdCircle Circle cmdCircumference Circumference cmdDiamter Diameter 10
Object Label1
Properties Name Caption Alignment Caption Alignment Name Name Name Name Caption Name Caption Name Caption
Value lblOperator Center = Center txt1 txt2 txtResult cmdAdd Add cmdMultiply Multiply cmdSubtract Subtract
a = Val(txt1) b = Val(txt2)
'
Private Sub File1_Click() Image1.Picture = LoadPicture(File1.Path & "/" & File1.FileName) End Sub
11
Extra Project II : Message Formatter The Date Time Picker and UpDown control may not appear in your toolbox window. They are custom control, and you must add them to the toolbox window before you can use them. 1. 2. 3. Open project menu Choose component Scroll down the list of the components windows until you see microsoft windows common controls-2 6.0 (SP4). If there is a check mark to the left of microsoft windows common controls-2 6.0 (SP4) that means it already resides in the toolbox windows. If there is no check mark in the check box, place one there by clicking the check box. Click OK button of the Component windows.
4.
5.
UpDown Control
12
Label Name:lblMessage
Listbox Name:lstFont List: Arial Times New Roman Bookman Old Style Comic Sans MS
Double Click Object Red Option button Blue Option button Checkbox Display Button UpDown ListBox
Add code lblMessage.Forecolor = vbRed lblMessage.Forecolor = vbBlue lblMessage.FontBold = chkBold.Value lblMessage.Caption = dtpDate.Value & : & txtMessage.Text txtSize.Text = updSize.Value lblMessage.FontSize = updSize.Value lblMessage.FontName = lstFont.Text
13