This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

Sunday, December 9, 2012

Fabonacci series,factorial of a number or prime number in visual basic.


Dim i, f, n As Integer
Dim a, b, c As Integer
Private Sub Cmdtable_Click()
n = Val(Text1.Text)
Me.Cls
For i = 1 To 10 Step 1
Me.Printi * n
Next i
End Sub

Private Sub CmdFabonaccii_Click()
Me.Cls
a = 0
b = 1
Me.Print a
Me.Print b
For j = 3 To 10 Step 1
c = a + b
a = b
b = c
Me.Print c
Next j
End Sub

Private Sub CmdFactorial_Click()
fact = 1
n = Val(Text1.Text)
i = 1
Do While (i<= n)
fact = fact * i
i = i + 1
Loop
MsgBox "the factorial is: " & fact
End Sub
Private Sub CmdPrime_click()
n = Val(Text1.Text)
Me.Cls
If n Mod 2 = 0 Then
Me.Print n & " is not prime"
Else
Me.Print n & " is prime"
End If
End Sub


Private Sub CmdExit_Click()
End
End Sub

 Output


 
Note:- Please set some property of your control like caption or id corresponding to your control

Program for calculating the bill using select case in visual basic


Dim unit As Integer
Dim amt As Double
Private Sub CmdCalculate_Click()
unit = Val(Txtnum1.Text)
Select Case unit
Case 0 To 150
amt = CDbl((250 + 0.6) * unit)
Case 151 To 300
amt = CDbl((250 + 100 + 1#) * (unit - 150))
Case 301 To 450
amt = CDbl((250 + 200 + 1.25) * (unit - 300))
Case Else
amt = CDbl((250 + 300 + 1.75) * (unit - 450))
End Select
LblAmt.Caption = amt
End Sub
Private Sub CmdExit_Click()
End
End Sub



 Output
Note:- Please set some property of your control like caption or id corresponding to your control