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.
http://www.vbforums.com/
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$