Click here to Skip to main content
Click here to Skip to main content

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

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
 ' 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.

License

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 School and I have a degree in three 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've gotten paid to teach coding. I am roughly 20 years old and i have been a teacher's assistant in programming ,
i have held a lecture in Visual basic 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 about a dozen small simple applications and games.

Comments and Discussions

 
GeneralMy vote of 5 Pinmembermanoj kumar choubey16-Feb-12 19:10 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 14 May 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid