Jump to content
Sign in to follow this  
darkshadow791

Math error...

Recommended Posts

darkshadow791

This is a really simple question with a possibly very simple question that I probably should know but don't, so I'm posting here.

The following code gives me very weird numbers and values for $percent... "1.#INF"

Local $temp = _FileCountLines("Definitions.txt")
    Local $percent = 0
    Local $perc = GUICtrlCreateProgress(0,(450/2)-(40/2),500,40)
    Local $lab = GUICtrlCreateLabel("Updating definitions...",(500/2) - 100,100,200,20)
    GUICtrlSetData($perc,$percent)
    For $count = 1 To $temp Step 1
        ;MsgBox(0,"",($count / $temp))
        $percent = (($count / $temp) * 100.0)
        GUICtrlSetData($perc,$percent)
        Local $temp = StringSplit(FileReadLine("Definitions.txt",$count),"|")
        $List[$count][1] = $temp[1]
        $List[$count][2] = $temp[2]
        ;Sleep(100)
    Next
    GUICtrlDelete($perc)
    GUICtrlDelete($lab)

Made with a simple textfile called definitions.txt that has lines of random txt with a "|" between them. The error occurs when $percent is being redefined in the for loop... And it makes my progressbar do weird things....

Share this post


Link to post
Share on other sites
therks

MsgBox(0, 'Divide by zero!', 1 / 0) = 1.#INF

Somewhere you're dividing by zero. I would be sure to check that $temp variable before throwing it into an equation.

Er whoa, wait, you're redefining temp within the for loop, that's why.

Watch what happens when I do this:

$toNum = 5
For $count = 1 to $toNum
  ConsoleWrite($count & ', ' & $toNum & @CRLF)
  $toNum = 0
NextoÝ÷ Øë­¦ëlr^×´ßN4çOÜ¡×v+@Øî²Ø§q«ÊÙ÷öÚÞjX³y©Ú®¶²zö¥¹«^²Ú3zº0éî±çb©¶¦jØjW±¦·¬²*'殶­sdFÒb33c¶W³Ð¤×6t&÷Âb33²b33²Ã²b33c¶W²Ò

*Edit2: Just had to mention, the Step 1 in your For loop is redundant. It steps by 1 by default. :shocked:

Edited by Saunders

Share this post


Link to post
Share on other sites
Gabburd

The problem stemmed from the reuse of your variable $temp

Try this:

#include <file.au3>
Local $temp = _FileCountLines("Definitions.txt")
Local $percent = 0
Local $perc = GUICtrlCreateProgress(0,(450/2)-(40/2),500,40)
Local $lab = GUICtrlCreateLabel("Updating definitions...",(500/2) - 100,100,200,20)
GUICtrlSetData($perc,$percent)
For $count = 1 To $temp Step 1
    Local $temp2 = StringSplit(FileReadLine("Definitions.txt",$count),"|")
    MsgBox(0,"",($count / $temp))
    $percent = (($count / $temp) * 100.0)
    GUICtrlSetData($perc,$percent)
    Local $List[$count+1][3]
    $List[$count][1] = $temp2[1]
    $List[$count][2] = $temp2[2]
    ;Sleep(100)
Next
GUICtrlDelete($perc)
GUICtrlDelete($lab)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×