Results 1 to 6 of 6

Thread: VB6 Hangman Code Help

  1. #1

    Thread Starter
    Registered User
    Join Date
    May 2018
    Posts
    7

    VB6 Hangman Code Help

    Hey,
    So I'm coding a Hangman game, and currently it works perfectly. However I need the game to show a hint for its respective word. How do I manage to do this? The words are in a separate text file which VB6 reads.

    I was wondering if on a separate text file I write the hints and somehow make it come with every word, but I really don't know how to code it.

    Any help will be appreciated, thanks.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Hangman Code Help

    Welcome to the forums

    Why not just add the hint to the existing text file, comma delmited: Word, Hint
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Registered User
    Join Date
    May 2018
    Posts
    7

    Re: VB6 Hangman Code Help

    Thanks for the welcome hah )

    I don't quite understand the concept, but let's see.
    So my text file is written like this:
    "Happy"
    "Calm"

    So with what you said, will it look like:
    "Happy, insert hint here"
    "Calm, insert hint here"

    My question is wouldn't the hint also be converted as a word the player has to guess, unless I'm missing something here...?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Hangman Code Help

    You can use VB's Line Input statement to read the line (probably what you're doing now). Then locate the comma in that line (VB's InStr function), and separate the hint from the word using Left$ (word) and Mid$ (hint). You'll be using two variables, one to hold the hangman word and one for the hint

    Edited: Air code follows
    Code:
    ... fNr is the file number of the word list
    ... use whatever method you are for selecting which line in the text file to use
    
        Dim sWord As String, sHint As String
        Dim lPos As Long
    
        Line Input #fnr, sWord
        lPos = InStr(sWord, ",")
        If lPos = 0 Then   ' no hint and done
            ' sHint is blank/null string, sWord contains the hangman word
            ' do whatever else you may need to do
        Else
            sHint = Trim$(Mid$(sWord, lPos + 1))
            sWord = Left$(sWord, lPos - 1)
        End If
    
        ' set up your hangman display
    Last edited by LaVolpe; May 21st, 2018 at 11:00 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Hangman Code Help

    Or, instead of using Line Input, you might be able to just use Input, like
    Input #file, Word, Hint

    If the file contains lines as you've shown, the first word should be read into word, and the second phrase should be read into Hint.

    Just be aware that for this to work you would have to have a hint for every word, and the hint couldn't contain a "," unless you enclosed the hint in quotations marks.

    LaVolpe's suggestion could be more robust in that sense, since you wouldn't need to have a hint for every word and could handle the cases where there wasn't one because you wouldn't find the "," in the line read from the file.
    Last edited by passel; May 21st, 2018 at 10:22 AM.

  6. #6

    Thread Starter
    Registered User
    Join Date
    May 2018
    Posts
    7

    Re: VB6 Hangman Code Help

    Ohh ok!! I got it, thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width