Click here to Skip to main content
16,021,417 members
Articles / Programming Languages / Visual Basic 6

How to Create a Joke Jukebox in Visual Basic 6.0

Rate me:
Please Sign up or sign in to vote.
3.40/5 (13 votes)
14 May 2010CPOL1 min read 38.7K   612   7   9
An article about how to create a Joke Jukebox in Visual Basic 6.0
Image 1

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.

VB.NET
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.

VB.NET
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.

VB.NET
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.

VB.NET
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)


Written By
Sweden Sweden
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.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey16-Feb-12 19:10
professionalManoj Kumar Choubey16-Feb-12 19:10 
GeneralMy vote of 2 Pin
dev11223318-May-10 10:36
dev11223318-May-10 10:36 
GeneralMy vote of 1 Pin
Alex Casals17-May-10 12:44
professionalAlex Casals17-May-10 12:44 
Generalnice! Pin
eran202216-May-10 9:56
professionaleran202216-May-10 9:56 
GeneralMy vote of 3 Pin
hammerstein0514-May-10 8:22
hammerstein0514-May-10 8:22 
GeneralMy vote of 2 Pin
DaveAuld11-May-10 2:31
professionalDaveAuld11-May-10 2:31 
GeneralRe: My vote of 2 Pin
TobiasP2-Dec-10 3:58
TobiasP2-Dec-10 3:58 
GeneralMy vote of 1 PinPopular
Munim Abdul10-May-10 10:26
Munim Abdul10-May-10 10:26 
GeneralRe: My vote of 1 Pin
Wimmo15-May-10 2:19
Wimmo15-May-10 2:19 
So why did you read the article if it isn't within your interest??Confused | :confused:
Ever thought about it that maybe there are people who has interest in it!

Sorry just another "I vote bla die bla" spam.

I don't have interest in c++ but I don't go spamming all articles about it!

and by the way, this site is called "codeproject" not "onlynewcodeproject"
•Life moves pretty fast. If you don't stop and look around once in a while, you could miss it. — Ferris Bueller

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.