Jump to content

FileReadLine, reads the line, and adds the "newline"..


 Share

Recommended Posts

Example:

; Creates/Opens the .txt and adds 2 seperate lines - and a new, empty, line beneeth.

$OpenFile = FileOpen("example.txt", 8 + 1)
  FileWriteLine($OpenFile, "This is the first line")
  FileWriteLine($OpenFile, "And then the follow-up")
FileClose($OpenFile)


; Opens the existing file, including the lines, and puts the seperate lines into vars.

$OpenFile = FileOpen("example.txt", 0)
  $Line1 = FileReadLine($OpenFile, 1)
  $Line2 = FileReadLine($OpenFile, 2)
FileClose($OpenFile)


; Creates a label with the vars content.

GUICtrlCreateLabel($Line1 & " - " & $Line2, 20, 20)

The result should be a label reading "This is the first line - And then the follow-up"

Though, the result is, that the label is cut in two lines, and the second(lower line) is cut in halvf horizontally.

My guess is that it is becouse FileReadLine, reads a line"break" or a "newline-function" between the lines from the choosen file.

How do I solve this problem?

Thanks alot.

EDIT: Posted original code in reply.

Edited by crz

Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

Link to comment
Share on other sites

It should be:

$OpenFile = FileOpen("example.txt", 9)

;the next openfile should be

$OpenFile = FileOpen("example.txt", 0)

That's why. :rolleyes:

And please put your code in autoit tags (click the little A next to the code button)

Everything else should work fine once that's fixed. In AutoIt it will never be a variable as a function name, such as $OpenFile("example.txt"). You have to say $OpenFile will open "example.txt", not $OpenFile is "example.txt". That won't be interpreted correctly.

Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

In the example I made a typ'O.. In my original script it says like your "correction".. and still doesn't work.

EDIT: Also, if you read the original post closer, you should know that it was a typ'O, as I say that the Label actually contains the lines, but cuts the label in two.

- It wouldn't even read the lines with my typ'O.

So the solution for me to have both lines in one label, is?

Edited by crz

Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

Link to comment
Share on other sites

Your "solution" is to post a working example which demonstrates your problem.

Because what you want is working just fine. Which means you're doing something wrong. Such as, your Label doesn't have sufficient width/height to contain a whole line or something like that...

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Date.au3>

HotKeySet("{ESC}", "Escape")
HotKeySet("{F5}", "Refresh")

#NoTrayIcon
    TraySetIcon("C:\Programmer\AutoIt\Icons\filetype-blank.ico")
    TrayTip("AutoIt", "AutoIt is minimized," & @CRLF & "to the system tray." & @CRLF & @CRLF & "- Left-click the icon to, restore." & @CRLF & "- Right-click the icon to, close.", 10, 1)
    TraySetToolTip("AutoIt")
    TraySetOnEvent(-8, "TrayRestore")
    TraySetOnEvent(-10, "TrayClose")

    Opt("TrayIconHide", 1)
    Opt("TrayAutoPause", 0)
    Opt("TrayMenuMode", 1)
    Opt("TrayOnEventMode", 1)

GUICreate("AutoIt", 200, 400, @DesktopWidth - 210, @DesktopHeight - 460, $WS_CAPTION + $WS_SYSMENU + $WS_MINIMIZEBOX)
    GUISetIcon("C:\Programmer\AutoIt\Icons\filetype-blank.ico")
    GUISetCursor(2, 0)
    GUISetBkColor("0xDDDDDD")
    GUISetFont(8, 400, "", "Tahoma")
    GUISetState(@SW_SHOW)

$MenuFiles = GUICtrlCreateMenu("Files")
    $MenuFilesClose = GUICtrlCreateMenuItem("Close          [ ESC ]", $MenuFiles)
$MenuEdit = GUICtrlCreateMenu("Edit")
    $MenuEditRefresh = GUICtrlCreateMenuItem("Refresh          [ F5 ]", $MenuEdit)

$TaskLabel = GUICtrlCreateLabel("No task!", 20, 20)
    GUICtrlSetColor($TaskLabel, 0x222222)

Opt("TrayIconHide", 0)

WinActivate("AutoIt")
    WinWaitActive("AutoIt")

WinSetState("AutoIt", "", @SW_MINIMIZE)
WinSetState("AutoIt", "", @SW_HIDE)

