epicfail Posted August 28, 2009 Posted August 28, 2009 (edited) hello forum ok here is my problem i have this code to change the image with a button Next/Back I would like to be able to save it to a txt or ini so it saves what image is loaded so it opens that image the next time the program starts. Can that be done with this code i have or i have to do it some other way? expandcollapse popup#include <GUIConstants.au3> Dim $Pick[5], $pics = 4 $Form1 = GUICreate("NextImage", 414, 305, 246, 194) $Pick[1]= GUICtrlCreatePic(@ScriptDir&"\1image.bmp", 8, 8, 393, 233) $Pick[2]= GUICtrlCreatePic(@ScriptDir&"\2image.bmp", 8, 8, 393, 233) GUICtrlSetState( -1, $GUI_HIDE) $Pick[3]= GUICtrlCreatePic(@ScriptDir&"\3image.bmp", 8, 8, 393, 233) GUICtrlSetState( -1, $GUI_HIDE) $Pick[4]= GUICtrlCreatePic(@ScriptDir&"\4image.bmp", 8, 8, 393, 233) GUICtrlSetState( -1, $GUI_HIDE) $notice = GUICtrlCreateLabel("Picture #1", 20, 258, 100, 30) GUICtrlSetFont( -1, 15, 700) $Back= GUICtrlCreateButton("Back", 160, 256, 97, 41) $Next = GUICtrlCreateButton("Next", 264, 256, 97, 41) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Back $set = -1 get_pic($set) Case $msg = $Next $set = 1 get_pic($set) Case Else EndSelect WEnd Exit Func get_pic($t) For $x = 1 to $pics $State = GUICtrlGetState($pick[$x]) If $State = 80 Then If $x = 1 And $t = -1 Then Return If $x = $pics And $t = 1 Then Return Guictrlsetstate($Pick[$x], $GUI_HIDE) Guictrlsetstate($Pick[$x + $set], $GUI_SHOW) GUICtrlSetData($notice, "Picture #" & $x + $set) Return EndIf Next EndFunc Edited August 28, 2009 by epicfail
BrettF Posted August 28, 2009 Posted August 28, 2009 Maybe save the variable $t (or $set, I hope you know which one i mean) and load that from the ini on startup by calling get_pic($t) just before you show your GUI? Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
epicfail Posted August 28, 2009 Author Posted August 28, 2009 (edited) ok i worked out how to save it to the ini but how do i do the read bit? i tryed $t = IniRead("C:\Settings.ini", "Pic", "dir", "") get_pic($t) at the top of my script it didnt work tho Edited August 28, 2009 by epicfail
epicfail Posted August 28, 2009 Author Posted August 28, 2009 is there any other way to do this to read the pic from a file?
Manjish Posted August 28, 2009 Posted August 28, 2009 (edited) Here's what u need: expandcollapse popup#include <GUIConstants.au3> Dim $Pick[5], $pics = 4 global $path="image.txt" $filer=FileOpen($path,0) $Form1 = GUICreate("NextImage", 414, 305, 246, 194) $Pick[1]= GUICtrlCreatePic(@ScriptDir&"\image1.jpg", 8, 8, 393, 233) $Pick[2]= GUICtrlCreatePic(@ScriptDir&"\image2.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[3]= GUICtrlCreatePic(@ScriptDir&"\image3.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[4]= GUICtrlCreatePic(@ScriptDir&"\image4.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[1]= GUICtrlCreatePic(@ScriptDir&"\image1.jpg", 8, 8, 393, 233) if FileReadLine($filer,1)<>"" Then $x=FileReadline($filer,1) Switch $x Case 1 For $m=2 to 4 GUICtrlSetState($pick[$m],$gui_hide) $notice = GUICtrlCreateLabel("Picture #1", 20, 258, 100, 30) Next case 2 GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[3],$gui_hide) GUICtrlSetState($pick[4],$gui_hide) $notice = GUICtrlCreateLabel("Picture #2", 20, 258, 100, 30) case 3 GUICtrlSetState($pick[2],$gui_hide) GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[4],$gui_hide) $notice = GUICtrlCreateLabel("Picture #3", 20, 258, 100, 30) case 4 GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[2],$gui_hide) GUICtrlSetState($pick[3],$gui_hide) $notice = GUICtrlCreateLabel("Picture #4", 20, 258, 100, 30) EndSwitch EndIf FileClose($filer) GUICtrlSetFont( -1, 15, 700) $Back= GUICtrlCreateButton("Back", 160, 256, 97, 41) $Next = GUICtrlCreateButton("Next", 264, 256, 97, 41) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Back $set = -1 get_pic($set) Case $msg = $Next $set = 1 get_pic($set) Case Else EndSelect WEnd Exit Func get_pic($t) For $x = 1 to $pics $State = GUICtrlGetState($pick[$x]) If $State = 80 Then If $x = 1 And $t = -1 Then Return If $x = $pics And $t = 1 Then Return Guictrlsetstate($Pick[$x], $GUI_HIDE) Guictrlsetstate($Pick[$x + $set], $GUI_SHOW) GUICtrlSetData($notice, "Picture #" & $x + $set) $filew=FileOpen($path,2) FileWriteLine($filew,$x+$set) FileClose($filew) Return EndIf Next EndFunc Just create a file "image.txt" in ur script directory and put any number between 1 to 4 in it, e.g. 1. (U ll need to do this initially only.) Edited August 28, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
BrettF Posted August 28, 2009 Posted August 28, 2009 Do not PM me asking for help ever again. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
epicfail Posted August 28, 2009 Author Posted August 28, 2009 so i cant run it from a ini? cos i dont really want to have a ini and a txt file cos i already have a ini file 4 other stuff.
Manjish Posted August 28, 2009 Posted August 28, 2009 (edited) @epicfall Did u check the script, I posted above??? Edited August 28, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
epicfail Posted August 28, 2009 Author Posted August 28, 2009 yeah but can i change it to read from a ini?
Manjish Posted August 28, 2009 Posted August 28, 2009 yes sure u can.. Give it a try!! [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
epicfail Posted August 28, 2009 Author Posted August 28, 2009 thats the thing i dont really know how to change it to a ini cos reading a ini is 1 line im staring at the code i dont know what to do.
Manjish Posted August 28, 2009 Posted August 28, 2009 (edited) c'mon.. I have already done everything for you.. All u need to do is change it to an ini from txt. The least bit u could do is Google it!! Don't expect to be spoon fed my friend!! If you are stuck then I ll gladly help you, but don't expect any help if you urself are not willing to put in an effort!! Its not that difficult!! I am sure you'll find it out!! Give it a try Edited August 28, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
epicfail Posted August 28, 2009 Author Posted August 28, 2009 if IniRead("C:\Settings.ini", "Pic", "dir", "") Then $x=IniRead("C:\Settings.ini", "Pic", "dir", "") Switch $x is that right?
Manjish Posted August 28, 2009 Posted August 28, 2009 Yes correct: Add it to the script and u get: expandcollapse popup#include <GUIConstants.au3> Dim $Pick[5], $pics = 4 global $path=@ScriptDir&"\image.ini" ;$filer=FileOpen($path,0) $Form1 = GUICreate("NextImage", 414, 305, 246, 194) $Pick[1]= GUICtrlCreatePic(@ScriptDir&"\image1.jpg", 8, 8, 393, 233) $Pick[2]= GUICtrlCreatePic(@ScriptDir&"\image2.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[3]= GUICtrlCreatePic(@ScriptDir&"\image3.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[4]= GUICtrlCreatePic(@ScriptDir&"\image4.jpg", 8, 8, 393, 233) ;GUICtrlSetState( -1, $GUI_HIDE) $Pick[1]= GUICtrlCreatePic(@ScriptDir&"\image1.jpg", 8, 8, 393, 233) MsgBox(4096,"",IniRead($path,"image","dir","xx")) if IniRead($path,"image","dir","")<>"" Then $x=IniRead($path,"image","dir","") Switch $x Case 1 For $m=2 to 4 GUICtrlSetState($pick[$m],$gui_hide) $notice = GUICtrlCreateLabel("Picture #1", 20, 258, 100, 30) Next case 2 GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[3],$gui_hide) GUICtrlSetState($pick[4],$gui_hide) $notice = GUICtrlCreateLabel("Picture #2", 20, 258, 100, 30) case 3 GUICtrlSetState($pick[2],$gui_hide) GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[4],$gui_hide) $notice = GUICtrlCreateLabel("Picture #3", 20, 258, 100, 30) case 4 GUICtrlSetState($pick[1],$gui_hide) GUICtrlSetState($pick[2],$gui_hide) GUICtrlSetState($pick[3],$gui_hide) $notice = GUICtrlCreateLabel("Picture #4", 20, 258, 100, 30) EndSwitch EndIf GUICtrlSetFont( -1, 15, 700) $Back= GUICtrlCreateButton("Back", 160, 256, 97, 41) $Next = GUICtrlCreateButton("Next", 264, 256, 97, 41) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Back $set = -1 get_pic($set) Case $msg = $Next $set = 1 get_pic($set) Case Else EndSelect WEnd Exit Func get_pic($t) For $x = 1 to $pics $State = GUICtrlGetState($pick[$x]) If $State = 80 Then If $x = 1 And $t = -1 Then Return If $x = $pics And $t = 1 Then Return Guictrlsetstate($Pick[$x], $GUI_HIDE) Guictrlsetstate($Pick[$x + $set], $GUI_SHOW) GUICtrlSetData($notice, "Picture #" & $x + $set) IniWrite($path,"image","dir",$x+$set) Return EndIf Next EndFunc Put a file called image.ini in your script directory with contents: [name] dir=1 Done!! [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
epicfail Posted August 28, 2009 Author Posted August 28, 2009 thanks heaps i just wasnt sure if that was right it didnt really look right what i did.
Manjish Posted August 28, 2009 Posted August 28, 2009 You will never know if anything's right untill you try.. play around.. change a thing here n there!! N your best buddy is msgbox() for this.. Check what value each variable is giving out, iniread, write etc!! Only then you'll know!! Good that you tried as much!! Cheers, M [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
nfaustin Posted August 28, 2009 Posted August 28, 2009 (edited) Try this Another sample: I used numbering for the picture images for easy coding. expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; Assume the images is place on IMAGES folder which resides on your script path. ; Assume the image's filename is numbering and start on number 1 and incremental. Global $Maximum = 5 ; Maximum numbers of image(also filename) on IMAGES folders. Global $x = IniRead(@ScriptDir&"\Settings.ini", "image", "dir", "1") ; read the previous save filename's number. $Form1 = GUICreate("NextImage", 414, 305, 246, 194) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $Pic1 = GUICtrlCreatePic(@ScriptDir&"\IMAGES\"&$x&".jpg", 8, 8, 393, 233) ; display the picture $Button1 = GUICtrlCreateButton("BACK", 160, 256, 97, 41) GUICtrlSetOnEvent ($Button1,"SELECT_PREV") $Button2 = GUICtrlCreateButton("NEXT", 264, 256, 97, 41) GUICtrlSetOnEvent ($Button2,"SELECT_NEXT") If $x = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) If $x = $Maximum Then GUICtrlSetState($Button2, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func SELECT_PREV() if $x > 1 then $x-=1 GUICtrlSetImage($Pic1,@ScriptDir&"\Folders\"&$x&".jpg") ; set the picture IniWrite(@ScriptDir&"\Settings.ini", "image", "dir",$x) ; save the filename If $x = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) If $x < $Maximum Then GUICtrlSetState($Button2, $GUI_ENABLE) EndIf EndFunc Func SELECT_NEXT() if $x < $Maximum then $x+=1 GUICtrlSetImage($Pic1,@ScriptDir&"\Folders\"&$x&".jpg") ; set the picture IniWrite(@ScriptDir&"\Settings.ini", "image", "dir",$x) ; save the filename If $x = $Maximum Then GUICtrlSetState($Button2, $GUI_DISABLE) If $x > 1 Then GUICtrlSetState($Button1, $GUI_ENABLE) EndIf EndFunc ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ; Clicking Minimize, Restore, and Close button of the Window Func SpecialEvents() SELECT Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc ; End of SpecialEvents ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Hope this will give you more idea. Edited August 28, 2009 by nfaustin [font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
epicfail Posted August 28, 2009 Author Posted August 28, 2009 that code is more simple seems good but it dont change the pic when i click next it just changes when i get out then bak in the gui
nfaustin Posted September 7, 2009 Posted September 7, 2009 that code is more simple seems good but it dont change the pic when i click next it just changes when i get out then bak in the guiI had similar script like yours and that code is working... Promise.Did you follow the Picture's name numbering? [font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now