AutoIt Forums: How To... - AutoIt Forums

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How To... Set something like cookies for $inputs

#1 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 07 November 2009 - 05:04 PM

Hi :)

Simple question

How to remember (by program) text what i was wrote in Inputbox?

Example

I was wrote some text in some program to input box (long text) and i close the program
I dont want write this text again when i open this program again :(

Is there any way to remember what user set in inputs, before he close the program?
0

#2 User is offline   ProgAndy 

  • Member :D
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 1,425
  • Joined: 04-February 08
  • Location:Germany

Posted 07 November 2009 - 05:12 PM

You could use an INI-file to save the data. (IniWrite on Exit, IniRead on Startup)
0

#3 User is online   GEOSoft 

  • Mr. Nice Guy [ NOT!]
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 6,486
  • Joined: 08-December 03
  • Gender:Male
  • Location:Nanaimo, BC, Canada

Posted 07 November 2009 - 05:13 PM

View PostSobiech, on 07 November 2009 - 08:04 AM, said:

Hi :)

Simple question

How to remember (by program) text what i was wrote in Inputbox?

Example

I was wrote some text in some program to input box (long text) and i close the program
I dont want write this text again when i open this program again :(

Is there any way to remember what user set in inputs, before he close the program?

See the INI functions in the Help file under Function Reference >> File, Directory and Disk functions Reference

The two you are looking for are IniWrite and IniRead

This post has been edited by GEOSoft: 07 November 2009 - 05:15 PM

0

#4 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 07 November 2009 - 05:22 PM

I have ~~ 30 inputs xd

But ok i will try :)
0

#5 User is offline   ProgAndy 

  • Member :D
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 1,425
  • Joined: 04-February 08
  • Location:Germany

Posted 07 November 2009 - 05:35 PM

View PostSobiech, on 07 November 2009 - 05:22 PM, said:

I have ~~ 30 inputs xd

But ok i will try :)

use Arrays and For-Loops ;)
0

#6 User is online   Valuater 

  • ”Hobbyist” a passionate enjoyable activist
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 10,730
  • Joined: 28-February 05
  • Location:Riverside, CA USA

Posted 07 November 2009 - 06:06 PM

Small snipit for ideas...

[ autoIt ]    ( Popup )
Dim $Input[11], $Ini_File = False, $File_Location = @ScriptDir & "Input.ini" If FileExists($File_Location) Then $Ini_File = True For $x = 1 To 10     If $Ini_File Then $Input[$x] = IniRead($File_Location, "Input", $x, "")     $Input[$x] = InputBox("Input", "Please type in your input", $Input[$x])     IniWrite($File_Location, "Input", $x, $Input[$x]) Next  


8)

Fixed IniRead() error, still not tested

This post has been edited by Valuater: 07 November 2009 - 06:09 PM

0

#7 User is online   GEOSoft 

  • Mr. Nice Guy [ NOT!]
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 6,486
  • Joined: 08-December 03
  • Gender:Male
  • Location:Nanaimo, BC, Canada

Posted 07 November 2009 - 06:08 PM

