Thursday, September 25, 2008

Volume of a Cylinder - Sample Visual Basic Program



This program compute the volume of cylinder

Private Sub Command1_Click()
radius = " "
hght = " "
volume = " "
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub OK_Click()
r = Val(radius.Text)
h = Val(hght.Text)
pi = 22 / 7
v = pi * (r ^ 2) * h
volume.Text = Str$(v)
End Sub

Private Sub radius_Change()

End Sub

Sample Visual Basic Program - Convert Celsius and Farenheit


This Program computes for celcius and farenheit


'celsius
Private Sub Command1_Click()
Text2.Text = (5 / 9) * (Text1.Text - 32)

End Sub

'farenheit
Private Sub Command2_Click()
Text2.Text = (9 / 5) * Text1.Text + 32
End Sub

Sample Program Visual Basic - Calculation Program


  • The hands on example illustrates variables, the Val function, and the FormatCurrency function.
  • Three text boxes, seven labels, and four command buttons comprise the solution
  • Be aware that there is a problem with the format command in general. The problem is that the discount amount is visually rounded by the FormatCurrency function to display in the “15% Discount” label. However, the calculation of the discount can create an answer that contains three or four decimal places. When the discount is subtracted from the Extended price, the answer can appear to be incorrect. Convince yourself. Try this: 10 units at $39.95. The answer displayed for Extended price is $399.50, which is correct. The answer displayed for the discount is $59.93 (rounded up from the actual answer of 59.925). The amount displayed for the Discounted Price is $339.58, which is the rounded result of 399.50 – 59.925. The solution—without using the Round function because it has not been introduced yet—is to add 5/10ths of a penny (.005) to the discount. Then both the discount and the resulting discounted price will both appear to be correct and will be correct!


Program Source Code

Dim quan, price, exprice, discount As String
Private Sub Calculate_Click()
exprice = quan * price
Text4.Text = FormatCurrency(exprice)
Text5.Text = exprice * discount
Text6.Text = Text4.Text - Text5.Text
Text4.Text = FormatCurrency(Text4.Text)
Text5.Text = FormatCurrency(Text5.Text)
Text6.Text = FormatCurrency(Text6.Text)
End Sub

Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
quan = 0
price = 0
exprice = 0
discount = 0.15
Text1.Text = n_quan
Text3.Text = n_price
Text4.Text = n_exprice
End Sub

Private Sub Label9_Click()
End Sub

Private Sub Text1_Change()
quan = Val(Text1.Text)
End Sub

Private Sub Text3_Change()
price = Val(Text3.Text)
End Sub

Wednesday, September 24, 2008

Sample Visual Basic Program - Order Information



Private Sub Command1_Click()
Dim cap, esp, latte, icecap, icelatte As Boolean
Dim i_amount As Currency
Dim n_tax As Currency
Dim totaldue As Currency
Dim q_amount As Integer
Const n_cap = 1.5, n_esp = 2, n_latte = 2.5, n_icelatte = 3, n_icecap = 3.5, tax = 0.12
q_amount = Val(txtquan.Text)
If cappucino.Value = True Then
i_amount = q_amount * n_cap
lblamount.Caption = n_cap
lblsubtotal.Caption = i_amount
ElseIf espresso.Value = True Then
i_amount = q_amount * n_esp
lblamount.Caption = n_esp
lblsubtotal.Caption = i_amount
ElseIf late.Value = True Then
i_amount = q_amount * n_latte
lblamount.Caption = n_latte
lblsubtotal.Caption = i_amount
ElseIf icedlatte.Value = True Then
i_amount = q_amount * n_icelatte
lblamount.Caption = n_icelatte
lblsubtotal.Caption = i_amount
ElseIf icedcap.Value = True Then
i_amount = q_amount * n_icecap
lblamount.Caption = n_icecap
lblsubtotal.Caption = i_amount
End If
If checktakeout.Value = 1 Then
n_tax = tax * i_amount
Else
lbltax.Caption = 0
End If

totaldue = i_amount + n_tax
lbltax.Caption = n_tax
lbltotaldue.Caption = totaldue

End Sub
Private Sub cappucino_Click()
MsgBox "Cappucino $1.5"
End Sub

Private Sub Command2_Click()
txtquan = ""
lblamount = ""
lblsubtotal = ""
lbltax = ""
lbltotaldue = ""
End Sub

Private Sub Command3_Click()
txtquan = ""
lblamount = ""
lblsubtotal = ""
lbltax = ""
lbltotaldue = ""
End Sub

Private Sub Command5_Click()
End
End Sub

Private Sub Label3_Click()

End Sub

Private Sub espresso_Click()
MsgBox "Espresso $2.0"
End Sub

Private Sub icedcap_Click()
MsgBox "Iced Cappucino $3.5"
End Sub

Private Sub icedlatte_Click()
MsgBox "Iced Latte $3.00"
End Sub

Private Sub late_Click()
MsgBox "Latte $2.5"
End Sub

*This is one of my programming assignment in my computer course

Monday, September 22, 2008

Password – Sample Assembly Program

; This program will validate if the user enter a correct password

.mode small
.code
.stack
org 100h

START:
MOV AH, 07 ; use service 7 command
INT 21H
CMP AL, ‘G’ ; was the type letter = G?
JNE START ; if no start over
INT 21H ; if yes get next letter
CMP AL, ‘A’; was the type letter = A?
JNE START ; if no start over
INT 21H ; if yes get the last letter
CMP AL, ‘B’ ; was the type letter = B?
JNE START ; if no start over
FINISH:
INT 27H ; if yes terminate
END START

Repeating Characters – Sample Assembly Program

; This program will repeat any character typed on the keyboard

.model small
.code
.stack
org 100h

START:
MOV AH, O6 ; use service 6 command

TOP:
MOV DL, OFFH ; read the character
INT 21H
JZ TYPEOUT ; if there is was no character, type out old one
MOV CL, AL ; store new character
CMP AL, ‘E’ ; was is an ‘E’?
JE FINISH ; if yes jump to the end of the program

TYPEOUT:
MOV DL, CL ; type out store character
INT 21H
JMP TOP ; jump to the beginning

FINISH:
INT 27
END START

Sample Assembly Program – User Input Function

; This program will accept an uppercase letters and convert it to lowercase letters

.model small
.code
.stack
org 100h

start:
jk: mov ah, 01h
int 21h
add al, 20h
mov ah, 02h
mov dl, al
int 21h
jnz jk
int 27h
code ends
end start