Sign in to follow this  
Followers 0
Diana (Cda)

After FileWrite, what is it called to put cursor at end of, say, 1st line?

5 posts in this topic

I've been combing the help file and have done numerous searches since Friday but I just can't find, nor remember, what it's called in AutoIt to after opening a file in FileWrite, to have the cursor go to the end of, say, the first line. I'm sure there's something in AutoIt to do that but it was so long ago I saw it and I can't remember what it's called. Can anyone tell me what this is called? Thx.

Share this post


Link to post
Share on other sites



I believe FileSetPos() is what you're looking for?

Example from the help file:

#include <Constants.au3>

Local Const $sFile = "test.txt"
Local $hFile = FileOpen($sFile, 2)

; Check if file opened for writing OK
If $hFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Write something to the file.
FileWriteLine($hFile, "Line1")
FileWriteLine($hFile, "Line2")
FileWriteLine($hFile, "Line3")

; Flush the file to disk.
FileFlush($hFile)

; Check file position and try to read contents for current position.
MsgBox(0, "", "Position: " & FileGetPos($hFile) & @CRLF & "Data: " & @CRLF & FileRead($hFile))

; Now, adjust the position to the beginning.
Local $n = FileSetPos($hFile, 0, $FILE_BEGIN)

; Check file position and try to read contents for current position.
MsgBox(0, "", "Position: " & FileGetPos($hFile) & @CRLF & "Data: " & @CRLF & FileRead($hFile))

; Close the handle.
FileClose($hFile)

; Clean up the temporary file.
FileDelete($sFile)

[center][/center]

Share this post


Link to post
Share on other sites

I believe FileSetPos() is what you're looking for?

...

Hmmm, no, don't recognize that and looking at the code, seems like a custom function, no (??). I entered it into the 3 AutoIt help files I have and it doesn't come up. Now I don't update AutoIt often, no more than once a year or so, so it might be something in a new help file. But I thought I remembered something that was a whole lot easier to use. I'm guessing I also just might be getting it confused with something else, though I could have sworn there was something in AutoIt that would do the job easiloy. After my scripts runs, I have to always press the END key to get the cursor to got the end of the first line which is a pain when you run a script 150-200 times a day! <g>

Well, I'll have to live with what I have because I couldn't get that code to work and can't take more time to figure out the ins and outs of the new UDF.

Thanks, though! Much appreciated. At least now I know the name of a new function. Cheers. ;)

Share this post


Link to post
Share on other sites

Diana (Cda),

FileGetPos was introduced in v3.3.2.0 released on 18th December, 2009. We are now on v3.3.6.1 - I would update if I were you! ;)

But I am not sure you need that function anyway. You mention FileWrite, but then say you want to position the cursor at the end of the line. ;) Are you sure you do not mean FileRead? And does this do what you want (use your own file path where indicated): :)

$sFileContent = FileRead("Your_File_Path_Here")

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hEdit = GUICtrlCreateEdit($sFileContent, 10, 10, 480, 480)

GUISetState()

ControlSend($hGUI, "", $hEdit, "^{HOME}")
Sleep(100)
ControlSend($hGUI, "", $hEdit, "{END}")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

 Hmmm, i wish i could help you, but in my opinion your question 

what it's called in AutoIt to after opening a file in FileWrite, to have the cursor go to the end of, say, the first line

has absolutely nothing to do with

I have to always press the END key to get the cursor to got the end of the first line which is a pain when you run a script 150-200 times a day! <g>

Your "question" is answered by Affe,

but if you want to SEND an END 200 times a day,

Send()
may be an option....

Unfortunately, you didn´t show  your script, so many of the "AutoIt-cracks" will ignore your posting. It is much easier to understand what you want to do when you show 10 lines of your code and explain that " between line 432 and 433 the cursor should go to End_Of_Line"

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  
Followers 0