Introduction
Designing apps in Microsoft Visual Basic 6.0 is pretty straight forward. Point this, click that, presto! place it on the form. But seriously, click on the desired component (control) located at the left toolbar of Visual Basic 6.0 , and draw it at an appropriate location on the form.
Components on the form align to rectangular grids, giving your apps a symmetric look.
This simple app demonstrates the ease of creating fun applications in Windows Forms.
Listbox
Fast forwarding a bit, we've created a Windows Form, placed listboxes, labels common dialogs on the form, to have all these controls respond to mouse clicks, we have to put some code into it.
So we double-click on any given control and place some code in that control's event method.
The List1_Click() Event
The List1_Click()
event is called upon when the left button is pressed down while above this listBox
. Once the index has changed, this method is called upon and it represents the user changing from one textfile containing jokes to another.
Private Sub List1_Click()
Label1.Caption = ""
JokeLineCount = 0
List2.ListIndex = JokeLineCount
List2.ListIndex = 0
CurrentJokeFile = List1.ListIndex
Label9.Caption = "TimeDelay : " & TimeDelay
LoadJokeFile
DisplayRandomJoke
End Sub
The GenerateRandomFile() Method
The GenerateRandomFile()
method is called upon to load jokes from a textfile to a string array.
Private Sub GenerateRandomFile()
ii = 0
ResetLines
DoneFile = True
Do
CurrentJokeFile = Int(MaxJokeFiles * Rnd)
For ii = 0 To MaxJokeFiles
If (CurrentJokeFile = DoneFiles(ii)) Then
DoneFile = True
End If
If (CurrentJokeFile <> DoneFiles(ii)) Then
DoneFile = False
End If
Next ii
Loop Until (DoneFile = False)
DoneFileCount = DoneFileCount + 1
DoneFiles(DoneFileCount) = CurrentJokeFile
Label11.Caption = "File : " & CurrentJokeFile & _
" UnOpened: " & MaxJokeFiles - DoneFileCount
If (MaxJokeFiles - DoneFileCount < 1) Then
ResetFiles
ResetLines
End If
LoadJokeFile
End Sub
The List2_Click() Event
The List2_Click()
event is called upon when the left button is pressed down while above this listBox
. Once the index has changed, this method is called upon and it represents the user changing from one line of joke to another.
Private Sub List2_Click()
JokeLineCount = List2.ListIndex
DisplayRandomJoke
Label5.Caption = "Current Line : " & JokeLineCount & " of _
" & JokeFile(CurrentJokeFile).MaxLines
Label10.Caption = "Line : " & JokeLineCount & " Unread: _
" & JokeFile(CurrentJokeFile).MaxLines - DoneLineCount
Label9.Caption = "TimeDelay : " & TimeDelay
End Sub
The DisplayRandomJoke() Method
The DisplayRandomJoke()
method is called upon to display one line of joke from a string array on a label.
Private Sub DisplayRandomJoke()
TimerStart = Timer
Label1.Caption = JokeLine(JokeLineCount).Line
TimeDelay = DefaultTimeDelay + (Len(Label1.Caption) * DelayTreshHold)
Label9.Caption = "TimeDelay : " & TimeDelay
Timer1.Interval = TimeDelay
Timer2.Interval = TimeDelay
End Sub
And that is how easy it is to create fun applications in Windows Forms.
Thanks for reading.