Results 1 to 2 of 2

Thread: Makes no sense why its not working...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    24

    Makes no sense why its not working...

    Any any of you see a reason this is not working right? Only one of the skills will not work correctly.

    Character File:
    Code:
    [SKILLS]
    character-skill = 0	99	23507590
    character-skill = 1	99	13500000
    character-skill = 2	99	14807330
    character-skill = 3	99	16385611
    VBCODE:
    Code:
    Dim TempLine1, FName1 As String
    Code:
    Private Sub List1_DblClick()
    FName1 = App.Path & "\characters\" & List1.Text & ".txt"
    Open FName1 For Input As #2
        Do While Not EOF(2)
        Line Input #2, TempLine1
            Call processLine
        Loop
    Close #2
    End Sub
    Code:
    Public Sub processLine()
    If Left(TempLine1, Len("character-skill = 0")) = "character-skill = 0" Then
        skillsInfo$ = Trim(Mid(TempLine1, InStr(1, TempLine1, vbTab) + 1))
        Call processSkills("attack", skillsInfo$)
    End If
    If Left(TempLine1, Len("character-skill = 1")) = "character-skill = 1" Then
        skillsInfo$ = Trim(Mid(TempLine1, InStr(1, TempLine1, vbTab) + 1))
        Call processSkills("defence", skillsInfo$)
    End If
    If Left(TempLine1, Len("character-skill = 2")) = "character-skill = 2" Then
        skillsInfo$ = Trim(Mid(TempLine1, InStr(1, TempLine1, vbTab) + 1))
        Call processSkills("strength", skillsInfo$)
    End If
    If Left(TempLine1, Len("character-skill = 3")) = "character-skill = 3" Then
        skillsInfo$ = Trim(Mid(TempLine1, InStr(1, TempLine1, vbTab) + 1))
        Call processSkills("hitpoints", skillsInfo$)
    End If
    If Left(TempLine1, Len("character-skill = 4")) = "character-skill = 4" Then
        skillsInfo$ = Trim(Mid(TempLine1, InStr(1, TempLine1, vbTab) + 1))
        Call processSkills("range", skillsInfo$)
    End If
    End Sub
    Code:
    Public Sub processSkills(ByVal skillName As String, ByVal incomingInfo As String)
    Dim skillInfo() As String
    Dim skillLv, skillExp As String
    skillInfo = Split(incomingInfo, vbTab)
    skillLv = skillInfo(0)
    skillExp = skillInfo(1)
    
    Select Case (skillName)
    Case "attack"
        attackLv.Text = skillLv
        attackExp.Text = skillExp
    Case "strength"
        strengthLv.Text = skillLv
        strengthExp.Text = skillExp
    Case "defence"
        defenceLv.Text = skillLv
        defenceExp.Text = skillExp
    Case "hitpoints"
        hitpointsLv.Text = skilllv
        hitpointsExp.text = skillExp
    End Select
    End Sub
    This is a screenshot of the output. See the strengthLv and strengthExp are both still "0" when they should not be.

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

    Re: Makes no sense why its not working...

    Looks like it shoud work if the Line Input is returning what is expected. You will need to find out why. Recommend...

    1. Place a Stop or Breakpoint on the code: Call processLine

    2. Run your project, when the code pauses on that line, hover over Templine1 and if it contains "character-skill = 2" then walk thru your code a line at a time and see what is happening. F8 will run a line at a time. If Templine1 does not contain "character-skill = 2", then press F5 and your code will stop again, the next time the code reads a line from your text file.

    3. FYI. Declaring variables like the following does not do what you think
    Code:
    Dim TempLine1, FName1 As String
    Dim skillLv, skillExp As String
    The above makes TempLine1 & skillLv Variants, not strings. The following make them strings:
    Code:
    Dim TempLine1 As String, FName1 As String
    Dim skillLv As String, skillExp As String
    4. Recommend adding OPTION EXPLICIT to the top of your form and declaring all variables you use. For example, you use but do not declare: skillsInfo$
    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}

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