PDA

View Full Version : [VB6] If Statement Calculation Wrong?



Integra
11-16-2013, 06:50 PM
Hi all,

This one is bothering me beyond belief at the moment. I have an if Statement in my current program (Score Sender List Maker) and its working for most games, but then, on the odd game and its a particular game like Escape from Meridell Castle and Meerca Chase II it just goes wrong, wrong wrong!



score = lblPointsToNPS * txtGainNPS

lblTest = score
Score5 = lblScore5
lblScore52 = Score5

time = txtWait
If lblTest > lblScore52 Then
mMod = 40
Else
mMod = txtMod
End If


So in the case of Escape from Meridell the lblTest = 310 and the lblScore52 = 1741, now for whatever reason, the game is setting my Mod to 40 which is basically my trigger for saying hey, you can't earn 1000 nps from this game, even though the score is below the high scores :\ Its like its picking something wrong thats not wrong.

j03
11-16-2013, 07:17 PM
Try this:




score = Val(lblPointsToNPS) * Val(txtGainNPS)

lblTest = score
Score5 = lblScore5
lblScore52 = Score5
time = txtWait

If Val(lblTest) > Val(lblScore52) Then
mMod = 40
Else
mMod = txtMod
End If

Integra
11-17-2013, 02:00 AM
Now its throwing an error with my while loop :\ Says I have a Loop without Do but I have the Do .... and no other Do's anywhere:



Dim strHTML As String, score As String, time As String, Score5 As Integer
Dim mMod As Integer

cmdStart.Enabled = False
cmdAdd.Enabled = False
cmdMLoad.Enabled = False
cmdRemove.Enabled = False
cmdSaveID.Enabled = False
cmdCreateIDList.Enabled = False

cmdStop.Enabled = True

Do While index <> lblCountID
While lblGameName = ""
strHTML = w.GetWrapper("[Only registered and activated users can see links]" & lstID.List(index), "[Only registered and activated users can see links]")

lblGameName = Functions.GSB(strHTML, "og:title" & Chr(34) & " content=" & Chr(34) & "Games Room - ", Chr(34) & "/>")
txtNPS = Functions.GSB(strHTML, "<div id=" & Chr(34) & "gr-ctp-neopoints-img" & Chr(34) & "></div>", "Points =")
lblPointsToNPS = Functions.GSB(txtNPS, "<b>", " ")
lblID = lstID.List(index)

Wend

While lblUser1 = ""

