Jump to content

FileWriteLine to Csv broken


Recommended Posts

Func Who()
$oIE = _IECreate($line, 0, 0,0)
Sleep(1000)
$Who = _IEGetObjById($oIE, "who_inside_buybox")
$text = $Price.innertext
GUICtrlSetData($BoxID,$text & @CRLF, "1")

#Region Used to create a test csv file
$hFile = FileOpen("Test.csv", $FO_OVERWRITE)
For $I = 01 To 1
    If Mod($I, 10) Then 
        FileWriteLine($hFile, "who,is,there,now")
          FileWriteLine($hFile, $text)
    Else
Sleep(100)
    EndIf
Next
FileClose($hFile)
#EndRegion
EndFunc

Thats part of my code, I cant get to work it right.

FileWriteLine will only enter last info into csv not all the info from IEGetObjById($oIE, "who_inside_buybox")

FileWriteLine($hFile, "who,is,there,now") must be columns a b c d and cannot be modifed. and i get about 1000 results for column a but it writes only last one, it wont go to next line

So im asking some one to please correct this code

Link to comment
Share on other sites

3 hours ago, Danp2 said:

As I understand it, FileWriteLine is designed to write a single line to the file.

I did a quick test, and FileWriteLine has no difficulty writing multiple lines (e.g. "asdf" & @CRLF & "asdf" is one line).  What sets is apart from FileWrite is that it adds a line break at the end.

Dercardano, I'm just a beginner script writer myself, but can you explain two things for me?

For $I = 01 To 1

So, this means that the For-Next loop will cycle only once, right?

This means that the script will write "a,b,c,d" & @CRLF, followed by the content of $text & @CRLF.  And if $text is just one line long, it will write just that one line.

I've noticed that $text is a map ($text = $Price.innertext) but since the For-Next loop will cycle only once, surely only one element of that map will be dealt with (and written to the text file). Right?

FileWriteLine($hFile, "who,is,there,now")
  FileWriteLine($hFile, $text)

Out of curiosity, why did you indent the second FileWriteLine?  I mean, you're free to do that, of course, but usually this indicates an expectation.

Edited by leuce
Link to comment
Share on other sites

2 hours ago, leuce said:

So, this means that the For-Next loop will cycle only once, right?

This means that the script will write "a,b,c,d" & @CRLF, followed by the content of $text & @CRLF.  And if $text is just one line long, it will write just that one line.

I've noticed that $text is a map ($text = $Price.innertext) but since the For-Next loop will cycle only once, surely only one element of that map will be dealt with (and written to the text file). Right?

Certainly there is some weirdness in the for loop.

OTOH, I’d imagine that whatever is shown by the 

GUICtrlSetData($BoxID,$text & @CRLF, "1")

statement is what is expected in the file. 

Code hard, but don’t hard code...

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...