Sign in to follow this  
Followers 0
Merchants

FileWrite how to write a big text click to read more

14 posts in this topic

FileWrite how to write a big text like this:

$file = FileOpen("test.txt", 1)

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

FileWrite($file, [
test1
test3
hi
yo man
Line1])

FileClose($file)

file results must be:

test1

test3

hi

yo man

Line1

But how do i make this happen ?

Share this post


Link to post
Share on other sites



Merchants,

You use the concatenation operator & to make a single string: ;)

FileWrite($file, "test1" & @CRLF & "test3" & @CRLF & "hi" & @CRLF & "yo man" & @CRLF & "Line1")

Just like it shows in the example in the Help file. :)

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

#3 ·  Posted (edited)

well it is a VERY long text to make that happen is it not poseble what i say in post 1?

Edited by Merchants

Share this post


Link to post
Share on other sites

Hello Merchants,

Try This:

$file = FileOpen("test.txt", 1)

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

FileWrite($file, "test1" & @CRLF _
    & "test3" & @CRLF _
    & "hi" & @CRLF _
    & "yo man" & @CRLF _
    & "Line1")

FileClose($file)

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

well it is a VERY long text to make that happen is it not poseble what i say in post 1?

Melba's Example will do what you ask Merchant, as will mine, our examples are different but will produce the same results, it all depends on how you want your code to look.

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Merchants.

well it is a VERY long text

Then break it up into smaller chunks and add the parts together using &= like this: ;)

$sText = "test1" & @CRLF
$sText &= "test3" & @CRLF
$sText &= "hi" & @CRLF
$sText &= "yo man" & @CRLF
$sText &= "Line1"

FileWrite($file, $sText)

Is that better? :)

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

#7 ·  Posted (edited)

well that is still very long work

i need to write a smal text like this

function myReadLine(filename, linenumber)
{
    var _tmpfile;
    var _line;

    _tmpfile = FileOpen(filename, 0);

    if(_tmpfile)
    {
        var _linenumber = 0;
        while(!_tmpfile.eof)
        {
            _line = _tmpfile.ReadLine();
            if(_line)
            {
                _linenumber = _linenumber + 1;
                if (_linenumber == linenumber)
                {
                    _tmpfile.Close();
                    return _line;
                }
            }
        }
        _tmpfile.Close();
    }

    return ""; // empty string if can't read file, or can't find the line wanted.
}
to set all the @CRLF is very long work if this was a smal text then i was not here..

i need to write it whiteout the CRLF

i hope that that is poseble..

Edited by Merchants

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

if i just paste it like this

$file = FileOpen("test.txt", 1)

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

FileWrite($file, [
function myReadLine(filename, linenumber)
{
    var _tmpfile;
    var _line;

    _tmpfile = FileOpen(filename, 0);

    if(_tmpfile)
    {
        var _linenumber = 0;
        while(!_tmpfile.eof)
        {
            _line = _tmpfile.ReadLine();
            if(_line)
            {
                _linenumber = _linenumber + 1;
                if (_linenumber == linenumber)
                {
                    _tmpfile.Close();
                    return _line;
                }
            }
        }
        _tmpfile.Close();
    }

    return ""; // empty string if can't read file, or can't find the line wanted.
}])

FileClose($file)

then the file results must be like this whit the spaces and enters and taps:

function myReadLine(filename, linenumber)

{

var _tmpfile;

var _line;

_tmpfile = FileOpen(filename, 0);

if(_tmpfile)

{

var _linenumber = 0;

while(!_tmpfile.eof)

{

_line = _tmpfile.ReadLine();

if(_line)

{

_linenumber = _linenumber + 1;

if (_linenumber == linenumber)

{

_tmpfile.Close();

return _line;

}

}

}

_tmpfile.Close();

}

return ""; // empty string if can't read file, or can't find the line wanted.

}

Edited by Merchants

Share this post


Link to post
Share on other sites

Merchants,

If you do not want to add the @CRLFs within AutoIt, then I can only suggest that you type the lines into an editor and save the result as a file - the editor adding the line feeds automatically. Then you can read the file into AutoIt with FileRead - you will include the @CRLFs from the file - and you can finally write the result using FileWrite. :)

By the way what is that strange mixture of code you are trying to write? ;)

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

#12 ·  Posted (edited)

.. well i al do it this way:

$file = FileOpen("test.txt", 1)

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


$sText = "function myReadLine(filename, linenumber)" & @CRLF
$sText &= "{" & @CRLF
$sText &= "   var _tmpfile;" & @CRLF
$sText &= "   var _line;" & @CRLF
$sText &= ""
$sText &= "   _tmpfile = FileOpen(filename, 0);" & @CRLF
$sText &= ""
$sText &= "   if(_tmpfile)" & @CRLF
$sText &= "   {" & @CRLF
$sText &= "      var _linenumber = 0;" & @CRLF
$sText &= "      while(!_tmpfile.eof)" & @CRLF
$sText &= "      {" & @CRLF
$sText &= "         _line = _tmpfile.ReadLine();" & @CRLF
$sText &= "         if(_line)" & @CRLF
$sText &= "         {" & @CRLF
$sText &= "            _linenumber = _linenumber + 1;" & @CRLF
$sText &= "            if (_linenumber == linenumber)" & @CRLF
$sText &= "            {" & @CRLF
$sText &= "               _tmpfile.Close();" & @CRLF
$sText &= "               return _line;" & @CRLF
$sText &= "            }" & @CRLF
$sText &= "         }" & @CRLF
$sText &= "      }" & @CRLF
$sText &= "      _tmpfile.Close();" & @CRLF
$sText &= "   }" & @CRLF
$sText &= "   return ""; // empty string if can't read file, or can't find the line wanted." & @CRLF
$sText &= "}"

FileWrite($file, $sText)


FileClose($file)
it is meby the fastest way to do it Edited by Merchants

Share this post


Link to post
Share on other sites

Merchants,

If you do not want to add the @CRLFs within AutoIt, then I can only suggest that you type the lines into an editor and save the result as a file - the editor adding the line feeds automatically. Then you can read the file into AutoIt with FileRead - you will include the @CRLFs from the file - and you can finally write the result using FileWrite. :)

By the way what is that strange mixture of code you are trying to write? ;)

M23

it is java script codes

Share this post


Link to post
Share on other sites

Merchants,

Thank you for that answer. :)

Glad you found a way to do what you want. ;)

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

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