Saturday, March 19, 2011
Looping Statement repetition.
----- Visual Basic 0.6 ( Looping Repetition )
------- GRADE CALCULATOR CODES.
Dim intCount As Integer, strChecked As String
If chkDone(Index).Value = vbChecked Then
cmdDisplay.Enabled = True
txtScore(Index).Enabled = True
txtScore(Index).SetFocus
Else
txtScore(Index).Text = 0
txtScore(Index).Enabled = False
strChecked = "N"
Do While intCount <= 4 And strChecked = "N"
If chkDone(intCount).Value = vbChecked Then
strChecked = "y"
End If
intCount = intCount + 1
Loop
If strChecked = "n" Then
cmdDisplay.Enabled = False
End If
End If
End Sub
Private Sub cmdClear_Click()
Dim x As Integer
For x = 0 To 4
chkDone(x).Value = False
txtScore(x).Text = ""
Next x
lblGrade.Caption = ""
txtName.SetFocus
End Sub
Private Sub cmdDisplay_Click()
Dim intEarned As Integer, intPossible As Integer
Dim sngRatio As Single, intCount As Integer
For intCount = 0 To 4
If chkDone(intCount).Value = vbChecked Then
intEarned = intEarned + Val(txtScore(intCount).Text)
Select Case intCount
Case 0 To 2
intPossible = intPossible + 10
Case Else
intPossible = intPossible + 50
End Select
End If
Next intCount
sngRatio = intEarned / intPossible
Select Case sngRatio
Case Is >= 0.9
lblGrade.Caption = "A"
Case Is >= 0.8
lblGrade.Caption = "B"
Case Is >= 0.7
lblGrade.Caption = "C"
Case Is >= 0.6
lblGrade.Caption = "D"
Case Else
lblGrade.Caption = "F"
End Select
End Sub
Private Sub cmdExit_Click()
Unload frmGrade
End Sub
Private Sub cmdPrint_Click()
PrintForm
End Sub
Private Sub Form_Load()
frmGrade.Top = (Screen.Height - frmGrade.Height) / 2
frmGrade.Left = (Screen.Width - frmGrade.Width) / 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Const conBtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
Dim intUserResponse As Integer
intUserResponse = MsgBox("Do you want to exit?", conBtns, "Grade Application")
If intUserResponse = vbNo Then 'User does not want to quit the app
Cancel = 1 'prevent form unload.
End If
End Sub
Private Sub txtScore_GotFocus(Index As Integer)
txtScore(Index).SelStart = 0
txtScore(Index).SelLength = Len(txtScore(Index).Text)
End Sub
Thursday, March 10, 2011
STRUCTURED PROGRAMMING
SELECTION CONSTRUCTS
The Selection constructs are used when the flow of execution may flow down two or more paths.I compile it in .Exe
THE IF STATEMENT
The If statement is used to control the flow of execution down one of two or more paths, depending on the result of a logical test. The Else If statement may be used to specify conditions should previous conditions be false, and Else may be used should none of the above be true.
of course on the Selection Statement you can see may example below the last topic on our subject.
-I use the Select Case construct to Access the code, according to which arrow key is pressed on the keyboard or in the screen using the point Cursor.
The Select statement can be used when multiple If statements become messy and difficult to read. Each Case statement is evaluated from the top down. Should the Case statement be true, the section of code associated with the condition is executed. Case Else is used as a catch all.
Tuesday, March 1, 2011
Programming Practices
a.) Meaningful Identifiers
Dim mAccessCode As Long
Dim message As String
Declaires the variable mAccessCode as type Long. Like Integer , Long stores whole numbers (w/o decimal point). the rage of the values that can be stored in a Long are-- 2,147,483,648 to 2,147,483,647.
The Long is a type of character &. with m allows them to be identified easily.
b.) Logic Practice
Select Case mAccessCode
Case Is < 1000
message = "Access Denied"
Beep
Case 1645 To 1689
message = "Technician Personnel"
Case 8345
message = "Custodial Services"
Case 55875
message = "Special Services"
Case 999898, 1000006 To 1000008
message = "Specific Personnel"
Case Else
message = "Access Denied"
End Select
Placing a larger value on the left side of keyword To in a Case is a logic error and is ignored at run-time.
When using the optional Case Else statement in a Select Case structure, not placing the Case Else as the last statement is a syntax error.
c.) Coding Practice
Case Is < 1000
Keywords Is along with the comparison operator < , specifies the rage of values to test.d.) Notes and Comments
Dim message As String
mAccessCode = txtDisplay.Text
txtDisplay.Text = ""
a.) Program Listing
Private Sub cmdZero_Click()
txtDisplay.Text = txtDisplay.Text & "0"
End Sub
I listed the properties for cmdZero, Although i did not use other numbered buttons, they have the same property settings.
b.) Program Specification
Security Keypad
-A Simple Vb Programming, Easy Operation
-A Simple Vb Programming, Easy Operation
- It can also a Security Access Control Keypad ( Company User )-For switching locks,entry and security systems.
-Has a limited Users codes.
Numbers combinations are possible for the 4 independent user codes:
1645 to 1689 (Technician Personnel)
8345 (Custodial Services)
55875 (Special Services)
999898, 1000006 to 1000008 (Scientific Personnel).
User code 1000 can be altered to act as a Panic code for reporting panic to an "Access Denied".
c.) File Layouts and Record Description
I listed the properties for cmdZero, Although i did not use other numbered buttons, they have the same property settings.
Tthe variable mAccessCode as type Long. Like Integer , Long stores whole numbers (w/o decimal point).
The rage of the values that can be stored in a Long are-- 2,147,483,648 to 2,147,483,647.
The rage of the values that can be stored in a Long are-- 2,147,483,648 to 2,147,483,647.
The Long is a type of character &.
1stLogEntry.AddItem Now & Space$ (3) & message
-It has the ability to record the time and date to the text box and it tells as if it is "Access Denied" or granted.
Now is the current system time and date.
function Space$(3) creates and returns a string containing spaces.
function Space$(3) creates and returns a string containing spaces.
d.) Operating Instruction
including the Case Else statement focuses the programer on the need to process exceptional conditions. In some situation s, no Case Else processing is needed.
The required End Select terminates the Select Case structure, such indentation improves program readability.
The required End Select terminates the Select Case structure, such indentation improves program readability.
Subscribe to:
Posts (Atom)


