Jump to content

Console to .txt?


Recommended Posts

Hello,

I'm using the snippet of following code to loop thru an array and print the results to a .txt file and also write into the console for test purposes. For some reason, the output to the .txt file stops before reaching the end of the array contents, however the output in the console is written complete and correctly. I'm at a loss to explain why? Is there some memory limitation in Notepad.exe? There's only about 32 lines of text to be output, so I can't believe that is the problem. Is there a command to transfer the contents of the consolewrite into a .txt file?? Thanks in advance.

For $i = 0 To 20

$source = FileOpen("C:\MyFile", 9)

$CHECK = StringIsFloat($aTableData[4][$i])

if $CHECK == 1 Then

if $i == 20 Then FileWriteLine($source, $aTableData[4][$i] & ",")

if $i < 20 Then FileWrite($source, $aTableData[4][$i] & ",")

ConsoleWrite($aTableData[4][$i])

ConsoleWrite(" ")

EndIf ;ensure no blank spaces in data write...(all values should be "floating" decimal values...)

Next

Link to comment
Share on other sites

Hello,

I have a follow-up question. Can I get an explanation as to why "checking the value of $i for the filewriteline() procedures" causes a problem in my code?? I have another script (below) with similar problems as the last...the last .txt that should be output is not written and the "2nd to last" file is not output correctly -- however as before the consolewrite prints complete and correctly. If in fact the error lies within the "check for the value of $i" (more or less than "10") then what is the cause of this? The code does not seem to have any errors...

Dim $INPUTS[20]

Dim $i

$source = FileOpen("C:\MyTEST.txt", 0)

$i = 1

While 1

if $i > 30 Then ExitLoop

$chars = FileReadLine($source)

$HISTORIES = StringSplit($chars, ",")

For $k = 0 To 19

if StringIsFloat($HISTORIES[$k]) Then

if $source then

$INPUTS[$k] = $HISTORIES[$k]

if $i == 30 Then ConsoleWrite($INPUTS[$k] & " ")

if $i < 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "00" & $i & ".inp", 10)

if $i >= 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "0" & $i & ".inp", 10)

FileWriteLine($source2, " " & "1" & " " & $INPUTS[1] & " " & "1.00");

FileWriteLine($source2, " " & "2" & " " & $INPUTS[2] & " " & "2.00");

FileWriteLine($source2, " " & "3" & " " & $INPUTS[3] & " " & "3.00");

...

FileWriteLine($source2, " " & "17" & " " & $INPUTS[17] & " " & "17.00");

Endif

EndIf

Next

FileClose($source2)

$i += 1

WEnd

FileClose($source)

Link to comment
Share on other sites

Hello,

I don't understand why you say that but could you explain your earlier statement about the problem lying in "checking the value of $i for the filewriteline() procedures"...I need to understand why there's some problem there when there doesn't appear to be anything wrong with the code...I thank you in advance.

Link to comment
Share on other sites

Thanks for the post. Your comment led me to think that my comparisons for the value of $i were causing some error on the output files. Since my "second code" example also had a similar comparison I thought that was messing up the .txt output somehow. That kinda puts me back to square one on my second code example, if the code is correct as I had thought then I'm at a loss to find a solution to the screwed up .txt files at the end of the While loop...

Link to comment
Share on other sites

I've done some more testing by adding some lines to the end of the original "read" file. It seems no matter how many lines I add (which in turn should add subsequent files to the output .txt files) only 29 files are being created in the output folder...I cannot find the error in the code that sets this limitation, it's obviously what is causing the problem but I don't see it, perhaps another set of eyes??

Dim $INPUTS[20]
Dim $i
$source = FileOpen("C:\MyTEST.txt", 0)

$i = 1 
While 1
if $i > 35 Then ExitLoop

$chars = FileReadLine($source)
$HISTORIES = StringSplit($chars, ",")

  For $k = 0 To 19
  if StringIsFloat($HISTORIES[$k]) Then 
  if $source then
  $INPUTS[$k] = $HISTORIES[$k] 
  if $i == 34 Then ConsoleWrite($INPUTS[$k] & " ")
  if $i < 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "00" & $i & ".inp", 10)
  if $i >= 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "0" & $i & ".inp", 10)
  FileWriteLine($source2, " " & "1" & " " & $INPUTS[1] & " " & "1.00");
  FileWriteLine($source2, " " & "2" & " " & $INPUTS[2] & " " & "2.00");
  FileWriteLine($source2, " " & "3" & " " & $INPUTS[3] & " " & "3.00");
  ...
  FileWriteLine($source2, " " & "17" & " " & $INPUTS[17] & " " & "17.00"); 

Endif
EndIf 
Next

FileClose($source2)
$i += 1
WEnd

FileClose($source)
Link to comment
Share on other sites

Maybe show your MyTEST.txt so it can be examined. Is it possible that you're not getting the files because of the StringIsFloat comparison at the top of the text writing section?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Howdy,

Thanks for the reply. No actually for testing purposes I just copied a few lines from the file and pasted them in at the end so as to create a larger test file, so the StringIsFloat can't be the problem, all the lines contain decimal places.

Where in NH you at? I used to live there for many years, but no more cold and snow for me... :)

Here's "MyTEST" file data used to extract the values from. There's now about 35 lines but as stated before my output consistently only has 29 files ("Lookup001" to "Lookup029") with the last ("Lookup29") outputting incorrect data. I've done some more testing by removing the "While" loop and simply inserting various line numbers in the "FileReadLine" function (like "FileReadLine($source, 33)" for example), works just fine that way...man I wish AutoIT had a "goto" statement...

16.23,16.85,16.68,16.55,16.44,16.54,17.28,17.52,17.59,17.40,17.59,17.37,17.12,17.16,17.40,17.32,17.14,17.21,17.21,
43.15,43.57,43.53,43.56,43.44,44.29,45.53,45.78,46.86,46.19,46.52,46.75,46.57,45.72,45.88,44.82,43.82,43.53,43.72,43.60,
70.12,72.01,72.30,70.76,70.23,70.93,73.04,72.24,72.48,71.40,72.26,72.14,72.66,72.63,72.71,71.93,71.38,70.98,71.00,
13.93,14.29,14.20,13.97,14.17,14.18,14.75,14.81,14.84,14.77,14.89,14.77,14.49,14.64,14.61,14.67,14.29,14.43,14.24,14.31,
99.86,102.93,102.00,100.57,100.02,102.01,105.86,103.36,103.55,103.00,103.26,103.54,100.60,99.79,100.61,100.47,99.59,98.93,99.09,98.01,
18.56,18.56,18.64,18.36,18.40,18.59,18.85,18.68,18.58,18.67,18.81,18.70,18.92,22.04,21.99,22.03,22.05,21.91,21.62,21.47,
102.90,103.75,102.10,102.03,102.27,100.32,98.72,97.17,96.66,96.34,96.95,96.45,96.70,96.24,97.74,97.66,97.11,97.31,96.48,
53.22,54.87,54.07,53.04,53.71,54.38,55.98,55.59,54.67,54.11,54.52,54.58,54.33,53.83,53.71,53.33,52.53,51.93,51.85,
42.99,43.74,42.95,42.42,42.13,42.65,43.56,43.70,43.70,43.09,43.24,43.41,43.31,43.36,41.18,40.94,40.71,40.50,40.49,39.88,
20.25,20.92,20.82,20.58,20.37,20.82,21.44,21.52,21.44,21.46,21.50,21.33,21.27,21.31,21.28,20.87,20.56,20.75,20.71,
36.76,37.47,37.08,37.14,37.30,38.09,38.48,38.18,37.86,37.69,37.58,37.48,37.31,37.17,37.16,36.60,36.80,36.70,36.56,36.99,
42.91,43.63,42.68,42.17,43.59,48.23,48.67,48.62,48.99,47.99,48.31,48.64,48.54,48.94,48.14,48.14,47.43,47.32,46.89,46.52,
159.97,161.88,162.28,160.77,160.18,161.95,164.84,164.24,163.40,162.84,163.22,163.85,164.09,164.65,166.05,164.82,164.00,163.53,163.30,
21.39,21.47,21.86,21.29,21.15,21.81,22.14,21.97,21.75,21.45,21.57,21.76,21.80,21.46,21.64,21.69,21.68,21.57,21.56,
60.70,61.44,59.64,60.25,60.39,60.65,61.11,60.79,60.52,60.62,60.70,60.70,60.93,60.88,60.94,60.87,60.84,60.80,60.62,
45.60,46.69,46.68,45.91,45.96,46.01,48.00,47.82,47.94,46.82,46.54,46.57,45.53,45.11,45.74,45.50,44.59,45.46,45.45,45.93,
31.55,31.84,31.71,31.78,31.68,31.47,30.91,30.84,30.80,30.67,30.49,30.66,31.11,31.24,31.13,30.87,31.19,30.74,30.56,30.67,
64.91,63.92,64.31,63.88,63.91,63.76,64.55,64.55,63.40,63.19,63.14,63.57,63.54,63.15,62.87,62.52,62.56,62.57,62.86,63.05,
74.89,75.68,74.44,75.21,75.19,75.70,76.13,75.98,76.02,76.15,76.24,76.14,75.76,75.93,75.36,73.45,74.05,73.83,73.64,
90.46,92.23,90.25,90.03,90.26,92.00,92.96,92.73,92.33,92.00,91.90,91.80,90.46,90.78,89.47,88.79,88.29,87.95,87.75,
32.46,32.57,32.19,32.03,32.09,32.34,32.85,33.10,32.96,32.79,32.82,33.07,33.04,33.09,33.27,33.00,32.89,32.90,33.82,34.00,
19.14,19.24,18.86,18.90,18.76,18.89,19.19,19.37,19.28,19.05,19.05,18.83,19.03,19.05,19.16,19.04,19.30,19.17,18.96,
62.74,63.05,62.84,63.05,64.15,64.07,64.30,64.00,63.76,63.92,64.54,64.73,64.58,64.39,64.64,64.55,63.61,62.90,62.79,62.92,
28.08,28.38,28.13,27.92,28.03,28.20,28.57,28.50,28.30,28.24,28.46,28.47,28.24,27.97,27.91,27.96,27.97,27.99,27.67,27.87,
59.22,59.93,59.60,59.33,60.42,60.53,60.92,59.78,59.46,59.35,58.84,58.99,58.46,58.81,57.88,57.18,57.41,57.25,56.71,56.81,
82.08,83.54,83.37,82.72,82.79,83.56,85.01,84.54,85.06,84.93,85.21,85.20,84.75,83.98,83.88,83.66,82.52,82.22,82.16,
36.02,36.92,35.97,35.58,35.81,36.00,36.62,36.37,36.17,36.46,35.90,36.39,36.42,36.68,36.34,36.02,36.31,36.38,36.16,36.27,
52.07,51.98,51.75,52.09,53.03,53.67,55.38,54.75,54.55,54.95,54.80,55.69,55.59,56.73,56.38,56.07,56.03,55.92,55.86,56.33,
84.80,85.53,85.34,85.97,87.07,85.44,84.50,83.88,83.69,82.97,84.91,82.82,83.20,82.55,82.98,83.93,83.28,83.44,83.41,
49.39,50.00,49.61,48.99,48.85,49.11,49.94,49.84,49.50,49.55,49.76,49.73,49.58,49.18,49.52,49.49,49.34,49.08,48.91,48.91,
21.39,21.47,21.86,21.29,21.15,21.81,22.14,21.97,21.75,21.45,21.57,21.76,21.80,21.46,21.64,21.69,21.68,21.57,21.56,
60.70,61.44,59.64,60.25,60.39,60.65,61.11,60.79,60.52,60.62,60.70,60.70,60.93,60.88,60.94,60.87,60.84,60.80,60.62,
45.60,46.69,46.68,45.91,45.96,46.01,48.00,47.82,47.94,46.82,46.54,46.57,45.53,45.11,45.74,45.50,44.59,45.46,45.45,45.93,
31.55,31.84,31.71,31.78,31.68,31.47,30.91,30.84,30.80,30.67,30.49,30.66,31.11,31.24,31.13,30.87,31.19,30.74,30.56,30.67,
64.91,63.92,64.31,63.88,63.91,63.76,64.55,64.55,63.40,63.19,63.14,63.57,63.54,63.15,62.87,62.52,62.56,62.57,62.86,63.05,
Link to comment
Share on other sites

