Jump to content

Next image....Back Image Saving to ini problem


Recommended Posts

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?

#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 by epicfail
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by epicfail
Link to comment
Share on other sites

Here's what u need:

#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 by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

@epicfall

Did u check the script, I posted above???

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

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 by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Yes correct:

Add it to the script and u get:

#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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Try this

Another sample:

I used numbering for the picture images for easy coding.

#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 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]
Link to comment
Share on other sites

  • 2 weeks later...

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

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