Jump to content

Gui , Filewrite , File Read ...


Recommended Posts

Hi guys, I need a little help again.

This is my script.

$x = filereadline("file.txt",1)
$Form1 = GUICreate("Gui", 633, 454, 203, 152)
$Label1 = GUICtrlCreateLabel($x, 160, 408, 62, 33)
guisetstate(@SW_SHOW)
While 1
guictrlsetdata($label1,Guictrlread($label1) + .011)
Exit
Wend

Func onautoitexit()
Filewrite("file.txt", guictrlread($label1))
Endfunc

This is what the txt looks like

0.000000

Now the problem: The problem is that when i open the program again (the second time) $label1 is equal to 0 why?

Please help!

Thank You

Edit: Forgot Guisetstate

Edited by kkKrazy
code
Link to comment
Share on other sites

The problem with your text is the variables as caps matter and should always; Label1 and label1 are two different things. However there seems to be a problem with the OnAutoItExit() function as it terminates the Label1 before itself is called those receiving a NULL character or 0. I tried this with every version of OnAutoItExit functions possible and cannot get it to carry over the Label1 display parameter with it. But I did get your program to work using this:

#Include <GuiConstants.au3>

Dim $msg

$file = FileOpen("file.txt", 0)

$x = FileReadLine($file, 1)

FileClose($file)

$Form1 = GUICreate("Gui", 633, 454, 203, 152)

$Label1 = GUICtrlCreateLabel($x, 160, 408, 62, 33)

GUISetState(@SW_SHOW)

; Because you could only get this once with the way you wrote it out I decided to place this outside the looping

GUICtrlSetData($Label1, GUICtrlRead($Label1) + .011)

$file = FileOpen("file.txt", 2)

FileWriteLine($file, GUICtrlRead($Label1))

FileClose($file)

; However, you don't need the loop because you terminated on the first tried so @SW_SHOW on the GUISetState seems kinda pointless. Could possiblily use @SW_HIDE next time since you are creating a GUI and terminating very quitely

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Wend

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

The problem with your text is the variables as caps matter and should always; Label1 and label1 are two different things.

$label1 and $Label1 are treated as the same variable as AutoIt is primarily a case insensitive language.

@kkKrazy

Your script has ended when OnAutoItExit() is called. You will need to save the contents of the control to variable before OnAutoItExit() is called so you can read the value of the variable within OnAutoItExit(). Macros and variables are still in memory when OnAutoItExit() is running.

$x = filereadline("file.txt",1)
$Form1 = GUICreate("Gui", 633, 454, 203, 152)
$Label1 = GUICtrlCreateLabel($x, 160, 408, 62, 33)
guisetstate(@SW_SHOW)

While 1
    guictrlsetdata($label1, Guictrlread($label1) + .011)
    $save = guictrlread($label1)
    Exit
Wend

Func onautoitexit()
    FileDelete("file.txt")
    FileWrite("file.txt", $save)
Endfunc

:D

Link to comment
Share on other sites

@kkKrazy

Your script has ended when OnAutoItExit() is called. You will need to save the contents of the control to variable before OnAutoItExit() is called so you can read the value of the variable within OnAutoItExit(). Macros and variables are still in memory when OnAutoItExit() is running.

Ahhh, thank you then MHz, but isn't your calling filedelete something that time consuming as with the OnAutoItExit()? You increased the time but 10 msec on my computer with over 1 thousand continous test on each of the stands. That is a considerable amount of time if you must run them continously. Yet you can even further downgrade mine if you want to those increasing it even more.

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

Ahhh, thank you then MHz, but isn't your calling filedelete something that time consuming as with the OnAutoItExit()? You increased the time but 10 msec on my computer with over 1 thousand continous test on each of the stands. That is a considerable amount of time if you must run them continously. Yet you can even further downgrade mine if you want to those increasing it even more.

I modified kkKrazys' code enough to work. I know of no information regarding continuous testing that you mention and no requirement was asked. I did not downgrade your code so I do not understand where you gathered that concern and it was never my intention to downgrade your code. Upon reviewing your code though, where is OnAutoItExit() in your example to explain kkKrazys' concern with the problem with the initial code that the topic asks about? :D
Link to comment
Share on other sites

Upon reviewing your code though, where is OnAutoItExit() in your example to explain kkKrazys' concern with the problem with the initial code that the topic asks about? :D

As I had said before I had tried it every way with not referring to storage of the variable, so I had bypassed it to a working program hence the code I had gotten. I don't want to say if anyones code is imperfect just creating it to be streamline is all I do. As with the variables regarding you first post you should always regardless to what language you are using keep them the same throughout your project, it is a good way to fall into a spiral on neatiness and future production of your code

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

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