Click here to Skip to main content
13,398,199 members (32,797 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 10 May 2010

How to Create a Joke Jukebox in Visual Basic 6.0

, 14 May 2010
Rate this:
Please Sign up or sign in to vote.
An article about how to create a Joke Jukebox in Visual Basic 6.0


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.


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
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
 DoneFile = True

   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
  End If

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
  Label5.Caption = "Current Line   : " & JokeLineCount & "  of  _
		" & JokeFile(CurrentJokeFile).MaxLines
  Label10.Caption = "Line :  " & JokeLineCount & "  Unread: _
		" & JokeFile(CurrentJokeFile).MaxLines - DoneLineCount
  Label9.Caption = "TimeDelay  : " & TimeDelay
 ' UpdateStats
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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey16-Feb-12 20:10
membermanoj kumar choubey16-Feb-12 20:10 
GeneralMy vote of 2 Pin
bflosabre9118-May-10 11:36
memberbflosabre9118-May-10 11:36 
GeneralMy vote of 1 Pin
Alex Casals17-May-10 13:44
memberAlex Casals17-May-10 13:44 
Generalnice! Pin
pita200916-May-10 10:56
memberpita200916-May-10 10:56 
GeneralMy vote of 3 Pin
hammerstein0514-May-10 9:22
memberhammerstein0514-May-10 9:22 
GeneralMy vote of 2 Pin
daveauld11-May-10 3:31
memberdaveauld11-May-10 3:31 
GeneralRe: My vote of 2 Pin
TobiasP2-Dec-10 4:58
memberTobiasP2-Dec-10 4:58 
GeneralMy vote of 1 Pin
Munim Abdul10-May-10 11:26
memberMunim Abdul10-May-10 11:26 
GeneralRe: My vote of 1 Pin
Wimmo15-May-10 3:19
memberWimmo15-May-10 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180216.1 | Last Updated 14 May 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid