Jump to content

variable within a varible's name?


Recommended Posts

Well from what I have seen in the helpfile, the way you suggest looks like alot more work. You have to make a few UDFs and it looks like the same amount of code, plus the while loop is still there....

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

Well from what I have seen in the helpfile, the way you suggest looks like alot more work. You have to make a few UDFs and it looks like the same amount of code, plus the while loop is still there....

It is certainly different, but once you've done it I think you'll find it much easier in the long run. Don't feel like making lots of little functions is a bad thing - Structured programming is GOOD for you! :P

This is as far as your posted script went, done with GuiOnEventMode (I trimmed it down to 4 programs 'cause I don't have your ini):

#include <GuiConstants.au3>
Opt("GuiOnEventMode", 1) ; Set on event mode
Global $program[4][7], $program_checkbox, $program_path_button ; BB - added elements to the second dimension

; Modified to simulate ini input
For $i = 0 To 3
    $program[$i][0] = "Program_" & $i ; Program name/Input box
    $program[$i][1] = Mod($i, 2) ; Checked (even=0, odd=1)
    $program[$i][2] = "v0." & $i ; Version/Input box
    $program[$i][3] = "C:\Path_" & $i ; Program path
    $program[$i][4] = "C:\Install\Setup_" & $i & ".exe" ; Installer path
    ; $program[$i][5] = Button
    ; $program[$i][6] = Checkbox
Next

; Create GUI
$checkbox_y = 30
$name_y = 25
$hMainGui = GUICreate("Change Latest Versions", 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hMainGui)

; Add controls for each program
For $i = 0 To 3
    $program[$i][6] = GUICtrlCreateCheckbox($program[$i][0], 5, $checkbox_y, 15, 15) ; BB - modified variable
    If $program[$i][1] = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
    If $program[$i][1] = 0 Then GUICtrlSetState(-1, $GUI_UNCHECKED)
    $program[$i][0] = GUICtrlCreateInput($program[$i][0], 25, $name_y, 125, 25)
    $program[$i][2] = GUICtrlCreateInput($program[$i][2], 150, $name_y, 75, 25)
    $program[$i][5] = GUICtrlCreateButton("Path", 230, $name_y, 50, 25) ; BB - modified variable
    GUICtrlSetOnEvent($program[$i][5], "_PathButton")
    $checkbox_y = $checkbox_y + 25
    $name_y = $name_y + 25
Next

; Add general controls
$save = GUICtrlCreateButton("Save Changes", 25, 550, 100, 25)
GUICtrlSetOnEvent($save, "_SaveButton")
$cancel = GUICtrlCreateButton("Cancel Changes", 150, 550, 100, 25)
GUICtrlSetOnEvent($cancel, "_CancelButton")
GUICtrlCreateLabel("Standard Programs", 100, 5, 150, 15)
GUICtrlCreateLabel("Instructions:", 20, 430, 60, 25)
GUICtrlCreateLabel("Checked boxes mean that the program next to it will be scanned for." & _
        " Uncheck the box if you wish to not scan for it. Changes will be " & _
        "saved until you come back and undo them in this same window. If you " & _
        "wish to permanently delete a custom entry, check the appropriate boxes " & _
        "and select 'delete checked programs' (highly unreccomended). When " & _
        "changing a version, make sure to use the syntax X.X.X.X as shown already. " & _
        "If version is not important and you wish to simply check for existance, " & _
        "type 'exist' into the version box. NOTE: all changes to 'path' are " & _
        "immediate and do not require the 'save' button be pressed.", 20, 450, 560, 85)

; Display GUI
GUISetState()
While 1
    Sleep(100)
WEnd


; =================================
;   Local Functions
; =================================

Func _Quit()
    Exit
EndFunc   ;==>_Quit


Func _PathButton()
    Local $ProgPath, $InstPath, $i, $ProgNum
    
    ; Determine which Path button was pushed
    For $i = 0 To UBound($program) - 1
        If $program[$i][5] = @GUI_CtrlId Then
            $ProgNum = $i
            MsgBox(64, "Debug", "Control ID = " & @GUI_CtrlId & "  Index = " & $ProgNum)
            ExitLoop
        EndIf
    Next
    ; Get path for program install
    $ProgPath = FileSelectFolder("Locate program folder", "", 1 + 4) ; 1=Create, 4=Edit
    If $ProgPath <> "" Then GUICtrlSetData($program[$ProgNum][0], $ProgPath)
    
    ; Get path for installation executable
    $InstPath = FileOpenDialog("Locate installer executable", "", "All Files (*.*)", 1) ; 1=Must exist
    If Not @error Then GUICtrlSetData($program[$ProgNum][2], $InstPath)
EndFunc   ;==>_PathButton


Func _SaveButton()
    MsgBox(64, "Save", "You clicked SAVE!")
    Exit
EndFunc   ;==>_SaveButton


Func _CancelButton()
    MsgBox(64, "Save", "You clicked CANCEL!")
    Exit
EndFunc   ;==>_CancelButton

Hope that helps you get over your Event-o-phobia! :nuke:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, Salty, that is really awesome of you to go out of your way and make that for me! :nuke:

I am going to steal a few things I learned from it such as how you made the folder browse window (really neat!)

Here is how I am handling my path button right now.

when the path is pressed, GUICtrlOnEvent runs the _PathButton command.

for some reason it will not load the default values into the Input boxes. any idea to as why?

I have not added the folder browsing capability yet but I'm pretty busy at work right now and my boss isn't so keen on me messing with my script at work, I tend to get distracted. :P

Func _PathButton()
    $locGUI=GUICreate("Locations", 400, 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $locGUI)
    GUICtrlCreateLabel("Enter the location of the EXE file.", 20, 20, 360, 25)
    $program[$i][3]=GUICtrlCreateInput($program[$i][3],20, 50, 360, 25)
    $program[$i][4]=GUICtrlCreateInput($program[$i][4], 20, 80, 360, 25)
    $PB_cancel=GUICtrlCreateButton("Cancel", 200, 120, 50, 30)
    GuiCtrlSetOnEvent(-1, "_Back")
    $PB_OK=GUICtrlCreateButton("OK", 100, 120, 50, 30)
    GuiCtrlSetOnEvent(-1, "_Save")
    GUISetState()
EndFunc

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

Just to help a bit more with your OnEvent-O-Phobia I am going to post this template I always use to start my GUI scripts since I started using OnEvent Mode.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Program Name:  Template - OnEventMode
;Description:   Template for OnEventMode GUI scripts
;Filename:      Template - OnEventMode.au3
;Used With:     
;Created by:    Jarvis J Stubblefield (support "at" vortexrevolutions "dot" com)
;Created on:    06/20/2006
;Modified on:   
;Modified by:   
;Version:       0.0.1
;Copyright:     Copyright (C) 2006 Vortex Revolutions. All Rights Reserved.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Declare Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $wHeight, $wWidth, $m_HWnd           ;Window variables
Global $wTitle                              ;Window variables II

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Preprocessor ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ;Set GUI to ONEvent Mode.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** File Installations ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Registry Information ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Command Line Options ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#cs UNCOMMENT FOR COMMANDLINE!
If $CmdLine[0] > 0 Then
    If StringRight($CmdLine[1], 4) = ".ext" Then
        _SomeFunc($CmdLine[1])
    Else
        _ErrorMsg("Incorret file extension. Please try again.")
        _TerminateApp()
    EndIf
EndIf
#ce

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$wHeight = 300
$wWidth  = 300
$wTitle  = "Template - OnEventMode"

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Creation ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Main GUI Creation
$m_HWnd     = GUICreate($wTitle, $wWidth, $wHeight)
;Main Options
$m_Options  = GUICtrlCreateButton("Options", 5, ($wHeight - 25), 94, 20)
;Main Help
$m_Help     = GUICtrlCreateButton("Help", 103, ($wHeight - 25), 94, 20)
;Main Exit
$m_Exit     = GUICtrlCreateButton("Exit", 201, ($wHeight - 25), 94, 20)

;Disable Options and Help until added
GUICtrlSetState($m_Options, $GUI_DISABLE)
GUICtrlSetState($m_Help, $GUI_DISABLE)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Set Events ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;GUI Events Handled by _GUIEventHandler()
GUICtrlSetOnEvent($m_Options, "_GUIEventHandler")
GUICtrlSetOnEvent($m_Exit, "_GUIEventHandler")
GUICtrlSetOnEvent($m_Help, "_GUIEventHandler")

;System Events Handled by _SysEventHandler()
GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $m_HWnd)

GUISetState(@SW_SHOW, $m_HWnd)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Main Program Loop ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1
    Sleep(100)
WEnd

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Event Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $m_Exit
            _TerminateApp()
        Case $m_Options
        Case $m_Help
    EndSwitch
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            GUIDelete($m_HWnd)
            _TerminateApp()
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case $GUI_EVENT_MAXIMIZE
        Case $GUI_EVENT_PRIMARYDOWN
        Case $GUI_EVENT_PRIMARYUP
        Case $GUI_EVENT_SECONDARYDOWN
        Case $GUI_EVENT_SECONDARYUP
        Case $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_RESIZED
        Case $GUI_EVENT_DROPPED
    EndSwitch
EndFunc

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _ErrorMsg($message)
    MsgBox(48 + 262144, "Error!", $message)
EndFunc

Func _TerminateApp()
    Exit
EndFunc

If you notice I use two Functions to handle the events. From there I can either put in scripted code, or call out another function, but with parameters if needed. GUICtrlOnEvent() doenst support functions with parameters, and I sometimes find this useful so that is why I have added teh _GUIEventHandler and _SysEventHandler().

I hope this helps you on your AutoIt Journey,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

That is a really nice template. I don't know if I would ever have a use for it in the near future but I stashed it away anyways. :P Who knows when I might need it.

My only problem still is that it is not saving or reading out the default locations, is it becuase it is in a different function?

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

That is a really nice template. I don't know if I would ever have a use for it in the near future but I stashed it away anyways. :P Who knows when I might need it.

My only problem still is that it is not saving or reading out the default locations, is it becuase it is in a different function?

What exactly are you trying to accomplish? It seems you are trying to use the same variables to declare the GUICtrlCreateInput, and the default of that function. I am not sure how that is supposed to turn out, or if it would even give you your desired "default".

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Thanks, Salty, that is really awesome of you to go out of your way and make that for me! :)

I am going to steal a few things I learned from it such as how you made the folder browse window (really neat!)

Here is how I am handling my path button right now.

when the path is pressed, GUICtrlOnEvent runs the _PathButton command.

for some reason it will not load the default values into the Input boxes. any idea to as why?

I have not added the folder browsing capability yet but I'm pretty busy at work right now and my boss isn't so keen on me messing with my script at work, I tend to get distracted. :P

Func _PathButton()
    $locGUI=GUICreate("Locations", 400, 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $locGUI)
    GUICtrlCreateLabel("Enter the location of the EXE file.", 20, 20, 360, 25)
    $program[$i][3]=GUICtrlCreateInput($program[$i][3],20, 50, 360, 25)
    $program[$i][4]=GUICtrlCreateInput($program[$i][4], 20, 80, 360, 25)
    $PB_cancel=GUICtrlCreateButton("Cancel", 200, 120, 50, 30)
    GuiCtrlSetOnEvent(-1, "_Back")
    $PB_OK=GUICtrlCreateButton("OK", 100, 120, 50, 30)
    GuiCtrlSetOnEvent(-1, "_Save")
    GUISetState()