~

Dude, that is going on with your posts?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I just tested the script with the text file you posted and I got all 35 files to the C:\MyFiles\Backs folder.

BTW, I'm in southern NH and you're missing one of the worst winters I've had to put up with in years. Can't convince the wife to move somewhere warmer. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hey BrewMan you got all 35 files with the script exactly as posted, correct? I ask because I can also get all 35 files if I take out the FOR...NEXT loop, it then seems to run perfectly. When I include the FOR...NEXT in the script that is when it bombs out and only outputs 29 files. I've tried using other similar commands (DO...UNTIL, and another nested WHILE loop) with the same bad output results...

Anybody have an idea why adding a loop of some kind would cause the output corruption I'm seeing when the script runs perfectly without a loop?? Right now I'd do just about anything for a goto statement which would possibly solve this...but alas that's not an option with AutoIT.

I've tried changing the script to output to different folders, AND even tested it on another computer...all with the same results... :)

Link to comment
Share on other sites

This is what I used, all I did was add in the missing lines to get all of the text on each line into the text files. I get all 35 files when I run this script.

Dim $INPUTS[20]
Dim $i
$source = FileOpen("C:\MyTEST.txt", 0)
$i = 1
While 1
    If $i > 35 Then ExitLoop
    $chars = FileReadLine($source)
    $HISTORIES = StringSplit($chars, ",")
    For $k = 0 To 19
        If StringIsFloat($HISTORIES[$k]) Then
            If $source Then
                $INPUTS[$k] = $HISTORIES[$k]
                If $i = 34 Then ConsoleWrite($INPUTS[$k] & " ")
                If $i < 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "00" & $i & ".inp", 10)
                If $i >= 10 Then $source2 = FileOpen("C:\MyFiles\BACKS\Lookup" & "0" & $i & ".inp", 10)
                FileWriteLine($source2, " " & "1" & " " & $INPUTS[1] & " " & "1.00");
                FileWriteLine($source2, " " & "2" & " " & $INPUTS[2] & " " & "2.00");
                FileWriteLine($source2, " " & "3" & " " & $INPUTS[3] & " " & "3.00");
                FileWriteLine($source2, " " & "4" & " " & $INPUTS[4] & " " & "4.00");
                FileWriteLine($source2, " " & "5" & " " & $INPUTS[5] & " " & "5.00");
                FileWriteLine($source2, " " & "6" & " " & $INPUTS[6] & " " & "6.00");
                FileWriteLine($source2, " " & "7" & " " & $INPUTS[7] & " " & "7.00");
                FileWriteLine($source2, " " & "8" & " " & $INPUTS[8] & " " & "8.00");
                FileWriteLine($source2, " " & "9" & " " & $INPUTS[9] & " " & "9.00");
                FileWriteLine($source2, " " & "10" & " " & $INPUTS[10] & " " & "10.00");
                FileWriteLine($source2, " " & "11" & " " & $INPUTS[11] & " " & "11.00");
                FileWriteLine($source2, " " & "12" & " " & $INPUTS[12] & " " & "12.00");
                FileWriteLine($source2, " " & "13" & " " & $INPUTS[13] & " " & "13.00");
                FileWriteLine($source2, " " & "14" & " " & $INPUTS[14] & " " & "14.00");
                FileWriteLine($source2, " " & "15" & " " & $INPUTS[15] & " " & "15.00");
                FileWriteLine($source2, " " & "16" & " " & $INPUTS[16] & " " & "16.00");
                FileWriteLine($source2, " " & "17" & " " & $INPUTS[17] & " " & "17.00");
                FileWriteLine($source2, " " & "18" & " " & $INPUTS[18] & " " & "18.00");
                FileWriteLine($source2, " " & "19" & " " & $INPUTS[19]& " " & "19.00");
            EndIf
        EndIf
    Next
    FileClose($source2)
    $i += 1
WEnd
FileClose($source)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks. I'll have to drop back 10 and punt, I can't even get that code to run without errors even though I'm running exactly the same script using exactly the same input .txt file (I simply copy/pasted the code into a new AutoIT script...). I keep getting these damn subscript errors:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If StringIsFloat($HISTORIES[$k]) Then

If StringIsFloat(^ ERROR

>Exit code: 1 Time: 0.252

Is it possible my system is somehow corrupted that may be the reason I cannot run these scripts???

Link to comment
Share on other sites

Make sure the path to the MyTEST.txt file is correct, I only got that error before I fixed that line because I had saved the file to a different location on my computer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks, I changed the directory and did a download/install of the current version of AutoIT since I was using an older version. Seems to be working now, thanks again for your help and patience. Now you just need to get out of the cold and snow...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...