0% found this document useful (0 votes)
67 views

VB Cods

This document contains code snippets from several Visual Basic programs. The code demonstrates different programming concepts like: 1. Using objects like Form, Command Button, Text Box. 2. Writing simple programs with concepts like variables, arithmetic operations, input/output. 3. Using loops and conditional statements like For Next, If/Then. 4. Working with data like arrays, recordsets for adding, deleting, navigating records. 5. Validating and formatting input, displaying messages and focusing controls. The document provides examples of basic and some intermediate level VB programming concepts in a teaching/learning context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

VB Cods

This document contains code snippets from several Visual Basic programs. The code demonstrates different programming concepts like: 1. Using objects like Form, Command Button, Text Box. 2. Writing simple programs with concepts like variables, arithmetic operations, input/output. 3. Using loops and conditional statements like For Next, If/Then. 4. Working with data like arrays, recordsets for adding, deleting, navigating records. 5. Validating and formatting input, displaying messages and focusing controls. The document provides examples of basic and some intermediate level VB programming concepts in a teaching/learning context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

fm%da.a?

ï fla; ,súu
Objects i|yd kï fh§fï § ms<s.;a iïm%odhla o ;sfí' Tn kula fhdackd l< úg
Object tflys iajrEmhg wod< jk mßÈ Visual Basic tys uq,g wlaIr ;=kla tl;=
lrhs

Object tl Uq,g tl;= lrk moh ksoiqk


Form frm frmcalculator
Command Button cmd , btn cmdExit , btnStart
Label lbl lblStart ,lblEnd
Text Box txt txtTime , txtName
Menu mnu mnuExit , mnuSave
Check box chk chkChoice
Program 1
Private Sub Form_Load()
Form1.Show
Print “ This is my first Visual Basic Program “
End Sub

Private Sub , End Sub kue;s mo ta


wdldrhg u ,sjsh hq;= h' Print hkq
uqøKh lrkak fkdj " ;srh u; ms<sìUq lrkak
nj f;areï .; hq;= h'
Program 2

Private Sub Form_Activate()


Print 35 + 15
Print 35 - 15
Print 15 * 15
Print 45 / 15
End Sub

w.hka iq¿ ù my,g ,súu isÿfõ


Program 3

Private Sub Form_Activate()


Print 35 + 15,
Print 35 – 15,
Print 15 * 15,
Print 45 / 15,
End Sub

w.hka iq¿ ù tl fma,ashg ,súu isÿfõ


Program 4
Private Sub Form_Activate()
A = 15
B = 20
C = 40
Print A+B+C
Print A-B+C
Print C/B
End Sub
;=ka jk Program tl jeä ÈhqKq lr 4 jk Program h ,shd ;sfí'
A , B iy C w;r wka;a in|;d lsysmhla ,shd ;sfí‘ tajdfha
w.hkays lsishï fjkila isÿ jQ wjia:djl §tla tla m%ldYkfha w.h
fjkia lsÍu i|yd iEfyk ld,hla ñvx.= lsÍug isÿ fjhs‘ ta fjkqjg .; jk
A , B iy C ys w.h fjkia lsßfï myiqlu fï Program fhka ,efí'
Private Sub Command1_Click()
Total.Caption = Val(Text1) + Val(Text2)
End Sub
Program 5
Repetition control structure

Program tll tla;rd fldgila kej; kej;;a lsysm jdrhla


l%shd;aul úu

1
For Next 2
3
Private sub Command1_Click() .
Dim i As interger .
For i = 1 to 10 10
Print i
Next i
End Sub
Private Sub Command1_Click()
Dim N As Integer
Cls
For N = 1 To 10
Print N
Next N
End Sub

Private Sub Form_Load()


Me.FontSize = 14

End Sub

For N 1 To 10 Step 2
For N-14 To 70 Step 7
For N -0.2 To 1 Step 0.1
For N 10 To 1 Step -1
T;af;a yd brÜfÜ ixLH uqøKh
Private Sub Cmd1_Click()
For I = 1 To 50
If I Mod 2 = 0 Then
Print I
End If
Next
End Sub

Private Sub Cmd2_Click()


For I = 1 To 50
If I Mod 2 = 1 Then
Print I
End If
Next
End Sub
Private Sub Command1_Click()
Dim N As Integer Do While Loop
Cls
Me.FontSize = 18
Me.ForeColor = RGB(0, 0, 255)
Print " For Next"
N=1
For N = 1 To 10
Print N
Next N
End Sub
Private Sub Command2_Click()
Dim N As Integer
Cls For Next Loop
Me.FontSize = 18
Me.ForeColor = RGB(255, 0, 0)
Print " Do While "
N=1
Do While N <= 10
Print N
N=N+1
Loop
End Sub
Private Sub Command1_Click()
Text1 = Val(InputBox("Enter the Second Number ")) +
Val(InputBox("Enter the First Number "))
End Sub
Private Sub Cmd1_Click()
MsgBox "Hello you are right", 4 + 64,
"Masege"
End Sub

Private Sub Cmdcheck_Click()


If Opt2.Value = True Then
Label3.Caption = " Answer is Corect"
Else
Label3.Caption = "Answer is in Corect"
End If
End Sub
Private Sub Cmb_Click()
Label2.Caption = Text1.Text + " " + "is" + " " + Cmb.Text
End Sub

Private Sub Form_Load()


Label3.Caption = Date
Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()


