Saturday, March 19, 2011

Repetition

Sample




CODE


Option Explicit

Private Sub cmdClear_Click()
Cls
End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdTryIt_Click()

Dim lngFactorial As Long
Dim intInputNbr As Integer
Dim intLoopCtr As Integer

intInputNbr = Val(InputBox("Enter a number:", "For/Next Loop"))

lngFactorial = 1

For intLoopCtr = 1 To intInputNbr
lngFactorial = lngFactorial * intLoopCtr
Next

Print CStr(intInputNbr); "! = "; lngFactorial

End Sub

Explanation
Repetition is also known as the looping or iteration control structure. Looping is the process of repeatedly executing one or more steps of an algorithm or program; it is essential in programming, as most programs perform repetitious tasks.

Saturday, March 12, 2011

sequence & selection

Selection

A SELECTION, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event.


CODE

Explanation
From its word select..example you just select or click the add button .. then its automatically add your input.. and when you select the subtract button you inputs are subtracted. In coding for this system you must put codes in every command buttons.

Sequence
"Sequence" refers to an ordered execution of statements.
A sequence is an ordered list of objects


CODE

Explanation
A sequence is a process, example when you click a command button you will see the next form and when you click an another command button you will see again a another form or the next form.In this system you can use "IF" and "END IF" statement.

Wednesday, March 2, 2011

Assignment - [03/02/11]

I used VISUAL BASIC 6.0 for the program.

1) Programming Readiability
--> Identifiers are used to name variables.
The identifiers that I used are: inNum1,intNum2,intNum3,txtBet,txtReset so that they are easy to determine.

--> Logic Structure
The logic structure that I used for coding this program is simple.

--> Coding Practice It should be written in the code that will do what is needed.
Sometimes it takes some errors when you code your program and it will debug when you run it. That's why you must understand your program well when you are coding.


--> Notes & Comments used to embed programmer-readable annotations in the source code of a computer program. Comments are usually added with the purpose of making the source code easier to understand.

2) Program Documentation

--> Program Listing a literal listing of all or part of a program. Used keyword and proper naming convention.
lblBet,lblWin,lblMessage

--> Program Specification the keyword is the requirements. You may type numbers on the text box and click the bet for the result.


--> File Layout & Record Description it should written the kinds of files used and explains details with they contains.
That program is an slotmachine, that contain numbers and you may get your bet when you play it.

--> Operating Instruction contains the actual instructions of the program. The list of possible errors and tells the user what to do.
There are some possible errors, it can be on the identifiers that you used. You must look or check carefully the identifiers that you used so that it may not cause of debugging your program.



Here is the Code of the Program
Private Sub cmdPlay_Click()

Dim intNum1 As Integer, intNum2 As Integer, intNum3 As Integer
Dim dblBet As Double, dblWin As Double

intNum1 = Rnd * 9
intNum2 = Rnd * 9
intNum3 = Rnd * 9
lblNumber.Caption = intNum1
lblNumber1.Caption = intNum2
lblNumber2.Caption = intNum3

If intNum1 = intNum2 And intNum1 = intNum3 Then
dblBet = txtBet.Text
dblWin = dblBet * 3
lblMessage.Caption = "You Won" & "P" & Format(dblWin, "standard")
Else
lblMessage.Caption = "Sorry, try your luck next time!!"
End If


End Sub

Private Sub cmdReset_Click()

lblNumber.Caption = ""
lblNumber1.Caption = ""
lblNumber2.Caption = ""
txtBet.Text = ""

End Sub