EndFuncoÝ÷ Ûú®¢×|ý·v)àÊ«ºÆ zíí7ê趦jºÚÉÊ+­ç-,¨¹ªÞ¢÷«Â¸­x-ç^}«¥¶­Æ­Ó~©®+jm7ê-ÚÝ7ê趦Ó~¢ã­Ø^znµº1rí®HÆÚrL!z|¨¹ÊÞj׶¦j)ÆP¢÷¢²Ø^r^~Ü­æ­x-ërÝBwÊ­ë¾)ඬyÊ'teßÛ"­rí®HËh±©¦V{*.j·Ê0§­Ê«²Ú+j¨~Ø^rí¢¹HÇè®Ø^znµº1zȧ¶¦j)ÆP^yÛh­ëay2¢êïj¸nW®±¨:w°k+hv­Â¥u·®±éÞÀihm©oj¸nW¬{ayû§rبú+¶§{(Úèìjwky§mç^}«¥¶­Çë¢kayÊ'¶º%²)íéq!«­¢+Ù±½°ÀÌØí±½U$°ÀÌØí%¹ÁÕÑ|Ä°ÀÌØí%¹ÁÕÑ|È()Õ¹}AÑ¡  ÕÑѽ¸ ¤($ÀÌØí±½U$õU%
ÉÑ ÅÕ½Ðí1½Ñ¥½¹ÌÅÕ½Ðì°ÐÀÀ°ÈÀÀ¤(%U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}
1=M°ÅÕ½Ðí}á¥ÐÅÕ½Ðì°ÀÌØí±½U$¤(%U%
Ñɱ
ÉÑ1° ÅÕ½Ðí¹ÑÈÑ¡±½Ñ¥½¸½Ñ¡a¥±¸ÅÕ½Ðì°ÈÀ°ÈÀ°ÌØÀ°ÈÔ¤($ÀÌØí%¹ÁÕÑ|ÄôU%
Ñɱ
ÉÑ%¹ÁÕСե
ÑɱI ÀÌØíÁɽɵlÀÌØí¥ulÍt¤°ÈÀ°ÔÀ°ÌØÀ°ÈÔ¤($ÀÌØí%¹ÁÕÑ|ÈôU%
Ñɱ
ÉÑ%¹ÁÕСե
ÑɱI ÀÌØíÁɽɵlÀÌØí¥ulÑt¤ÈÀ°àÀ°ÌØÀ°ÈÔ¤($ÀÌØíA   }¹°õU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí
¹°ÅÕ½Ðì°ÈÀÀ°ÄÈÀ°ÔÀ°ÌÀ¤(%Õ¥
ÑɱMÑ=¹Ù¹Ð ´Ä°ÅÕ½Ðí}    ¬ÅÕ½Ðì¤($ÀÌØíA   }=,õU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí=,ÅÕ½Ðì°ÄÀÀ°ÄÈÀ°ÔÀ°ÌÀ¤(%Õ¥
ÑɱMÑ=¹Ù¹Ð ´Ä°ÅÕ½Ðí}MÙÅÕ½Ðì¤(%U%MÑMÑÑ ¤)¹Õ¹

The _Save() function would read the new values from the second GUI using the control IDs in $Input_1 and $Input_2 (declared as Global outside the function so they will be visible in the _Save() function) and set them to the input controls back in the main GUI at contol IDs $program[$i][3] and $program[$i][4]. Then the _Save() function deletes the GUI at $locGUI, leaving the main GUI on the screen.

:nuke:

Edit: Tweaked to cover deleting the second GUI.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I am not sure that the issue with the varaible equalling the input with the variable as a default was a problem because I am doing it the whole time in the main GUI screen. I did change them and it is still not reading it out in the input box. It is unable to read the program variable as proven by the message box I inserted within the pathbutton function that would read out the [$i][3] and [$i][4] arrays and it came up blank. :P

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

I think I may know what is going on. The $i variable within the _PathButton() Function is not being assigned correctly, probably becuase of the fact that it's outside of the for...next loop of the pathbuttons being created. I threw a messagebox that called the $i variable in the pathbutton function and $i is set to '33'. No coincidence that 33 is one more than 32. I guess $i goes one higher after the for...next loop ends.

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

I figured it out. Salty, I was using your UBound loop that found out which button was pressed (ingenious) and after 30 minutes of staring at the screen realized that I was not making my path buttons variables. :P DOH! (searches for dunce cap smiley) I made them set as $program[$i][5] and it couldnt have worked better. thanks a bunch! this is really starting to come together as a fully functional script! :nuke:

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Link to comment
Share on other sites

I figured it out. Salty, I was using your UBound loop that found out which button was pressed (ingenious) and after 30 minutes of staring at the screen realized that I was not making my path buttons variables. :P DOH! (searches for dunce cap smiley) I made them set as $program[$i][5] and it couldnt have worked better. thanks a bunch! this is really starting to come together as a fully functional script! :nuke:

Churchill:

Never, never, never give up!

:)
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...