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

Sample Assembly Program – Looping Operation

; This program will display ABCD vertically with sounds

.model small
.code
.stack 100
org 100h

start :
mov ah, 02h
mov cl, 41h

skip :
mov dl, cl
int 21h
mov dl, 0ah ; move one line down
int 21h
mov dl, 0dh ; move to the first column
int 21h
inc cl
cmp cl, 45h ; if true the output is 0, if false output 1
jnz skip
int 27h
end start

Assembly Language Sample Program

; This is my first sample TASM program
; This program will print characters ABC on the screen

.model small
.code
.stack
org 100h

start:

mov ah, 02h
mov cl, 41h
mov dl, cl
int 21h
mov cl, 42h
mov dl, cl
int 21h
mov cl, 43h
mov dl, cl
int 21h

int 27h
end start

Assembly Language Programming

Assembly language is consider one of the most powerful programming languages ever developed and is consider the only low level language. Low-level languages are representation of machine language in a form that is easy to understand by human.

Assembly Language is an example of low-level language. It has a direct control to the processor which makes it more powerful than other languages.

Assembly Language Coding Format

An assembler reads a program in low-level language format and generates codes of equivalent program in machine language. To understand Assembly language programming you must be familiar with the instruction and how to use it. Basic knowledge in the machine architecture is also important in creating the source code for a certain task. When you create a program in Assembly language you must do more than describe a formal solution to your program code. Programmers must break their codes into small basic steps. These steps tell the processor what to do, one instruction at a time.

Assembly Language has four field, namely

(Label)
A name defined with specific attribute maximum length is 31 characters and end with;
Characters such as A – Z / 0-9/?, @, _, and $

Mnemonic
Abbreviated spellings of instructions
Contains 2 –to -7 letter acronym for the instruction

[Operand]
Part of instruction that represents a value on which the instruction or directive acts.
Contain either 1 or 2 operands, separated from the mnemonic by 1 space or tab.

[;comment]
All or part of a statement that is ignored by the Assembler, preceded by a semicolon ;

SAMPLE

MOV dl, 0ah ; Move one line down

Assembly Language Program Part

.model
- specifies the memory model that you want to use

.stack - defines the beginning and end of stacks

.data - allows the user to create a data segment, data destination

.code - defines program instruction

start - tells the compiler the beginning of the program body

end - finish the assembler program

How to construct an Assembly Language Program
  1. Create a source code using a text editor program (MS-DOS Edit, MS Windows Note Pad). The extension name is .ASM
  2. Using the TASM compiler, create an Object File with an extension name of .OBJ
  3. Linking the Object File (.OBJ) will produce an Executable File