TrayTip("AutoIt", "AutoIt is minimized," & @CRLF & "to the system tray." & @CRLF & @CRLF & "- Left-click the icon to, restore." & @CRLF & "- Right-click the icon to, close.", 10, 1)

While 1
    $GUIMsg = GUIGetMsg()
    $GUIClose = $GUI_EVENT_CLOSE
    $GUIMinimize = $GUI_EVENT_MINIMIZE

    $NowDate = _NowDate()
    $NowTime = _NowTime()

    Select
        Case $GUIMsg = $MenuEditRefresh
            $Count = 0
            Do
                $OpenFile = FileOpen($NowDate & ".txt", 0)
                If $OpenFile = -1 Then
                    GUICtrlSetData($TaskLabel, "No task!")
                Else
                    $TheTask = FileReadLine($OpenFile, 1)
                    $TheTime = FileReadLine($OpenFile, 2)
                    FileClose($OpenFile)

                    GUICtrlSetData($TaskLabel, $TheTime & ": " & $TheTask)
                EndIf

            $Count = $Count + 1
            Until $Count = 1

        Case $GUIMsg = $MenuFilesClose
            $CloseQuestion = MsgBox(32 + 4, "AutoIt", "Are you positive that," & @CRLF & "you want to close, AutoIt?")
            If $CloseQuestion = 6 Then
                Exit
            EndIf

        Case $GUIMsg = $GUIMinimize
            Opt("TrayIconHide", 0)

            WinSetState("AutoIt", "", @SW_HIDE)

            TrayTip("AutoIt", "AutoIt is minimized," & @CRLF & "to the system tray." & @CRLF & @CRLF & "- Left-click the icon to, restore." & @CRLF & "- Right-click the icon to, close.", 10, 1)

        Case $GUIMsg = $GUIClose
            $CloseQuestion = MsgBox(32 + 4, "AutoIt", "Are you positive that," & @CRLF & "you want to close, AutoIt?")
            If $CloseQuestion = 6 Then
                Exit
            EndIf
    EndSelect
WEnd

Func TrayRestore()
    Opt("TrayIconHide", 1)

    WinSetState("AutoIt", "", @SW_SHOW)

    Sleep(100)

    WinActivate("AutoIt")
        WinWaitActive("AutoIt")

    WinSetState("AutoIt", "", @SW_RESTORE)
EndFunc

Func TrayClose()
    Opt("TrayIconHide", 1)

    $CloseQuestion = MsgBox(32 + 4, "AutoIt", "Are you positive that," & @CRLF & "you want to close, AutoIt?")
    If $CloseQuestion = 6 Then
        Exit
    Else
        Opt("TrayIconHide", 0)
    EndIf
EndFunc

Func Escape()
    If WinActive("AutoIt") Then
        Opt("TrayIconHide", 1)

        $CloseQuestion = MsgBox(32 + 4, "AutoIt", "Are you positive that," & @CRLF & "you want to close, AutoIt?")
        If $CloseQuestion = 6 Then
            Exit
        Else
            Opt("TrayIconHide", 0)
        EndIf
    EndIf
EndFunc

Func Refresh()
    $Count = 0
    Do
        $OpenFile = FileOpen($NowDate & ".txt", 0)
        If $OpenFile = -1 Then
            GUICtrlSetData($TaskLabel, "No task!")
        Else
            $TheTask = FileReadLine($OpenFile, 1)
            $TheTime = FileReadLine($OpenFile, 2)
            FileClose($OpenFile)

            GUICtrlSetData($TaskLabel, $TheTime & ": " & $TheTask)
        EndIf

    $Count = $Count + 1
    Until $Count = 1
EndFunc

The "16-06-2007.txt" says:

This is the task
15:54:32
Edited by crz

Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

Link to comment
Share on other sites

Specify width and height when creating the label (big enough to fit updated string).

Because you don't, it's created the size to fit the text "No task!". When you update it with a longer string, it doesn't fit into your label.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

As I said.. simple.. LOL

I just didn't thought it was logic to bump "the rest of the label" to a new line, so couldn't make any sence of it.

- Thanks alot.. christ I feel stupid right now!

Take care.

Edited by crz

Steffen "crz" Jorgensenwww.crz.dkcrz@crz.dk

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