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.

Create Bill

Detail of Form :-

  1.  Select Two form  
  2. Select 8 Text Box for Bill number, Name, Price Quantity, Discount Percent, Total, Discount, and Final Payment.
  3. Select Two Button first for Calculate and Second for Exit.

 Code For Bill :-

Private Sub Command1_Click()
Dim bill, n, p, q, t, dp, d, pay As Integer
bill = Text1.Text
n = Text2.Text
p = Text3.Text
q = Text4.Text
t = p * q
Text5.Text = t
dp = Text8.Text
d = t * dp / 100
Text6.Text = d
pay = t - d
Text7.Text = pay
End Sub

Private Sub Command2_Click()
Form1.Show
Form2.Hide
End Sub

Creating Result Using Check Box & Option Button

  Here are the codes -

Private Sub Command1_Click()
Dim roll, m1, m2, t, p As Integer
roll = Val(Text1.Text)
m1 = Val(Text2.Text)
m2 = Val(Text3.Text)
t = m1 + m2
Text4.Text = t
If Option1.Value = True Then
p = t * 100 / 250
ElseIf Option2.Value = True Then
p = t * 100 / 200
End If
If Check1.Value = 1 Then
p = p + 2
End If
Text5.Text = p
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text4.Enabled = False
Text5.Enabled = False
End Sub
Private Sub Command3_Click()
Form1.Show
Form2.Hide
End Sub

 Design of form :-

Friday 14 June 2013

Count Digit

 

Count Digit :-

In Out-put Enter the 5 to 10 digit in INPUT-BOX Like that :-





This Code for that:-

Private Sub Command1_Click()
Dim n, a, 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
End Sub

Armstrong Number

Armstrong Number Code :-

Design Form like that :- 


And write down that code :-

Private Sub Command1_Click()
Dim i, x, r, n As Integer
n = InputBox("enter the numnber")
x = n
i = 0
While (x > 0)
r = x Mod 10
i = i + r * r * r
x = Int(x / 10)
Wend
If n = i Then
Print "Armstrong"
Else
    Print "not armstrong"
    End If
End Sub