AutoHotkey Community

It is currently May 26th, 2012, 8:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: August 23rd, 2009, 1:33 am 
Offline

Joined: August 12th, 2009, 6:07 pm
Posts: 26
Simple problem...for the life of me I cannot debug my script and fix it, but basically I have a script that reads from a large txt file, performs a lot of manipulations to it, and then ultimately spits out the formatted reults in a new text file.

I have my program set up to operate on a given text file based on user input. The problem I am encountering is that as I switch between files being worked on a remnant of the previous file is appended to the new file loaded.

If I close my script and reopen it the script will load the new file correctly, so somewhere in my script something is not resetting between executing the code. Is there any way to reset my vairables without reloading the entire GUI and there by losing the user input?

I am new so the code represents my lack of understanding from the start, but, essentially, by time it gets to fileappend...test.txt, the temporary file appends a remnant from the previous time it was run (assuming this was the second time the script was excuted).

Thanks!


Code:
ButtonViewPicks:
filedelete, %A_ProgramFiles%\tracks\Test.txt
FileDelete,%programfiles%\tracks\%trk%.txt
FileDelete, %A_ProgramFiles%\tracks\picks.txt
FileDelete, %A_ProgramFiles%\tracks\raceone.txt
FileDelete, %A_ProgramFiles%\tracks\racesort.txt
filedelete, %A_ProgramFiles%\tracks\race%race#%.txt
FileDelete, %A_ProgramFiles%\tracks\%trk%.txt

Gui,submit, NoHide
FormatTime,date,%MyCalendar%,MMdd

IfNotExist, %A_ProgramFiles%\tracks\%trk%%date%.pcs
{
MsgBox, 16, File Not Found, The selected PCS file does not exist
Return
}


FileRead, contents, C:\Program files\tracks\%trk%%date%.pcs
StringSplit,TestVar,contents,`,

loop 150
{

        if (A_Index=1)
                {
                Track=1
                DateN = 2
                Race = 3
                Name = 45
                Speed=846
                Lengths=746
                position=616
                }
                else
                {
                 
                Track+=1434
                DateN+= 1434
                Race+= 1434
                Name+= 1434
                Speed+=1425
                Lengths+=1425
                position+=1425
                }

data:=TestVar%Track%
data2:=TestVar%DateN%
data3:=TestVar%Race%
data4:=TestVar%Name%
data5:=TestVar%Speed%
data6:=TestVar%Lengths%
data7:=TestVar%position%


       
                Fileappend, %data%|, %A_ProgramFiles%\tracks\Test.txt
                Fileappend, R%data3%|, %A_ProgramFiles%\tracks\Test.txt
                Fileappend, %data4%|`n, %A_ProgramFiles%\tracks\Test.txt


        Loop 10         ;must be set at 10
       {
                if (A_Index=1)
                        {
                        Speed= %speed%
                        Lengths= %lengths%
                        position=%position%
                        }
                else
                        {
                        Speed+=1
                        Lengths+=1
                        position+=1
                        }

data5:=TestVar%Speed%
data6:=TestVar%Lengths%
data7:=TestVar%position%

    if data6 < 3.1
        Fileappend, %data5%|, %A_ProgramFiles%\tracks\Test.txt
    Else if data7 = 1
        Fileappend, %data5%|, %A_ProgramFiles%\tracks\Test.txt
   
        }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 1:48 am 
Offline

Joined: August 12th, 2009, 6:07 pm
Posts: 26
I should add I tried putting

MyVar:=
MyVar2:=
...
at the end of the script, to know avail...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 9:26 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
At the end you mean outside the loop, try moving it to before the last } so the vars are cleared in each iteration of the loop

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 8:09 pm 
Offline

Joined: August 12th, 2009, 6:07 pm
Posts: 26
Thanks, I need the variables to hold there data until the loop is finished so I can't. It works fine during the initial execution, its just when I run it a second time on a new file that it carries over data from the previous execution.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 8:39 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Then at the TOP of the script of just before/after the fileread?

Edit: or you can Reload the script (see doc page) it will clear all vars

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 9:05 pm 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 355
Location: Germany
Do you want to tell us, that every "%trk%%date%.pcs" file has 215,100 or more fields, separated by comma? So many must be there as you loop constantly with 150 and use everey 1434th field. If there are less , the residual fields contain the contents of the previous record(s). To avoid this problem use
Code:
loop % TestVar0

Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 9:59 pm 
Offline

Joined: August 12th, 2009, 6:07 pm
Posts: 26
Thanks Hubert,

The file will usually only have about 157k comma delimated fields, I put 150 just to make sure it doesn't stop short of looping through everything...I understand your point...

However, I am not sure if I am utilzing what you suggested right.

I replaced

Code:
Loop 150


with

Code:
Loop % TestVar0


And it just infinitely loops. What am I missing? Thanks for the help.

Just to clarify what your saying...if I looped a file that had 180k fields, it will store data in TestVar180,000 (or whatever). Now, when I loop through a new file that has 150k fields it keeps looping beyond the end of the file, and since there is nothing past 150k, it just spits out the data from from TestVar180k that was never cleared or rewritten. If I understand you right, you just caused a :idea:.

...HugoV, yea, I tried clearing them at the beginning as well. I am using the reload now as a temporary work around, but it is a pain because it resets my calendar/user input as well. Regardless, it is pissing me off because I want to understand why its doing what it's doint :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 10:11 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I'm assuming it's the "data" variables that you've set into a pseudo array that are causing the problem? If it is you could just clear the variables with a loop once the label is called:

Code:
ButtonViewPicks:
Loop, 7 {
  if A_Index = 1
    VarSetCapacity(data,0)
  else
    VarSetCapacity(data%A_Index%,0)
}
; MsgBox as error check to verify the variables are now cleared of data
MsgBox % "data = " data "`n" "data2 = " data2 "`n" "data3 = " data3 "`n" "data4 = " data4 "`n" "data5 = " data5 "`n" "data6 = " data6 "`n" "data7 = " data7 "`n"
<< ...script continues... >>

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 10:34 pm 
Offline

Joined: August 12th, 2009, 6:07 pm
Posts: 26
Ok, I got it...

I added this to the beginning of the script to clear the variables. Thanks for all the help...

Code:
Loop 150 ; Clear all TestVar variables
{
if (A_Index=1)
                {
                Track=1
                DateN = 2
                Race = 3
                Name = 45
                Speed=846
                Lengths=746
                position=616
                }
                else
                {
                 
                Track+=1434
                DateN+= 1434
                Race+= 1434
                Name+= 1434
                Speed+=1425
                Lengths+=1425
                position+=1425
                }

TestVar%Track%:=
TestVar%DateN%:=
TestVar%Race%:=
TestVar%Name%:=
TestVar%Speed%:=
TestVar%Lengths%:=
TestVar%position%:=
}


FileRead, contents, C:\Program files\tracks\%trk%%date%.pcs
StringSplit,TestVar,contents,`,

Loop 150
{

        if (A_Index=1)
                {
                Track=1
                DateN = 2
                Race = 3
                Name = 45
                Speed=846
                Lengths=746
                position=616
                }
                else
                {
                 
                Track+=1434
                DateN+= 1434
                Race+= 1434
                Name+= 1434
                Speed+=1425
                Lengths+=1425
                position+=1425
                }

data:=TestVar%Track%
data2:=TestVar%DateN%
data3:=TestVar%Race%
data4:=TestVar%Name%
data5:=TestVar%Speed%
data6:=TestVar%Lengths%
data7:=TestVar%position%


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, joetazz, Leef_me, Mickers, tidbit, tomoe_uehara and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group