Programming with visual Basic: 1-Introdution to Visual Basics 2-Forms and Control tools. 3-Project explorer, properties and events. 4-make project, save it and its applications. 5- Files projects and exercises. 6- Dialogue boxes message boxes. 7-Basic elements for visual basic statements, Variables, assignment statements. 8-General view on assignment statement, constants and operations. 9-Adding astringe of variable. 10-Control statements and If then statements. 11-If-hen-els statement. 12-Select statement. 13-For-next statement. 14-Condition loop. 15-Nested-loop. 16-Seguences.
Microsoft Visual Basic 6.0
Basic Beginning All purpose Symbolic Instruction Code Windows VB Dos graphical VB user interface Properties Events VB Objects Actions Start>Programs>Microsoft Visual Studio 6.0>Microsoft Visual Basic 6.0 VB
a b c f d e Menu bar g a Toolbox Controls Toolbar c b Pointer Picture box (Label) Text Box Frame Command Button Check Box Option Button
Drop- Combo Box Down list List Box Horizontal Scrollbar Vertical Scrollbar Timer Drive List Box Dir List Box File List Box Shape Line Image Data OLE Form Window Stretch d object Properties Window Project Explorer Window e Form Layout Window f Private sub Code Code Window g
End sub VB objects toolbox design
Project1-Microsoft Visual Basic (design) object Code Project1-Form1 (Code) Start End Form Run Run Run Save Save File as File Save Project save save Project as VB Label
caption backcolor forecolor "اصنل"= Labelno.caption (رمق) QBcolor = Labelno.backcolor (رمق) QBcolor = Labelno.forecolor Fontsize (رمق)= Labelno.fontsize رمق = Labelno.fontsize or Label1 label caption label size Font
Text box control Text backcolor forecolor "اصنل"= textno.text (رمق) QBcolor = textno.backcolor (رمق) QBcolor = textno.forecolor Multiline Multiline True Enabled text Multiline False اعفل textno.enabled=true ریغ اعفل textno.enabled=false text delete welcome to visual basic world text1 text form textbox welcome to visual basic world true false text1 multiline Command Button
caption Style backcolor "اصنل"= commandno.caption 1-Graphical 0-Standard (رمق) QBcolor = commandno.backcolor style 1-Graphical name label form label Label Comma label1 caption form label caption form command button name command1 Private Sub Command1_Click() Label1.Caption = "Ahmad" command1 form Calculator
form VB Form object form name "الامس اولطملب"= formno.caption caption (رمق) formno.backcolor=qbcolor backcolor يمام( 0-15 ) (رمق) formno.forecolor=qbcolor forecolor (0-15) Shape shape backstyle backcolor bordercolor 0-rectangle 1-square 2-oval 3-circle 0-trancsparence 1-opaque shape1 shape shape1 shape 3- circle
caption label1 circle label1 Sha Lab :design stage List box Listno list show label form VB form hide hide show display form2 Form1 Label1: caption=" " Command1: caption="show"
Command2: caption="hide" Label1 Command1 Command2 form2 Option Button Caption, Font, Enabled, BackColor and visible click Command Button red, blue, green form option1:caption green option2: caption blue option3: caption red green option2 option1 caption
qbcolor vb Private Sub Option1_Click() Form1.BackColor = vbgreen Private Sub Option2_Click() Form1.BackColor = vbblue Private Sub Option3_Click() Form1.BackColor = vbred Check Box Caption, Font, Enabled, BackColor, Forecolor, value and visible Text Box Text1 Text Check1 caption Bold Check2 caption Italic Check3 caption underline Text1 Check1 Check2 Check3 text Private Sub Check1_Click() Text1.FontBold = Check1.Value Private Sub Check2_Click() Text1.FontItalic = Check2.Value Private Sub Check3_Click() Text1.FontUnderline = Check3.Value
Timer Interval enabled true/false interval timer timer1 interval timer caption label 1000 label1 Label Timer Private Sub Timer1_Timer() Label1.Caption = Time label1 time Message Box Input-Output Boxes Input Box Msgbox Msgbox "Message", Symbol, "title" Message box Msgbox
vbcritical 16 vbquestion 32 vbexclamation 48 vbinformation 64 Commands Commands Vbokonly 0 Ok Vbokcancel 1 Ok, Cancel vbabortretryignor 2 Abort, Retry, Ignore vbyesnocancel 3 Yes, No, Cancel vbyesno 4 Yes, No vbretrycancel 5 Retry, Cancel MsgBox "please close your program", 16, "Error" or MsgBox "please close your program", vbcritical, "Error"
Input Box Message Box X = Inputbox ("prompt","title") ok Prompt caption Title X inputbox x form Private Sub Form_Load() X=Inputbox("enter value of x", "calculation") enter value of x calculation x
Variables) Dim As true or false Integer Long Single Double String Boolean Date Time Constant Const = π. Const π.
assignment statement Variable name = expression Operation ) Operation Code) Mod AND, OR 3(x+4y) 3*(x+4*y) 2 X 4/2 X^2 4 / 2 : Val ( ) :Cstr( ) CInt ( )
Input textbox inputbox output textbox label message box print form caption form Command1 caption + Command2 Caption - Label1 Caption Caption text Label2 text1, text2 Dim x, y, z as integer Private sub command1_click () X=val(text1.text) Y=val(text2.text) Z=x + y Msgbox(" ="&z) End sub Private sub command2_click () X=val(text1.text) Y=val(text2.text) Z=x - y Msgbox(" ="&z) End sub
,"2007","100$","name" (string ) Dim As String Length Len ) Form1 Caption String length Command1 caption Click here Label1 Caption Length= Text1 Text Dim s As String Private Sub Command1_Click() s = InputBox("inter string") L = Len(s) Text1.Text = CStr(L) End sub abs(x) sqr(x) sin(x), cos(x) tan(x) x sin,cos,tan
print command1 text1, text2, text3 print run caption Dim a, b, c, av As single Private sub command1_click () a=val (text1.text) b=val(text2.text) c =val(text3.text) av=(a+b+c) / 3 Print "av=";av End sub input box label1, label2 run
conditional statements if statement select case if statement <, >, <=, >=, < >, =, and, or if if If..Then If condition then statement pass Dim x as integer Private sub command1_click() X= cint(text1.text) If x>= 50 then text2.text= "pass" End sub If block If condition then End if
pass Dim x as integer Private sub command1_click() X= cint(text1.text) If x>= 50 then text2.text= "pass" text2.fontsize=18 end if End sub If.. Then.. Else If condition then Else End if Dim x As Integer Private Sub command1_click() x = CInt(Text1.Text) If x >= 50 Then Text2.Text = "pass" Else Text2.Text = "fail" End If If.. then.. Elseif..Else If condition then Elseif condition then
Else End if Dim x As String Private Sub command1_click() x = text1.text If x = "Muhammad" Then MsgBox "hello, Muhammad" ElseIf x = "hasan" Then MsgBox "hello,hasan" Else MsgBox "hello, guest" End If If condition then If condition then Else Elseif Else End if option button nested if illegal division operation If Dim a, b, c As Single Private Sub command1_click() a = Val(Text1(0).Text) b = Val(Text2.Text) If Option1.Value Then c=a*b Text3.Text = CStr(c) Else
If b <> 0 Then Text3.Text = CStr(c) Else Text3.Text = "illegal division operation" End If End If Select Statement Select case variables Case value1 Case value2... Case else End select form Dim x As Integer Private Sub Command1_Click() x = CInt(Text1.Text) Select Case x Case 1 MsgBox ("Sunday") Case 2 MsgBox ("Monday") Case 3 MsgBox ("Tuesday")
Case 4 MsgBox ("Thursday") Case 5 MsgBox ("Wednesday") Case 6 MsgBox ("Friday") Case 7 MsgBox ("Saturday") End Select loop statement visual basic counter loop for next For variable = start value to end value step step value Next variable Dim i as integer Private Sub Command1_Click () For i = 1 To 5 Print "hello" Next i hello Conditional Loop Do while Do until Do while Do Do Do while Do while Loop
Do while condition Loop do while Dim i as integer Private Sub Command1_Click () i=1 Do while i <= 5 Print "hello"; i i=i+1 Loop hello Do until Do until Loop Do until condition Loop Dim i as integer Private Sub Command1_Click () i=1 Do Print "hello"; i i=i+1 Loop until i > 5 hello Exit Exit for Exit Do For next Do while
s=1+x+x 2 +x 3 + +x n x Dim I, n, sum as integer Dim x,s as Double Private Sub command1_click () sum = 1 n=cint(text1.text) x=val(text2.text) For i = 1 To n Sum = sum +x^i Next i Text3.text=cstr(sum) nested for For i = 1 To n For j = 1 To m Next j Next i Dim I, j As Integer Private Sub command1_click() For I = 1 To 10 For j = 1 To 10 p=i*j Print I; "*"; j; "="; p, Next j Print Next I
label y x x x y=-x Y=x check box option button 9-10 A 7-8 B 5-6 C 0-4 D