AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dynamic var as v%var% doesn't work

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Apr 18, 2008 5:37 pm    Post subject: dynamic var as v%var% doesn't work Reply with quote

i have the following piece of code
Code:
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
Gui, 4:Tab, %Counter%
Gui, 4:Add, ListBox, v%Tabs%
Counter+=1
}
As you can see, i read several values from a inifile (wich is done correctly by the way), but AHK fails to add my ListBox because of the v%Tabs% part. How can i fix this to make it work.
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 370
Location: canada

PostPosted: Fri Apr 18, 2008 5:43 pm    Post subject: Reply with quote

what is the content of your INI file?
how do you know
Quote:
(wich is done correctly by the way),

where is your output?

tip > Counter can be replaced with %A_index% and is autoincremented every loop itereation so no need for counter+=1 or counter = 0

what is the output of

msgbox, %Tabs%
_________________
-=Raz=-
Back to top
View user's profile Send private message
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Apr 18, 2008 7:38 pm    Post subject: Reply with quote

this is the contents of the inifile:
Code:
[bus]
aantal=10
1=SCC
2=Emma
3=ABB (boschstraat)
4=Intratuin Heerlen (In de Kramer)
5=Intratuin Kerkrade (Wiebachstraat)
6=Groen
7=Schoonmaak
8=Facilitair
9=Metaal
10=J. Defauwes

and the values i get back from this code:
Code:
Inifile = bus.ini
IniRead, edAantal, %Inifile%, bus, aantal
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
msgbox, %Tabs%
Counter+=1
}
are the numberd parts (SCC, Emma, ABB (boschstraat), Intratuin Heerlen (In de Kramer), etc. etc.) each as a seperate message, so the loop works. but AHK is complaining about the line
Code:
Gui, 4:Add, ListBox, v%Tabs%
(wich i had to remove for the msgbox to work) He perticularly complains about the v%Tabs% part
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 850
Location: London, UK

PostPosted: Fri Apr 18, 2008 8:07 pm    Post subject: Reply with quote

What your current code is doing is adding a new listbox, (not an entry) for each entry in your ini. then giving it the variable reference of whatever is in the inifile.

What you probably want is either one listbox, with all the contents in one.
Or multiple listboxes with the contents of each one either way it will be.

Code:
Inifile = bus.ini
IniRead, edAantal, %Inifile%, bus, aantal 
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %a_index%
Gui, 4:Add, ListBox, vList%a_index%,%tabs%
}
Code:

Tabs:=""
Inifile = bus.ini
IniRead, edAantal, %Inifile%, bus, aantal 
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %a_index%
Tabs.=tabs "|"
}
Gui, 4:Add, ListBox, vList%a_index%,%tabs%


Not tested but something like one of them
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Apr 18, 2008 9:43 pm    Post subject: Reply with quote

What i want to do (if you look correctly) is to add a listbox on several tabs. The var of the listbox MUST have the name from the inifile, as there will be data added later to the listbox (and later to that same inifile, in different sections). eacht tab get's a different section in the inifile. the bu section of the infile is a indicator for how many section (and tabs) there will be in the inifile

that's why i tried this:
Code:
Gui, 4:Tab, %Counter%
Gui, 4:Add, ListBox, v%Tabs%
, but AHK trips over the v%Tabs% part. that is where my problem is.

Here you have full code of the gui i try to create:
Code:
ShowEditor()
{
Gui, 4:+owner1
Gui +Disabled
Inifile = bus.ini
IniRead, edAantal, %Inifile%, bus, aantal
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
edTabs = %edTabs%|%Tabs%
Counter+=1
}
StringTrimLeft, edTabs, edTabs, 1
Gui, 4:Add, Tab2,, %edTabs%
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
Gui, 4:Tab, %Counter%
Gui, 4:Add, ListBox, v%Tabs%
Counter+=1
}
;LV_Add om items toe te voegen
Gui, 4:Tab
Gui, 4:Add, Button, w50 Default, OK
Gui, 4:Show,, Bewerk INI
}
return



[edit]in my new code, i only removed the counter var and replaced it with %a_index%, but that posts no change[/edit]

[edit2]here is the exact error that i get:
Code:

Error: A control's variable must be global or static.  The current thread will exit.

Specifically: vSCC

   Line#
   095: StringTrimLeft,edTabs,edTabs,1
   096: Gui,4:Add,Tab2,,%edTabs%
   097: Counter = 1
   098: Loop,%edAantal%
   099: {
   100: IniRead,Tabs,%Inifile%,bus,%Counter%
   101: Gui,4:Tab,%Counter%
--->   102: Gui,4:Add,ListBox,v%Tabs%
   103: Counter += 1
   104: }
   106: Gui,4:Tab
   107: Gui,4:Add,Button,w50 Default,OK
   108: Gui,4:Show,,Bewerk INI
   109: }
   110: Return

---------------------------
OK   
---------------------------
[/edit2]
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Fri Apr 18, 2008 11:12 pm    Post subject: Reply with quote

Quote:
Error: A control's variable must be global or static.

thats probably your problem.
As your gui is created in a function, all vars are local by default.
try this:
Code:
ShowEditor()
{
global
Gui, 4:+owner1
Gui +Disabled
Inifile = bus.ini
IniRead, edAantal, %Inifile%, bus, aantal
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
edTabs = %edTabs%|%Tabs%
Counter+=1
}
StringTrimLeft, edTabs, edTabs, 1
Gui, 4:Add, Tab2,, %edTabs%
Counter=1
Loop, %edAantal%
{
IniRead, Tabs, %Inifile%, bus, %Counter%
Gui, 4:Tab, %Counter%
Gui, 4:Add, ListBox, v%Tabs%
Counter+=1
}
;LV_Add om items toe te voegen
Gui, 4:Tab
Gui, 4:Add, Button, w50 Default, OK
Gui, 4:Show,, Bewerk INI
}
return
Back to top
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Apr 18, 2008 11:14 pm    Post subject: Reply with quote

Thanks mate. the global did it. thx thx and thx again Very Happy
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Apr 18, 2008 11:24 pm    Post subject: Reply with quote

Now just one more problem. The OK button i create AFTER each list control is put INSIDE the tabcontrol. How do i get it Below the tabcontrol again (preferably without using a position marker x and y)

I solved it already by just using the x10 parameter of the Ok button
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group