[ code='text' ]    ( ExpandCollapse - Popup )
$sIni = @AppDataDir & "\Myapp\Myapp.ini" $Input1 = GUICtrlCreateInput() $Input2 = GUICtrlCreateInput() more more more etc. $input30 = GUICtrlCreateInput() For $i = $Input1 To $Input30     GUICtrlSetData($i, IniRead($sIni, "Settings", $i, "")) Next GUISetState() While 1    $nMsg = GUIGetMsg()    Switch $Msg       Case -3          For $i = $Input1 To $Input30              If IniRead(IniRead($sIni, "Settings", $i, "") <> GUICtrlRead($i) Then                  IniWrite($sIni, "Settings", $i, GUICtrlRead($i)              EndIf          Next          Exit    EndSwitch Wend  


Edit: Corrected closing code tag

This post has been edited by GEOSoft: 07 November 2009 - 06:09 PM

0

#8 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 07 November 2009 - 06:27 PM

Ok byt if my inputs have other names than "$InputX" ? Example
[ code='text' ]    ( Popup )
$sIni = @AppDataDir & "\Myapp\Myapp.ini" $StartKey = GUICtrlCreateInput() $RunKey = GUICtrlCreateInput() $ExitKey = GUICtrlCreateInput()  


Can I use

Dim $startkey[0], $runkey[1] ???

How can i use "for loop" if my inputs have the captions above
0

#9 User is online   Valuater 

  • ”Hobbyist” a passionate enjoyable activist
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 10,730
  • Joined: 28-February 05
  • Location:Riverside, CA USA

Posted 07 November 2009 - 08:34 PM

Can I use

Dim $startkey[0], $runkey[1] ???


No, this will not work.


How can i use "for loop" if my inputs have the captions above

You will not be able to use a "for loop" with different names
(unless they are in an array, but that is another story and more complicated)

8)
0

#10 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 07 November 2009 - 11:41 PM

View PostGEOSoft, on 07 November 2009 - 06:08 PM, said:

[ code='text' ]    ( ExpandCollapse - Popup )
$sIni = @AppDataDir & "\Myapp\Myapp.ini" $Input1 = GUICtrlCreateInput() $Input2 = GUICtrlCreateInput() more more more etc. $input30 = GUICtrlCreateInput() For $i = $Input1 To $Input30     GUICtrlSetData($i, IniRead($sIni, "Settings", $i, "")) Next GUISetState() While 1    $nMsg = GUIGetMsg()    Switch $Msg       Case -3          For $i = $Input1 To $Input30              If IniRead(IniRead($sIni, "Settings", $i, "") <> GUICtrlRead($i) Then                  IniWrite($sIni, "Settings", $i, GUICtrlRead($i)              EndIf          Next          Exit    EndSwitch Wend  


Edit: Corrected closing code tag


I have Syntax error :\
[ code='text' ]    ( Popup )
C:\Project\123.au3(278,78) : ERROR: syntax error              If IniRead(IniRead($Ini, "Settings", $i, "") <> GUICtrlRead($i) Then ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Project\123.au3(279,64) : ERROR: syntax error                  IniWrite($Ini, "Settings", $i, GUICtrlRead($i) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^  


and more more more more in rest od code (but only if i use your code :|)
0

#11 User is offline   Authenticity 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,378
  • Joined: 22-January 09
  • Gender:Male

Posted 07 November 2009 - 11:45 PM

[ autoIt ]    ( Popup )
If IniRead(IniRead($sIni, "Settings", $i, "")) <> GUICtrlRead($i) Then                  IniWrite($sIni, "Settings", $i, GUICtrlRead($i))  


You're missing the closing parentheses.
0

#12 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 08 November 2009 - 12:17 AM

View PostAuthenticity, on 07 November 2009 - 11:45 PM, said:

[ autoIt ]    ( Popup )
If IniRead(IniRead($sIni, "Settings", $i, "")) <> GUICtrlRead($i) Then                  IniWrite($sIni, "Settings", $i, GUICtrlRead($i))  


You're missing the closing parentheses.


[ code='text' ]    ( Popup )
C:\Project\123.au3(283,46) : ERROR: IniRead() [built-in] called with wrong number of args.     If IniRead(IniRead($Ini, "Settings", $i, ""))     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Project\D2NT1.5v3.6M2ConfigEditorByInFlames.au3 - 1 error(s), 0 warning(s) >Exit code: 2    Time: 0.217  


O_o


Ahh and i change names of $inputs :)

I have now 61 input fields :)

This post has been edited by Sobiech: 08 November 2009 - 12:19 AM

0

#13 User is offline   Authenticity 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,378
  • Joined: 22-January 09
  • Gender:Male

Posted 08 November 2009 - 12:29 AM

Sorry, moi mistake:

[ autoIt ]    ( Popup )
If IniRead($sIni, "Settings", $i, "") <> GUICtrlRead($i) Then                  IniWrite($sIni, "Settings", $i, GUICtrlRead($i))  


This is syntactically correct, it might not be correct though.
0

#14 User is online   GEOSoft 

  • Mr. Nice Guy [ NOT!]
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 6,486
  • Joined: 08-December 03
  • Gender:Male
  • Location:Nanaimo, BC, Canada

Posted 08 November 2009 - 12:31 AM

I think it was me that left off the closing parenthesis. Sorry about that.
0

#15 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 08 November 2009 - 12:53 AM

Ok thx now its work :)

So I have

[ code='text' ]    ( Popup )
For $i = $Input1 To $Input61     GUICtrlSetData($i, IniRead($Ini, "Settings", $i, "")) Next While 1    $nMsg = GUIGetMsg()    Switch $nMsg       Case -3          For $i = $Input1 To $Input61 If IniRead($Ini, "Settings", $i, "") <> GUICtrlRead($i) Then                  IniWrite($Ini, "Settings", $i, GUICtrlRead($i))              EndIf          Next          Exit    EndSwitch Wend  


I think this can help me to load last $inputs from .ini?
And one more thing, actually i dont have .ini from i can load informations. First i must create it :\

I used one time this thing
[ code='text' ]    ( Popup )
IniWrite($Ini, "Keys", "StartKey", $input43)  

And this is ok, but i have 61 inputs O_o.
Is there faster way to create that ini?
0

#16 User is offline   Authenticity 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,378
  • Joined: 22-January 09
  • Gender:Male

Posted 08 November 2009 - 01:03 AM

[ autoIt ]    ( Popup )
For $i = 1 To 61     IniWrite($Ini, "Keys", $i, Eval("Input" & $i)) Next


It's not recommended to use control's ID as the key, value, or iterator (such as in a For...Next loop). It's not consistent and is bugs prone. You can build an array of input, using loops where the iterator is an index. Just my thought.
0

#17 User is offline   colafrysen 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 248
  • Joined: 30-October 07
  • Gender:Male
  • Location:Sweden

Posted 08 November 2009 - 01:30 AM

Extremly bad-written and over-exaggerated code FTW!
[ autoIt ]    ( ExpandCollapse - Popup )
#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $INI = "MyINI.ini" $Form1 = GUICreate("Massive over-exaggeration FTW", 800, 600) Dim $Input[85] Dim $InputText[85] For $n = 0 To UBound($InputText)-1 Step 1     $InputText[$n] = IniRead($INI,"Inputs","Input"&$n,"") Next $n = 0 For $x= 8 To 600 Step 130     For $y = 8 To 400 Step 24     $Input[$n] = GUICtrlCreateInput($InputText[$n], $x, $y, 121, 21)     $n+=1 Next Next $Save = GUICtrlCreateButton("Save values",8,450,100,100) GUISetState(@SW_SHOW) While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $save             For $n = 0 To UBound ($Input)-1 Step 1                 ToolTip("saving value " & $n)                 IniWrite($INI,"Inputs","Input"&$n,GUICtrlRead($Input[$n]))             Next         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd  

1

#18 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 08 November 2009 - 02:04 AM

Colafrysen said:



You chaged my life O_o

And Thx for all who help me :)

Now i must understand your code in 100% :)

This post has been edited by Sobiech: 08 November 2009 - 02:22 AM

0

#19 User is online   Valuater 

  • ”Hobbyist” a passionate enjoyable activist
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 10,730
  • Joined: 28-February 05
  • Location:Riverside, CA USA

Posted 08 November 2009 - 03:54 AM

me too! lol

We have many choices.... :P

8)
0

#20 User is offline   Sobiech 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 54
  • Joined: 12-May 09
  • Gender:Male
  • Location:Poland

Posted 08 November 2009 - 05:27 PM

Ok i did what i want :)

Big thanks for all :)
0

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users