Jump to content

Problem with Variable-Names


Pat
 Share

Recommended Posts

Hello,

I want generate "dynamic Variable-Names" in a While-Loop

I'd like to do something like this, perhaps somebody has an idea.

$counter = 1

$line = 10

While 1

$base_$count = GUICtrlCreateCheckbox($Counter, 10, $line,-1) ; I want that the Variable-Name is in the first loop base_1, next loop base_2, then base_3 and so on

$counter = $count + 1

$line = $line + 20

GUISetState()

Wend

At the moment i'll only get this Error when i try to run this programm

==> Variable used without being declared.:

$base_&$count= GUICtrlCreateCheckbox($counter, 10, $line,-1)

^ ERROR

The Second Question that i have is

how can i get the checked checkbox and work on ?

Pleas help me to resolv this problem.

Excuse my bad English.

Sincerly Pat

Edited by Pat
Link to comment
Share on other sites

1. I hope you have other code for creating a GUI, otherwise no point in using GUICtrlCreateCheckbox($Counter, 10, $line,-1) or GUISetState()

2. You would be better creating an array and holding your variables in there

Can you explain what your script is going to do, as the above is a bit vague

Edit: Spelling

Edited by sandyd
----[ SandyD ]---
Link to comment
Share on other sites

Hello Sandy,

i want to Modfiy (add/delete/list) the content of a text/ini file.

the Add Function is allready done, the list function solved i with this call notepad.exe $file

here is the complete Source

#include <GuiConstants.au3>

$ini = "setup.ini"

$hGui           = GUICreate("Modify IniFile")

$menu = GUICtrlCreateMenu ("&File")
$menu_list_item = GUICtrlCreateMenuitem ("Show Ini",$menu)
$menu_add_item  = GUICtrlCreateMenuitem  ("Add Programm", $menu)
$menu_del_item  = GUICtrlCreateMenuitem  ("Del Programm", $menu)
$menu_blank_item = GUICtrlCreateMenuitem  ("", $menu)
$menu_exit_item = GUICtrlCreateMenuitem ("Exit",$menu)
$about = GUICtrlCreateMenu ("&?")

GUISetState()
While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Or $msg = $menu_exit_item Then ExitLoop
    If $Msg = $menu_list_item Then Run('notepad.exe "' & $ini & '"')
    If $Msg = $menu_add_item Then Insert_Programm()
    If $Msg = $menu_del_item Then Delete_Programm() 
WEnd

Func Delete_Programm()
    $count = 1
    $zeile = 10
    While 1 
        $Programm = FileReadLine($ini, $count)
        If @error = -1 Then ExitLoop
        $Programm_zaehler = "programm" & $count
        $Menu_item_zaehler= "menu" & $count
        $Check_&$count= GUICtrlCreateCheckbox($Programm, 10, $zeile,-1) ; <-- There Is my Problem
        $count = $count + 1
        $zeile = $zeile + 20
        GUISetState()
; The Delete comes later, at first i want  Checkboxes for every line 
    Wend
EndFunc

Func Insert_Programm()
    $Programm = InputBox("Programm", "Enter Path\programm.exe", "")
    $Parameter = InputBox("Parameter", "Enter Switches", "")
    If $Programm = "" or $Parameter = "" Then
        MsgBox(64,"Error", "Program or Parameter missing") 
        Exit
    EndIf
    FileWrite($ini,'"'& $Programm & '"  ; "' & $Parameter & '"' & @CRLF)
EndFunc

The Content of setup.ini is:

Line1

Line2

Line3

I hope this helps

Edited by Pat
Link to comment
Share on other sites

if understand this right, you want to add checkboxes to your gui if you add apps right ?

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Ok, here is a idea i came upp with.

Create a Ini, create a Index something like this.

[Index]
apps=app1,app2,app3

[app1]
string=string

[app2]
string=string

[app3]
string=string

#include <array.au3>

$index = IniRead('inifile', 'index', 'apps', 'no apps inn index')

$apps = StringSplit($index, ',')
_arraydisplay($apps,'') ; will fail here if array is empty / nonexistant.

well dont know if this is an efficiant way of doing this, but i can be done.

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Thanks for your Idea,

but the problem is, the Ini File is later parsed by an other program an every line would be used vor an action as it stands in the file

so I cann't work with an ini like yours.

Unfortunally i don't now who the program works wich is parsing this ini,

i only now that the ini will read line by line and every line will takes an action

I'll hope you understand me

Link to comment
Share on other sites

Your problem could be that the variable $Check_ isn't declared anywhere.

$Check_&$count= GUICtrlCreateCheckbox($Programm, 10, $zeile,-1); <-- There Is my Problem

you have 2 variables here - $Check_ and $count

while $count exists (1) I can't see $Check_ anywhere else.

I may be wrong and I appologize ($Check_ could be regarded as a local variable into Delete function) but I guess is worth a try to declare $Check_ first

(Maybe a

Dim $Check_
somewhere inside your function).

I hope to be right :whistle:

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

What you really need to do (as suggested earlier) is use an array.

for example,

local $Check[2], $zeile = 10
While 1
        $Programm = FileReadLine($ini, $Check[0]+1)
        If @error = -1 Then ExitLoop
        $Check[0] += 1
        Redim $Check[$Check[0]+1]
        $Programm_zaehler = "programm" & $Check[0]
        $Menu_item_zaehler= "menu" & $Check[0]
        $Check[$Check[0]]= GUICtrlCreateCheckbox($Programm, 10, $zeile,-1) 
        $zeile = $zeile + 20
        GUISetState()
    Wend

I eliminated the variable $Count, and am using $Check[0] to hold the number found, incremented by one each time a new line is read. This way, you will have an array where $Check[0] always holds the number of vectors in the array (for example, if you create 20 checkboxes, $Check[0]=20) and all subsequent vectors of $Check ($Check[1], $Check[2], etc.) will be the handles of the controls

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