UQ Students should read the Disclaimer & Warning
Note: This page dates from 2005, and is kept for historical purposes.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>COMP2301 - Assignment 3 - User Interface in Visual Basic</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
.wrong {
background: #FF9999;
}
body {
background: url(_img/DSC04989.jpg) fixed center;
font-family: "Arial Unicode MS", Arial, Helvetica, sans-serif;
}
th, td, textarea {
border: 1px solid #000000;
padding: 0 1ex;
background: transparent;
overflow: hidden;
}
table {
border: none;
}
-->
</style>
</head>
<body>
<h1>COMP2301 – Assignment Three – User Interface in Visual Basic</h1>
<p> This assignment is a pass/fail assignment. I achieved a pass.</p>
<p>The goal of this assignment is to design a user interface in Visual Basic.</p>
<p>This program must provide the functionality of <a href="COMP2301-assignment-1" title="COMP2301 Assignment 1">assignment
1</a> with a number of enhancements. </p>
<p> Although the functional specifications for the stop watch remains basically
the same there is no longer any limit to how the graphics and user interface
are drawn to the screen. </p>
<p> You may use or recode as much of your assignment one code as you see fit. </p>
<h2>New features required for the user interface </h2>
<ul>
<li> Start / Stop button to start/stop the stop watch (one button, context sensitive
label) </li>
<li> Set clock counting mode (forward/ backwards) </li>
<li> Preset start time to any [minute, second] setting </li>
<li> Reset start time to zero minutes, zero seconds </li>
<li> Set alarm time (Alarm is displayed by blinking stop watch for 3 seconds) </li>
<li> Select colour from pallet for
<ul>
<li> stop watch face </li>
<li> minute hand </li>
<li> second hand </li>
<li> digital display (one colour for frame and one digits) </li>
</ul>
</li>
<li> Set option Digital display on/off </li>
<li> Store and restore from the last 5 custom setups (counting mode, colour
settings, Alarm, digital display status (on/off) ... ) </li>
<li> Provide a Menu System with the following
<ul>
<li> File → Exit </li>
<li> Help → About (About must bring up a modal dialog box, with project
information including Student Name, Number etc) </li>
</ul>
</li>
</ul>
<h2>General </h2>
<ul>
<li> Code comments must correctly reference the work of others </li>
<li> Code must be readable, well structured and conform to the pre-defined style </li>
<li> The solution must demonstrate the use of check boxes, sliders, text
input and pull down lists </li>
<li> Users must be able to store and restore a previous configuration at will </li>
<li> Reasonable error checking is required. Eg Program must handle invalid entries
(invalid start time or alarm time) gracefully </li>
</ul>
<p><em>Note: This assignment was intentionally coded as poorly as possible. After
putting much effort into <a href="COMP2301-assignment-2" title="COMP2301 Assignment 2">assignment 2</a>, and
then realising that no one noticed or cared (I could have had <a href="COMP2301-assignment-2" title="COMP2301 Assignment 2">assignment
2</a> passed irregardless of whether it even worked or not), I decided to code this
assignment using whatever idea first occurred to me, with no restructuring
or refactoring at all. This made the assignment easy, and had the side effect
of making it look horrible – more effort went into getting it to look as bad
as possible, than anything else. </em></p>
<p><a href=".//COMP2301-assignment-3-stopwatch.exe" title="Downloadable application - Stopwatch">Compiled
(WIN32) binary</a> (60 KB) </p>
<p>Clock.frm<br />
<textarea name="k" cols="82" rows="1182" readonly="readonly" title="Visual Basic Code">VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmClock
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 0 'None
Caption = "Stopwatch"
ClientHeight = 6105
ClientLeft = 150
ClientTop = 720
ClientWidth = 7935
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
MousePointer = 13 'Arrow and Hourglass
Picture = "Clock.frx":0000
ScaleHeight = 6105
ScaleWidth = 7935
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.Frame frmLoadSave
BackColor = &H00FFFFFF&
Caption = "Load/Save"
Height = 1815
Left = 0
TabIndex = 29
Top = 720
Width = 1455
Begin VB.CheckBox chkClearSaved
BackColor = &H00FFFFFF&
Caption = "Clear Saved"
Height = 255
Left = 120
TabIndex = 37
Top = 1440
Width = 1215
End
Begin VB.CommandButton cmdSave
Caption = "Save"
Height = 255
Left = 480
TabIndex = 36
Top = 840
Width = 735
End
Begin VB.CommandButton cmdLoad
Caption = "Load"
Enabled = 0 'False
Height = 255
Left = 360
TabIndex = 35
Top = 480
Width = 735
End
Begin VB.OptionButton optLoadSaveFour
BackColor = &H00FFFFFF&
Caption = "Option1"
Enabled = 0 'False
Height = 255
Left = 240
TabIndex = 34
Top = 240
Width = 255
End
Begin VB.OptionButton optLoadSaveThree
BackColor = &H00FFFFFF&
Caption = "Option2"
Enabled = 0 'False
Height = 255
Left = 120
TabIndex = 33
Top = 720
Width = 255
End
Begin VB.OptionButton optLoadSaveFive
BackColor = &H00FFFFFF&
Caption = "Option3"
Enabled = 0 'False
Height = 255
Left = 720
TabIndex = 32
Top = 240
Width = 255
End
Begin VB.OptionButton optLoadSaveTwo
BackColor = &H00FFFFFF&
Caption = "Option4"
Enabled = 0 'False
Height = 255
Left = 480
TabIndex = 31
Top = 1200
Width = 255
End
Begin VB.OptionButton optLoadSaveOne
BackColor = &H00FFFFFF&
Caption = "Option5"
Height = 255
Left = 1080
TabIndex = 30
Top = 1200
Value = -1 'True
Width = 255
End
End
Begin ComctlLib.ProgressBar ProgressBar
Height = 135
Left = 720
TabIndex = 28
Top = 5880
Width = 6255
_ExtentX = 11033
_ExtentY = 238
_Version = 327682
Appearance = 1
Max = 59
End
Begin VB.Timer TimerAlarmFlash
Left = 1920
Top = 5280
End
Begin VB.TextBox txtMinutes
Appearance = 0 'Flat
Height = 285
Left = 4560
MaxLength = 3
TabIndex = 23
Text = "0"
Top = 1800
Width = 390
End
Begin VB.ListBox lstAlarm
Height = 450
ItemData = "Clock.frx":11FC
Left = 5040
List = "Clock.frx":1206
TabIndex = 22
Top = 2520
Width = 495
End
Begin VB.TextBox txtSeconds
Appearance = 0 'Flat
Height = 285
Left = 4080
MaxLength = 3
TabIndex = 21
Text = "0"
Top = 2880
Width = 390
End
Begin VB.CheckBox chkDigitalToggle
BackColor = &H00FFFFFF&
Caption = "Digital"
Height = 255
Left = 7320
TabIndex = 19
Top = 4920
Value = 1 'Checked
Width = 255
End
Begin ComctlLib.Slider sldColourPick
Height = 1815
Left = 120
TabIndex = 8
Top = 2520
Width = 495
_ExtentX = 873
_ExtentY = 3201
_Version = 327682
Orientation = 1
LargeChange = 1
Max = 4
End
Begin MSComDlg.CommonDialog CommonDialog
Left = 7200
Top = 3480
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton cmdChangeColour
BackColor = &H00FFFFFF&
Caption = "Change Colour"
Height = 375
Left = 5160
Style = 1 'Graphical
TabIndex = 7
Top = 5280
Width = 1935
End
Begin VB.CommandButton cmdPreset
BackColor = &H000000FF&
Caption = "Preset Now"
Height = 615
Left = 4800
MaskColor = &H000000FF&
Style = 1 'Graphical
TabIndex = 6
Top = 360
Width = 975
End
Begin VB.ComboBox lstSeconds
Height = 315
Left = 1440
TabIndex = 5
Text = "Seconds"
Top = 240
Width = 615
End
Begin VB.ComboBox lstMinutes
Height = 315
Left = 480
TabIndex = 4
Text = "Minutes"
Top = 240
Width = 735
End
Begin VB.OptionButton optForwards
BackColor = &H00FFFFFF&
Caption = "Forwards"
Height = 375
Left = 6240
TabIndex = 3
Top = 2640
Value = -1 'True
Width = 1575
End
Begin VB.OptionButton optBackwards
BackColor = &H00FFFFFF&
Caption = "Backwards"
Height = 495
Left = 6240
TabIndex = 2
Top = 1920
Width = 1575
End
Begin VB.CommandButton cmdReset
BackColor = &H00FFC0FF&
Caption = "Reset"
Height = 495
Left = 6240
Style = 1 'Graphical
TabIndex = 1
Top = 480
Width = 1215
End
Begin VB.CommandButton cmdStartStop
BackColor = &H0000C000&
Caption = "Stop"
Height = 375
Left = 6120
Style = 1 'Graphical
TabIndex = 0
Top = 0
Width = 1215
End
Begin VB.Timer Timer1
Interval = 1
Left = 960
Top = 5280
End
Begin VB.Frame frmDigital
BackColor = &H00FFFFFF&
Caption = "Digital Display!"
Height = 1095
Left = 2040
TabIndex = 14
Top = 3960
Width = 4815
Begin VB.Label lblDigitalClockMinutes
BackColor = &H00000000&
BackStyle = 0 'Transparent
Caption = "Minutes"
Height = 255
Left = 360
TabIndex = 18
Top = 480
Width = 495
End
Begin VB.Label lblDigitalClockSeconds
BackColor = &H00000000&
BackStyle = 0 'Transparent
Caption = "Seconds"
Height = 375
Left = 2640
TabIndex = 17
Top = 480
Width = 495
End
Begin VB.Label lblMinutesName
BackColor = &H00000000&
BackStyle = 0 'Transparent
Caption = "minutes"
Height = 255
Left = 960
TabIndex = 16
Top = 480
Width = 1335
End
Begin VB.Label lblSecondsName
BackColor = &H00000000&
BackStyle = 0 'Transparent
Caption = "seconds"
Height = 375
Left = 3240
TabIndex = 15
Top = 480
Width = 1455
End
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "Alarm"
Height = 255
Left = 4200
TabIndex = 27
Top = 2040
Width = 495
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Minutes Seconds"
Height = 255
Left = 4080
TabIndex = 26
Top = 2280
Width = 1455
End
Begin VB.Image imgAlarm
Height = 2505
Left = 1800
Picture = "Clock.frx":1213
Top = 480
Visible = 0 'False
Width = 2280
End
Begin VB.Label lblAlarmSeconds
BackStyle = 0 'Transparent
Caption = "0"
Height = 375
Left = 4560
TabIndex = 25
Top = 2520
Width = 375
End
Begin VB.Label lblAlarmMinutes
BackStyle = 0 'Transparent
Caption = "0"
Height = 375
Left = 4080
TabIndex = 24
Top = 2520
Width = 375
End
Begin VB.Label lblDigitalToggle
BackColor = &H00FFFFFF&
Caption = "Digital Clock On"
Height = 615
Left = 6960
TabIndex = 20
Top = 4560
Width = 855
End
Begin VB.Line secondHand
BorderColor = &H000000FF&
X1 = 3240
X2 = 4440
Y1 = 2160
Y2 = 2205
End
Begin VB.Line minuteHand
BorderWidth = 3
X1 = 2880
X2 = 2880
Y1 = 1800
Y2 = 960
End
Begin VB.Shape Clockface
FillColor = &H00FFFFFF&
FillStyle = 0 'Solid
Height = 2535
Left = 1080
Shape = 3 'Circle
Top = 480
Width = 3615
End
Begin VB.Label lblColourDigits
BackStyle = 0 'Transparent
Caption = "Digital Digits"
Height = 255
Left = 720
TabIndex = 13
Top = 4080
Width = 1815
End
Begin VB.Label lblColourFace
BackStyle = 0 'Transparent
Caption = "Stopwatch Face"
Height = 255
Left = 720
TabIndex = 12
Top = 3720
Width = 1335
End
Begin VB.Label lblColourDigitalBorder
BackStyle = 0 'Transparent
Caption = "Digital Border"
Height = 255
Left = 720
TabIndex = 11
Top = 3360
Width = 1215
End
Begin VB.Label lblColourMinuteHand
BackStyle = 0 'Transparent
Caption = "Minute Hand"
Height = 255
Left = 720
TabIndex = 10
Top = 3000
Width = 975
End
Begin VB.Label lblColourSecondHand
BackStyle = 0 'Transparent
Caption = "Second Hand"
Height = 255
Left = 720
TabIndex = 9
Top = 2640
Width = 1095
End
Begin VB.Menu mnuFile
Caption = "File"
Begin VB.Menu mnuExit
Caption = "Exit"
Shortcut = ^Q
End
End
Begin VB.Menu mnuHelp
Caption = "Help"
Begin VB.Menu mnuAbout
Caption = "About"
Shortcut = ^A
End
End
End
Attribute VB_Name = "frmClock"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'
' Author: Ned Martin #40529927
'
' Creation Date: 27-APR-2004
'
' Version: 1.2 27-APR-2004
'
' Copyright: 2004 Ned Martin, Student s40529927, for COMP2301,
' University of Queensland
'
' Description: Assignment 3 for COMP2301
' Draws a clock face, second and minute hands, and digital
' display, and maintains a count of the minutes and
' seconds elapsed, updating its display to match this.
'
' Tab Stops: Eight spaces
'
' variables
Dim seconds As Integer
Dim minutes As Integer
Dim XCentre As Integer
Dim YCentre As Integer
Dim length As Integer
Dim alarmcounter As Integer
Dim pi As Double
Private Type clockState
countingBackwards As Boolean
alarmOn As Boolean
alarmMinutes As Integer
alarmSeconds As Integer
digitalDisplayOn As Boolean
colourSecondHand As ColorConstants
colourMinuteHand As ColorConstants
colourBorder As ColorConstants
colourFace As ColorConstants
colourDigits As ColorConstants
saved As Boolean
End Type
Dim currentState As clockState
' counting mode, alarm on, alarm minutes, alarm seconds, digital display on,
' colour second, colour minute, colour border, colour face, colour digits
Dim savedState(1 To 5) As clockState
'
' Function: chkClearSaved_Click()
'
' Purpose: Clears saved states
'
' Method: Sets the saved flag for each saved state to false and
' re-initializes the state.
'
' Returns: None
'
Private Sub chkClearSaved_Click()
Dim ii As Integer
If chkClearSaved.Value = 1 Then
' clear saved states
' set the savedState saved flag to false for all saved states
For ii = 1 To 5
savedState(ii).saved = False
Next ii
Call saveState
Call initStuff
' check option one
optLoadSaveOne.Value = True
End If
' uncheck the box
chkClearSaved.Value = 0
End Sub ' chkClearSaved
'
' Function: chkDigitalToggle_Click()
'
' Purpose: Sets the display state of the digital display when its toggle is
' clicked
'
' Method: Sets the digital display flag in the currentState.
'
' Returns: None
'
Private Sub chkDigitalToggle_Click()
If chkDigitalToggle.Value = 1 Then
currentState.digitalDisplayOn = True
Else:
currentState.digitalDisplayOn = False
End If
End Sub ' chkDigitalToggle_Click
'
' Function: cmdChangeColour_Click()
'
' Purpose: Changes colour of elements depending on a slider position.
'
' Method: Gets the current position of the colour change slider, and
' allows user to select new colour from a colour palette and sets
' the appropriate element's colour in the currentState, and then
' sets the appropriate element to that colour.
'
' Returns: None
'
Private Sub cmdChangeColour_Click()
CommonDialog.ShowColor
' get position of colour change slider
Select Case sldColourPick.Value
' second
Case "0": 'secondHand.BorderColor = CommonDialog.Color
currentState.colourSecondHand = CommonDialog.Color
secondHand.BorderColor = currentState.colourSecondHand
' minute
Case "1":
currentState.colourMinuteHand = CommonDialog.Color
minuteHand.BorderColor = currentState.colourMinuteHand
' digital border
Case "2":
currentState.colourBorder = CommonDialog.Color
frmDigital.BackColor = currentState.colourBorder
' face
Case "3":
currentState.colourFace = CommonDialog.Color
Clockface.FillColor = currentState.colourFace
' digits
Case "4":
currentState.colourDigits = CommonDialog.Color
End Select
' set elements to their colours
lblDigitalClockSeconds.ForeColor = currentState.colourDigits
lblDigitalClockMinutes.ForeColor = currentState.colourDigits
lblMinutesName.ForeColor = currentState.colourDigits
lblSecondsName.ForeColor = currentState.colourDigits
End Sub ' cmdChangeColour_Click
'
' Function: initStuff()
'
' Purpose: Initializes elements to the same values as currentState.
'
' Method: Sets colours, text, captions, visiblility of elements to their
' corresponding value in the currentState.
'
' Returns: None
'
Private Sub initStuff()
' set elements to their values in currentState
frmDigital.Visible = currentState.digitalDisplayOn
secondHand.BorderColor = currentState.colourSecondHand
minuteHand.BorderColor = currentState.colourMinuteHand
frmDigital.BackColor = currentState.colourBorder
Clockface.FillColor = currentState.colourFace
lblDigitalClockSeconds.ForeColor = currentState.colourDigits
lblDigitalClockMinutes.ForeColor = currentState.colourDigits
lblMinutesName.ForeColor = currentState.colourDigits
lblSecondsName.ForeColor = currentState.colourDigits
txtMinutes.Text = currentState.alarmMinutes
txtSeconds.Text = currentState.alarmSeconds
lblAlarmMinutes.Caption = currentState.alarmMinutes
lblAlarmSeconds.Caption = currentState.alarmSeconds
' set alarm list to on or off position
If currentState.alarmOn Then
lstAlarm.ListIndex = 0
Else:
lstAlarm.ListIndex = 1
End If
' set the saved slots options to disabled or enabled
If savedState(5).saved Then
optLoadSaveFive.Enabled = True
Else
optLoadSaveFive.Enabled = False
End If
If savedState(4).saved Then
optLoadSaveFour.Enabled = True
optLoadSaveFive.Enabled = True
Else
optLoadSaveFour.Enabled = False
End If
If savedState(3).saved Then
optLoadSaveThree.Enabled = True
optLoadSaveFour.Enabled = True
Else
optLoadSaveThree.Enabled = False
End If
If savedState(2).saved Then
optLoadSaveTwo.Enabled = True
optLoadSaveThree.Enabled = True
Else
optLoadSaveTwo.Enabled = False
End If
If savedState(1).saved Then
optLoadSaveOne.Enabled = True
optLoadSaveTwo.Enabled = True
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub ' initStuff
'
' Function: cmdPreset_Click()
'
' Purpose: Presets the time to a value.
'
' Method: Sets the running count of seconds and minutes to a value from
' two drop down inputs.
'
' Returns: None
'
Private Sub cmdPreset_Click()
seconds = lstSeconds.ListIndex
minutes = lstMinutes.ListIndex
End Sub ' cmdPreset_Click
'
' Function: cmdReset_Click()
'
' Purpose: Resets the time to 0.
'
' Method: Resets the minutes and seconds counters to 0.
'
' Returns: None
'
Private Sub cmdReset_Click()
minutes = 0
seconds = 0
End Sub ' cmdReset_Click
'
' Function: cmdStartStop_Click()
'
' Purpose: Starts or stops the timer.
'
' Method: Toggles the main timer on or off.
'
' Returns: None
'
Private Sub cmdStartStop_Click()
If cmdStartStop.Caption = "Stop" Then
cmdStartStop.Caption = "Start"
Timer1.Enabled = False
Else
Timer1.Enabled = True
cmdStartStop.Caption = "Stop"
End If
End Sub ' cmdStartStop
'
' Function: Form_Load
'
' Purpose: Runs on form load and sets some initial values.
'
' Method: Runs when app is first run, and sets drawing elements to their
' initial values and calls functions to set up other initial
' values. Also specifies some constants.
'
' Returns: None
'
Private Sub Form_Load()
' set lines to centre of analogue circle
XCentre = 3000
YCentre = 2000
pi = 3.14159265358979
length = 1000
secondHand.X1 = XCentre
secondHand.Y1 = YCentre
minuteHand.X1 = XCentre
minuteHand.Y1 = YCentre
Clockface.Left = XCentre - length
Clockface.Top = YCentre - length
Clockface.Width = length * 2
Clockface.Height = length * 2
' display digital clock is initially on
currentState.digitalDisplayOn = True
Call addItems
Call setupCurrentState
' load saved states and initialize
Call loadState
End Sub ' Form_Load
'
' Function: addItems()
'
' Purpose: Adds numbers 0 through 59 to minutes and seconds boxes for
' presetting time.
'
' Method: As above.
'
' Returns: None
'
Private Sub addItems()
Dim ii As Integer
For ii = 0 To 59
lstMinutes.AddItem ii, ii
lstSeconds.AddItem ii, ii
Next ii
' set minutes and seconds drop down boxes to 0
lstMinutes.ListIndex = 0
lstSeconds.ListIndex = 0
lstAlarm.ListIndex = 1
End Sub ' addItems
'
' Function: setupCurrentState()
'
' Purpose: Sets the currentState to its initial values.
'
' Method: Sets each element in currentState to some initial values.
'
' Returns: None
'
Private Sub setupCurrentState()
currentState.alarmMinutes = 0
currentState.alarmOn = False
currentState.alarmSeconds = 0
currentState.colourBorder = vbWhite
currentState.colourDigits = vbBlack
currentState.colourFace = vbWhite
currentState.colourMinuteHand = vbRed
currentState.colourSecondHand = vbBlack
currentState.countingBackwards = False
currentState.digitalDisplayOn = True
End Sub ' setupCurrentState
'
' Function: lstAlarm_Click()
'
' Purpose: Toggles the alarm on and off.
'
' Method: Toggles alarm value in currentState on and off when the alarm
' list is clicked.
'
' Returns: None
'
Private Sub lstAlarm_Click()
If lstAlarm.ListIndex = 1 Then
txtSeconds.Enabled = False
txtMinutes.Enabled = False
currentState.alarmOn = False
Else:
txtSeconds.Enabled = True
txtMinutes.Enabled = True
currentState.alarmOn = True
End If
End Sub ' lstAlarm_Click
'
' Function: cmdSave_Click
'
' Purpose: Saves the current clock state.
'
' Method: Saves currentState to one of five positions in an array.
'
' Returns: None
'
Private Sub cmdSave_Click()
Dim loading As Integer
' get which slot we are saving
If optLoadSaveOne Then
loading = 1
End If
If optLoadSaveTwo Then
loading = 2
End If
If optLoadSaveThree Then
loading = 3
End If
If optLoadSaveFour Then
loading = 4
End If
If optLoadSaveFive Then
loading = 5
End If
' saving
savedState(loading) = currentState
savedState(loading).saved = True
Call initStuff
cmdLoad.Enabled = True
' save the state
Call saveState
End Sub ' cmdSave_Click
'
' Function: cmdLoad_Click()
'
' Purpose: Loads a saved clock state.
'
' Method: Loads a saved state into the currentState.
'
' Returns: None
'
Private Sub cmdLoad_Click()
Dim loading As Integer
' get which slot we are loading
If optLoadSaveOne Then
loading = 1
End If
If optLoadSaveTwo Then
loading = 2
End If
If optLoadSaveThree Then
loading = 3
End If
If optLoadSaveFour Then
loading = 4
End If
If optLoadSaveFive Then
loading = 5
End If
' loading
currentState = savedState(loading)
Call initStuff
End Sub ' cmdLoad_Click
'
' Function: mnuAbout_Click()
'
' Purpose: Shows about window.
'
' Method: Shows a pop-up modal about window.
'
' Returns: None
'
Private Sub mnuAbout_Click()
frmAbout.Show
End Sub ' mnuAbout_Click
'
' Function: mnuExit_Click()
'
' Purpose: Exits program.
'
' Method: Exits the program when the exit menu is selected.
'
' Returns: None
'
Private Sub mnuExit_Click()
End
End Sub ' mnuExit_Click
'
' Function: optBackwards_Click()
'
' Purpose: Makes the counter go backwards.
'
' Method: Sets the countingBackwards flag in currentState to true.
'
' Returns: None
'
Private Sub optBackwards_Click()
currentState.countingBackwards = True
End Sub ' optBackwards_Click
'
' Function: optForwards_Click
'
' Purpose: Makes the counter go forwards.
'
' Method: Sets the countingBackwards flag in currentState to false.
'
' Returns: None
'
Private Sub optForwards_Click()
currentState.countingBackwards = False
End Sub ' optForwards_Click
'
' Function: optLoadSaveOne_Click() through optLoadSaveFive_Click()
'
' Purpose: Checks if a saved state exists for each option and enables the
' load command box if it does.
'
' Method: Checks the saved flag in the savedState array position relating
' to the option position and enables the load command box if saved
' is true for that position, otherwise disables the load command
' box.
'
' Returns: None
'
Private Sub optLoadSaveOne_Click()
If savedState(1).saved Then
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub
Private Sub optLoadSaveTwo_Click()
If savedState(2).saved Then
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub
Private Sub optLoadSaveThree_Click()
If savedState(3).saved Then
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub
Private Sub optLoadSaveFour_Click()
If savedState(4).saved Then
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub
Private Sub optLoadSaveFive_Click()
If savedState(5).saved Then
cmdLoad.Enabled = True
Else
cmdLoad.Enabled = False
End If
End Sub ' optLoadSaveOne_Click through optLoadSaveFive_Click
'
' Function: Timer1_Timer()
'
' Purpose: Runs a one second timer.
'
' Method: Increments the second counter every one second, and the minute
' counter every minute. Calls a function to change the digital
' timer display each second, and checks if an alarm condition has
' been met each second.
'
' Returns: None
'
Private Sub Timer1_Timer()
' count every second
Timer1.Interval = 1000
' count forwards or backwards
Dim incrementer As Integer
If currentState.countingBackwards Then
incrementer = -1
Else
incrementer = 1
End If
seconds = seconds + incrementer
seconds = seconds Mod 60
If seconds = 0 Then
minutes = minutes + incrementer
End If
' change digital time
Call changeTime
' check for an alarm
If seconds = currentState.alarmSeconds And minutes = currentState.alarmMinutes And currentState.alarmOn Then
alarmcounter = 0
TimerAlarmFlash.Enabled = True
TimerAlarmFlash.Interval = 10
End If
If alarmcounter < 3 Then
alarmcounter = alarmcounter + 1
Else
TimerAlarmFlash.Enabled = False
frmDigital.Visible = currentState.digitalDisplayOn
imgAlarm.Visible = False
End If
End Sub ' Timer1_Timer
'
' Function: TimterAlarmFlash_Timer()
'
' Purpose: Flashes the alarm.
'
' Method: Toggles elements every 100 milliseconds to indicate an alarm.
'
' Returns: None
'
Private Sub TimerAlarmFlash_Timer()
TimerAlarmFlash.Interval = 100
frmDigital.Visible = Not frmDigital.Visible
imgAlarm.Visible = Not imgAlarm.Visible
End Sub ' TimerAlarmFlash_Timer
'
' Function: changeTime()
'
' Purpose: Changes the time.
'
' Method: Changes the displayed digital clock values, draws the minute
' and second hands in new positions and increments the progress
' bar.
'
' Returns: None
'
Private Sub changeTime()
Dim xSeconds As Double
Dim ySeconds As Double
Dim xMinutes As Integer
Dim yMinutes As Integer
' digital clock
lblDigitalClockSeconds.Caption = seconds
lblDigitalClockMinutes.Caption = minutes
' set hand endpoints for analogue clock
xSeconds = (length * Cos((pi * (seconds - 15) / 30)))
ySeconds = (length * Sin((pi * (seconds - 15) / 30)))
xMinutes = (length * Cos((pi * (minutes - 15) / 30)))
yMinutes = (length * Sin((pi * (minutes - 15) / 30)))
' analogue clock
secondHand.X2 = xSeconds + XCentre
secondHand.Y2 = ySeconds + YCentre
minuteHand.X2 = xMinutes + XCentre
minuteHand.Y2 = yMinutes + YCentre
' progress bar
ProgressBar.Value = Abs(seconds)
End Sub ' changeTime
'
' Function: txtMinutes_Change() and txtSecondsChange)_
'
' Purpose: Changes alarm minutes and seconds value.
'
' Method: Verifies values entered into the alarm minutes and seconds text
' boxes are a valid integer between 0 and 59 inclusive, and sets
' the alarm values in currentState to match. Also updates the
' label for the alarm.
'
' Returns: None
'
Private Sub txtMinutes_Change()
If Abs(Val(txtMinutes.Text)) > 59 Then
txtMinutes.Text = "0"
End If
lblAlarmMinutes.Caption = Val(txtMinutes.Text)
currentState.alarmMinutes = Val(txtMinutes.Text)
End Sub
Private Sub txtSeconds_Change()
If Abs(Val(txtSeconds.Text)) > 59 Then
txtSeconds.Text = "0"
End If
lblAlarmSeconds.Caption = Val(txtSeconds.Text)
currentState.alarmSeconds = Val(txtSeconds.Text)
End Sub ' txtMinutes_Change and txtSeconds_Change
'
' Function: saveState()
'
' Purpose: Saves clock states.
'
' Method: Opens a binary file and saves the savedState array to it.
'
' Returns: None
'
Private Sub saveState()
Dim ii As Integer
Open "fileClockSave.bin" For Binary As #1
For ii = 1 To 5
With savedState(ii)
Put #1, , .countingBackwards
Put #1, , .alarmOn
Put #1, , .alarmMinutes
Put #1, , .alarmSeconds
Put #1, , .digitalDisplayOn
Put #1, , .colourSecondHand
Put #1, , .colourMinuteHand
Put #1, , .colourBorder
Put #1, , .colourFace
Put #1, , .colourDigits
Put #1, , .saved
End With
Next ii
Close #1
End Sub ' saveState
'
' Function: loadState()
'
' Purpose: Loads saved clock states.
'
' Method: Reads a binary file and loads its contents into the savedState
' array then initalizes the state.
'
' Returns: None
'
Private Sub loadState()
Dim ii As Integer
Open "fileClockSave.bin" For Binary As #1
For ii = 1 To 5
With savedState(ii)
Get #1, , .countingBackwards
Get #1, , .alarmOn
Get #1, , .alarmMinutes
Get #1, , .alarmSeconds
Get #1, , .digitalDisplayOn
Get #1, , .colourSecondHand
Get #1, , .colourMinuteHand
Get #1, , .colourBorder
Get #1, , .colourFace
Get #1, , .colourDigits
Get #1, , .saved
End With
Next ii
Close #1
Call initStuff
End Sub ' loadState
</textarea>
<br />
Code © Copyright 2004 Ned Martin</p>
<p>15-May-2004</p>
</body>
</html>