Label4.Caption = "MY Program is good"
End Sub
D wl=r 10 jrla uqøKh lsßu

Private Sub Command1_Click()


For i = 1 To 10
Print "D"
Next
End Sub

Private Sub Form_Load()


Me.FontSize = 12
Me.FontBold = True

End Sub
jD;a;hl mßñ;sh yd j¾.M,h fiùu

Private Sub Command1_Click()


Dim r, SQ
Const i = 22 / 7
r = InputBox("Input r Value")
SQ = 2 * i * r
Print SQ
End Sub

Private Sub Command2_Click()


Dim r, CIR
Const i = 22 / 7
r = InputBox("Input r Value")
CIR = i * r ^ 2
Print CIR
End Sub
fikaáóg¾ yd w.,a w;r mßj¾:kh

Private Sub Command1_Click()


Dim Cm, Feet
Const i = 2.54
Cm = InputBox("Input Cm value")
Feet = (Cm / i) / 12
Print Format(Feet, "#### 0.00")
End Sub
is,skavrhl j¾.M,h ,nd .eksu

Private Sub Command1_Click()


Dim r, V, h
Const i = 22 / 7
r = InputBox("Input r Value ")
h = InputBox(" Input h Value ")
V=i*r^2*h
Print V
End Sub
Private Sub Command1_Click()
Dim N(5) As Integer
Private Sub Command3_Click()
Dim i As Integer
Dim N(10) As String
For i = 1 To 5
Dim i As Integer
N(i) = InputBox("Input Value")
For i = 1 To 10
Next
N(i) = InputBox("Enter you a Name")
For i = 1 To 5
Next
Print N(i)
For i = 1 To 10
Next
Print N(i)
End Sub
Next
End Sub Private Sub Command2_Click()
Dim N As Integer
Dim i As Integer
For i = 1 To 5
N = InputBox("Value")
Next
For i = 1 To 5
Print N
Next
End Sub
Private Sub Command1_Click() Private Sub Command2_Click()
Dim N As Integer Dim Sum As Long
Dim Sum As Integer Dim i As Integer
Dim i As Integer For i = 1 To 1000
For i = 1 To 5 If i Mod 5 = 0 Then
N = InputBox("Enter a value") Sum = Sum + i
Sum = Sum + N End If
Print Sum
Next Next
Print Sum

End Sub
End Sub
Private Sub Command1_Click()
Private Sub Command1_Click() Dim Res As Integer
Dim Res As Integer Res = MsgBox("Are You went to Add",
Res = MsgBox("Are You went to Add", vbYesNo, "Add")
vbYesNo, "Add") If Res = vbYes Then
If Res = vbYes Then Data1.Recordset.AddNew
Data1.Recordset.AddNew Text1.SetFocus
Text1.SetFocus Else
Else If Res = vbNo Then
If Res = vbNo Then Exit Sub
Exit Sub End If
End If End If
End If
End Sub
End Sub

PTO
Private Sub Command2_Click() Private Sub Command3_Click()
Text1 = "" If Not Data1.Recordset.EOF Then
Text2 = "" Data1.Recordset.MoveNext
Text3 = "" Else
Text4 = "" MsgBox "End of data", 0 + 64, "Warning"
Text5 = "" End If
Text6 = "" Call New_Data
Text7 = ""
Text8 = "" End Sub
Text10 = ""
Text11 = "" Private Sub Command4_Click()
If Not Data1.Recordset.BOF Then
End Sub Data1.Recordset.MovePrevious
Else
MsgBox "End of data", 0 + 64, "Warning"
End If
Call New_Data

End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command1_Click() Private Sub Command3_Click()
If Not DtaSBA.Recordset.EOF Then Dim Res As Integer
DtaSBA.Recordset.MoveNext Res = MsgBox("Are You went to Add",
Else vbYesNo, "Add")
MsgBox "End of data", 0 + 64, "Warning" If Res = vbYes Then
End If DtaSBA.Recordset.AddNew
Text1.SetFocus
End Sub Else
If Res = vbNo Then
Private Sub Command2_Click() Exit Sub
If Not DtaSBA.Recordset.BOF Then End If
DtaSBA.Recordset.MovePrevious End If
Else
MsgBox "End of data", 0 + 64, "Warning" End Sub
End If
End Sub
Private Sub Command4_Click()
Text1 = "" Private Sub Command5_Click()
Text2 = "" DtaSBA.Recordset.MoveNext
Text3 = "" End Sub
Text4 = ""
Text5 = "" Private Sub Command6_Click()
Text6 = "" DtaSBA.Recordset.MoveLast
Text7 = "" End Sub
Text8 = ""
Text9 = ""
Text10 = ""
Text11 = "" Private Sub Text15_GotFocus()
Text12 = "" Text15.Text = Val(Text14) / 9
Text13 = "" Text15.Text = Format(Text15, "0.00")
Text14 = "" End Sub
Text15 = ""
End Sub
Private Sub Text14_GotFocus()
Text14.Text = Val(Text5) + Val(Text6) + Val(Text7) + Val(Text8) + Val(Text9) +
Val(Text10) + Val(Text11) + Val(Text12) + Val(Text13)
End Sub
Private Sub Command1_Click()
If T1.Text = "abc" Then
Form1.Enabled = True
Else
Unload Me
Unload Form1
End If
End Sub

Private Sub Form_Load()


Form1.Show
End Sub

You might also like