strHTML = w.GetWrapper("[Only registered and activated users can see links]" & lstID.List(index), w.LastPage)
lblUser1 = Functions.GSB(strHTML, "<td align=center>1</td>", "b>")
lblUser1 = Functions.GSB(lblUser1, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore1 = Functions.GSB(strHTML, lblUser1 & "</b></a></td>", "/td>")
lblScore1 = Functions.GSB(lblScore1, "=center>", "<")

lblUser2 = Functions.GSB(strHTML, "<td align=center>2</td>", "b>")
lblUser2 = Functions.GSB(lblUser2, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore2 = Functions.GSB(strHTML, lblUser2 & "</b></a></td>", "/td>")
lblScore2 = Functions.GSB(lblScore2, "=center>", "<")

lblUser3 = Functions.GSB(strHTML, "<td align=center>3</td>", "b>")
lblUser3 = Functions.GSB(lblUser3, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore3 = Functions.GSB(strHTML, lblUser3 & "</b></a></td>", "/td>")
lblScore3 = Functions.GSB(lblScore3, "=center>", "<")

lblUser4 = Functions.GSB(strHTML, "<td align=center>4</td>", "b>")
lblUser4 = Functions.GSB(lblUser4, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore4 = Functions.GSB(strHTML, lblUser4 & "</b></a></td>", "/td>")
lblScore4 = Functions.GSB(lblScore4, "=center>", "<")

lblUser5 = Functions.GSB(strHTML, "<td align=center>5</td>", "b>")
lblUser5 = Functions.GSB(lblUser5, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore5 = Functions.GSB(strHTML, lblUser5 & "</b></a></td>", "/td>")
lblScore5 = Functions.GSB(lblScore5, "=center>", "<")
Wend

If cmdStop.Enabled = False Then
strHTML = MsgBox("Successfully stopped!", vbOKOnly, "Stopped Auto List!")
Exit Do
Else


score = Val(lblPointsToNPS) * Val(txtGainNPS)

lblTest = score
Score5 = lblScore5
lblScore52 = Score5
time = txtWait

If Val(lblTest) > Val(lblScore52) Then
mMod = 40
Else
mMod = txtMod
End If


If optAdd1.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
Else
If optAdd2.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
Else
If optAdd3.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
End If
End If
End If

lblGameName = ""
lblUser1 = ""


index = index + 1
Loop


I hate the fact I can't work out what the hell it is doing and why :\

Zachafer
11-17-2013, 03:24 AM
I properly indented your code and the error popped right out


Dim strHTML As String, score As String, time As String, Score5 As Integer
Dim mMod As Integer

cmdStart.Enabled = False
cmdAdd.Enabled = False
cmdMLoad.Enabled = False
cmdRemove.Enabled = False
cmdSaveID.Enabled = False
cmdCreateIDList.Enabled = False

cmdStop.Enabled = True

Do While index <> lblCountID
While lblGameName = ""
strHTML = w.GetWrapper("[Only registered and activated users can see links]" & lstID.List(index), "[Only registered and activated users can see links]")
lblGameName = Functions.GSB(strHTML, "og:title" & Chr(34) & " content=" & Chr(34) & "Games Room - ", Chr(34) & "/>")
txtNPS = Functions.GSB(strHTML, "<div id=" & Chr(34) & "gr-ctp-neopoints-img" & Chr(34) & "></div>", "Points =")
lblPointsToNPS = Functions.GSB(txtNPS, "<b>", " ")
lblID = lstID.List(index)
Wend

While lblUser1 = ""
strHTML = w.GetWrapper("[Only registered and activated users can see links]" & lstID.List(index), w.LastPage)
lblUser1 = Functions.GSB(strHTML, "<td align=center>1</td>", "b>")
lblUser1 = Functions.GSB(lblUser1, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore1 = Functions.GSB(strHTML, lblUser1 & "</b></a></td>", "/td>")
lblScore1 = Functions.GSB(lblScore1, "=center>", "<")

lblUser2 = Functions.GSB(strHTML, "<td align=center>2</td>", "b>")
lblUser2 = Functions.GSB(lblUser2, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore2 = Functions.GSB(strHTML, lblUser2 & "</b></a></td>", "/td>")
lblScore2 = Functions.GSB(lblScore2, "=center>", "<")

lblUser3 = Functions.GSB(strHTML, "<td align=center>3</td>", "b>")
lblUser3 = Functions.GSB(lblUser3, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore3 = Functions.GSB(strHTML, lblUser3 & "</b></a></td>", "/td>")
lblScore3 = Functions.GSB(lblScore3, "=center>", "<")

lblUser4 = Functions.GSB(strHTML, "<td align=center>4</td>", "b>")
lblUser4 = Functions.GSB(lblUser4, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore4 = Functions.GSB(strHTML, lblUser4 & "</b></a></td>", "/td>")
lblScore4 = Functions.GSB(lblScore4, "=center>", "<")

lblUser5 = Functions.GSB(strHTML, "<td align=center>5</td>", "b>")
lblUser5 = Functions.GSB(lblUser5, "<td align=center><a href='randomfriend.phtml?user=", "'>")
lblScore5 = Functions.GSB(strHTML, lblUser5 & "</b></a></td>", "/td>")
lblScore5 = Functions.GSB(lblScore5, "=center>", "<")
Wend

If cmdStop.Enabled = False Then
strHTML = MsgBox("Successfully stopped!", vbOKOnly, "Stopped Auto List!")
Exit Do
Else
score = Val(lblPointsToNPS) * Val(txtGainNPS)

lblTest = score
Score5 = lblScore5
lblScore52 = Score5
time = txtWait

If Val(lblTest) > Val(lblScore52) Then
mMod = 40
Else
mMod = txtMod
End If

If optAdd1.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
ElseIf optAdd2.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
ElseIf optAdd3.Value = True Then
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
lstList.AddItem ("GameID: " & lblID & " Score: " & score & " Time: " & time & " Mod: " & mMod)
End If
End If

lblGameName = ""
lblUser1 = ""


index = index + 1
Loop

Integra
11-17-2013, 05:31 AM
*sigh* The Uni Lecturer could only get indenting into my head when assignments were needed :\ I suppose I owe you a big thanks then Zachafer !!

However, in light of all this Infamous Joe, I still have the issue of not being able to get it to calculate correctly, eg Gadsgads Game which was working fine earlier is now doing the same thing. I don't understand how the if statement can get it wrong if the damn values say that the statement is false and therefore it cannot do what it is doing.

Its nearly got to be with the formatting of the values stored in the labels doesn't it? The comma's must be throwing something out of whack :\

Edit:
Never mind, declaring Score5 as Long instead of Integer would of helped greatly! And reordering some stuff has fixed most of it, now to just clean it up and remove any unnecessary crap!