Wednesday 5 February 2014

Code for compare two numbers..

Design form :-
1. Select 2 text box
2. Select 1 command button..

Code :-

Private sub command1_click()
Dim a,b As Integer
a=val(Text1.Text)
b=val(Text2.Text)
If a>b
MsgBox "A is greater then B"
Else
MsgBox "B is greatee then A"
End If
End Sub

Thursday 30 January 2014

Print the value from 10 to 1

Design Form :-
1. Select one command button on form.

Private Sub Command1_Click()
Dim i As Integer
i =10
Do While i>=1
Print i
i = i-1
Loop
End Sub

Count the digit

Design Form :-
1. Select one command button on form.

Now double click on command button then type that code :-

Private Sub Command1_Click()

Dim n As Integer, a As Integer, k As Integer

n =inputbox("enter the number");

while(n>0)
a=n mod 10
k=k+1
n=int(n/10)
wend
print k

Monday 7 October 2013

Using airthmatic operators

Design Form

  1. Select four option button for airthmatic operators
  2. Two Command Button first for calculate and second for Exit.
  3.  Two text box for Enter the value.

Code :-

Private Sub Command1_Click()
Dim a, b, c As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
If Option1.Value = True Then
c = a + b
ElseIf Option2.Value = True Then
    c = a - b
    ElseIf Option3.Value = True Then
    c = a * b
    ElseIf Option4.Value = True Then
    c = a / b
    Else
    MsgBox "please select any option for your result"
    End If
    Text3.Text = c
    End Sub


Private Sub Command2_Click()
Form2.Show
Form1.Hide

Login Code

Design Form -

  1. Select 2 Text Box.
  2. Select 2 Label, First for User Name and Second for Password.
  3. Select 1 Button.
  4. Select 2 Forms first for code and second for next form,

 Code-

Private Sub Command1_Click()
If Text1.Text = "admin" And Text2.Text = "shelu" = True Then
Form12.Show
Form1.Hide
End If
End Sub

Traffic Light Code with Timer

Form Design -

  1. Select 3 shape on the form 
  2. Click on shape properties and select shape - Circle.
  3. Click on shape properties and select Fill Style - Solid.
  4. Click on shape properties and select Fill Color - Red, Yellow, Green.
  5. Select Timer form toolbox.
  6. Click on Timer properties and feel interval time 1500. 

Code -

Private Sub Timer1_Timer()
If Shape1.Visible Then
Shape2.Visible = True
Shape1.Visible = False
Shape3.Visible = False
ElseIf Shape2.Visible Then
Shape3.Visible = True
Shape2.Visible = False
Shape1.Visible = False
Else
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
End If
End Sub


 

All Types of loop

Code for Loops 

A. For next ...Loop :-

Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 10
Print i
Next i
End Sub

B. Do while.....Loop

Private Sub Command2_Click()
Dim i As Integer
i = 1
Do While i <= 10
Print i
i = i + 1
Loop
End Sub

C. Do until....Loop

Private Sub Command3_Click()
Dim i As Integer
i = 10
Do While i >= 1
Print i
i = i - 1
Loop
End Sub

D. Do...Loop While 

Private Sub Command4_Click()
Dim i As Integer
i = 1
Do
Print i
i = i + 1
Loop While i <= 10
End Sub

 E. Do....until Loop

Private Sub Command5_Click()
Dim i As Integer
i = 10
Do
Print i
i = i - 1
Loop While i >= 1
End Sub

F. While...Wend

Private Sub Command6_Click()
Dim i As Integer
i = 1
While i <= 10
Print i
i = i + 1
Wend
End Sub.