 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 6:11 am Post subject: I can't find the failure ... pls help |
|
|
hi,
can you tell me why this script doesn't work:
| Code: | #Persistent
#singleinstance force
inifile = config.ini
;-------------------------------------------------[
Menu, subMenu, Add, &Restart, Restart
Menu, subMenu, Add, &Exit, Quit
;-------------------------------------------------[
Menu, CoreMenu, Add, Menu, Restart
Menu, CoreMenu, Add, ;sep
;-------------------------------------------------[
IniRead, ThisCoreMenuAmount, %inifile%, Config, Items ;-----[ IniRead - the first menu item
Loop, %ThisCoreMenuAmount%
{
IniRead, ThisCoreMenuEntry, %inifile%, Menu, Item%A_Index%
IniRead, ThisSubMenuAmount, %inifile%, %ThisCoreMenuEntry%, Entry ;-----[ IniRead - the first menu item
if ThisSubMenuAmount = ERROR
{
Break
}
ThisAIndex = %A_Index%
Loop, %ThisSubMenuAmount%
{
IniRead, ThisSubMenuEntry, %inifile%, %ThisCoreMenuEntry%, Desc%A_Index%
if ThisSubMenuAmount = ERROR
{
Break
}
Menu, subMenu%ThisAIndex%, Add, %ThisSubMenuEntry%, ThisItemAction
;MsgBox, 48, Msg, %ThisCoreMenuEntry%: %ThisSubMenuEntry%
}
Menu, CoreMenu, Add, %ThisCoreMenuEntry%, :subMenu%ThisAIndex%
;MsgBox, 48, Msg, %ThisCoreMenuEntry%
}
;-------------------------------------------------[
Menu, CoreMenu, Add,
Menu, CoreMenu, Add, Program, :subMenu
Menu, CoreMenu, Show
Return
;-------------------------------------------------[
ThisItemAction:
Loop
{
IniRead, ThisItemDescVar, %inifile%, %ThisItemVar%, Desc%A_Index%
if ThisItemDescVar = %A_ThisMenuItem%
{
IniRead, ThisItem, %inifile%, %ThisItemVar%, Cont%A_Index%
break
}
}
MsgBox, %ThisItem%
Return
;-------------------------------------------------[
Restart:
Reload
Return
;-------------------------------------------------[
Quit:
ExitApp
Return |
INI:
[Config]
Items=2
[Menu]
Item1=Menu1
Item2=Menu2
[Menu1]
Entry=2
Desc1=SubMenu1
Cont1=SubMenu1
Desc2=SubMenu2
Cont2=SubMenu2
[Menu2]
Entry=2
Desc1=SubMenu1
Cont1=SubMenu1
Desc2=SubMenu2
Cont2=SubMenu2
look forward ... _________________ Works on my machine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 6:57 am Post subject: |
|
|
Hi,
What doesn't work? Please be more specific. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 7:04 am Post subject: |
|
|
Please try to use this line | Code: | Item := Item%A_Index%
IniRead, ThisCoreMenuEntry, %inifile%, Menu, %Item%
|
Do the same for | Code: | | IniRead, ThisSubMenuEntry, %inifile%, %ThisCoreMenuEntry%, Desc%A_Index% | and | Code: | | Menu, subMenu%ThisAIndex%, Add, %ThisSubMenuEntry%, ThisItemAction | and | Code: | | Menu, CoreMenu, Add, %ThisCoreMenuEntry%, :subMenu%ThisAIndex% | and | Code: | | IniRead, ThisItemDescVar, %inifile%, %ThisItemVar%, Desc%A_Index% | and | Code: | | IniRead, ThisItem, %inifile%, %ThisItemVar%, Cont%A_Index% |
Just a guess. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 7:20 am Post subject: |
|
|
The MsgBox (MsgBox, %ThisItem% ) doesn't appear ...
But I didn't try your suggestion, yet. I will test it now. _________________ Works on my machine! |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 7:27 am Post subject: |
|
|
Sorry I should add that <Desc1=SubMenu1> is the entry of the
Submenu and <Cont1=SubMenu1> should be the contents of the MsgBox. _________________ Works on my machine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 8:02 am Post subject: |
|
|
ThisItemVar is never set, where should the iniread read from? _________________ Ciao
toralf  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 8:04 am Post subject: |
|
|
BTW: You could limit/reduce the amount of disc access, if you would read the menus at script start into arrays or lists and only work on the arrays/lists afterwards. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 9:52 am Post subject: |
|
|
awkward! as blind as a mole. many thanks for your feedback!
replacing it with %ThisCoreMenuEntry% solved it.
I can't figure out your second idea but I'm working on it ...
umek _________________ Works on my machine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 10:19 am Post subject: |
|
|
I hope you mean %A_ThisMenuItem% or %A_ThisMenu% (instead of ThisItemVar) _________________ Ciao
toralf  |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 11:15 am Post subject: |
|
|
I am all mixed up now. No normally not!
You gave me the hint to replace ThisItemVar because it was not set yet.
I replaced ThisItemVar with ThisCoreMenuEntry because ThisCoreMenuEntry is the variable for the Section of my ini-file.
It works so far.
Replacing %ThisCoreMenuEntry% (before ThisItemVar) with %A_ThisMenuItem% or %A_ThisMenu% causes errors.
I don't know why because %A_ThisMenu% should be the same as %ThisCoreMenuEntry%. _________________ Works on my machine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 11:26 am Post subject: |
|
|
I do not know why it is causing errors.
But ThisCoreMenuEntry should be wrong, since it changes in the loop from Menu1 to Menu2. So after that it will always be Menu2.
But your routine, should look up the right section in the INI and that should be the one with A_ThisMenu, AFAIK.
Please add a Msgbox and test the content of all these vars. I'm sure you'll find a solution. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 12:12 pm Post subject: |
|
|
I think it's right. It's a loop in a loop. First the loop reads and creates the
contents of the SubMenu in Menu1. If the loop reaches the end it will do the
same with Menu2. I build in MsgBoxes and it works fine with ThisCoreMenuEntry.
But not with %A_ThisMenuItem% or %A_ThisMenu%.
Take a look (with MsgBox):
| Code: |
#Persistent
#singleinstance force
inifile = config.ini
;-------------------------------------------------[
Menu, subMenu, Add, &Restart, Restart
Menu, subMenu, Add, &Exit, Quit
;-------------------------------------------------[
Menu, CoreMenu, Add, Menu, Restart
Menu, CoreMenu, Add, ;sep
;-------------------------------------------------[
IniRead, ThisCoreMenuAmount, %inifile%, Config, Items ;-----[ IniRead - the first menu item
Loop, %ThisCoreMenuAmount%
{
IniRead, ThisCoreMenuEntry, %inifile%, Menu, Item%A_Index%
IniRead, ThisSubMenuAmount, %inifile%, %ThisCoreMenuEntry%, Entry ;-----[ IniRead - the first menu item
if ThisSubMenuAmount = ERROR
{
Break
}
ThisAIndex = %A_Index%
Loop, %ThisSubMenuAmount%
{
IniRead, ThisSubMenuEntry, %inifile%, %ThisCoreMenuEntry%, Desc%A_Index%
if ThisSubMenuAmount = ERROR
{
Break
}
Menu, subMenu%ThisAIndex%, Add, %ThisSubMenuEntry%, ThisItemAction
MsgBox, 48, Msg, %ThisCoreMenuEntry%: %ThisSubMenuEntry%
}
Menu, CoreMenu, Add, %ThisCoreMenuEntry%, :subMenu%ThisAIndex%
MsgBox, 48, Msg, %ThisCoreMenuEntry%
}
;-------------------------------------------------[
Menu, CoreMenu, Add,
Menu, CoreMenu, Add, Program, :subMenu
Menu, CoreMenu, Show
Return
;-------------------------------------------------[
ThisItemAction:
Loop
{
IniRead, ThisItemDescVar, %inifile%, %ThisCoreMenuEntry%, Desc%A_Index%
if ThisItemDescVar = %A_ThisMenuItem%
{
IniRead, ThisItem, %inifile%, %ThisCoreMenuEntry%, Cont%A_Index%
break
}
}
MsgBox, %ThisItem%
Return
;-------------------------------------------------[
Restart:
Reload
Return
;-------------------------------------------------[
Quit:
ExitApp
Return
|
I changed the INI for a better overview:
INI:
[Config]
Items=2
[Menu]
Item1=Menu1
Item2=Menu2
[Menu1]
Entry=2
Desc1=Menu1 SubMenu1 Desc
Cont1=Menu1 SubMenu1 Cont
Desc2=Menu1 SubMenu2 Desc
Cont2=Menu1 SubMenu2 Cont
[Menu2]
Entry=2
Desc1=Menu2 SubMenu1 Desc
Cont1=Menu2 SubMenu1 Cont
Desc2=Menu2 SubMenu2 Desc
Cont2=Menu2 SubMenu2 Cont
But let us drop the subject. I should be happy that it works.
umek _________________ Works on my machine! |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 12:20 pm Post subject: |
|
|
toralf I'm sorry and you are right. It just developes radom features.
The MsgBox (MsgBox, %ThisItem% ) doesn't appear evrytime.
Ok I have still food for thought ... but I will get it.
umek _________________ Works on my machine! |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Jun 29, 2005 1:32 pm Post subject: |
|
|
Here is something that works, you can extend this as you want.
| Code: | #Persistent
#singleinstance force
/*
[Menus]
Menus=Umek|Toralf
[SubMenus]
Actions1=Action 11|Action 12
Tasks1=Task 11|Task 12
Actions2=Action 21|Action 22
Tasks2=Task 21|Task 22
*/
;read ini
IniRead, MenuList, %A_ScriptName%, Menus, Menus
StringSplit,Menu,MenuList,|
Loop, %Menu0%
{
IniRead, SubActionList, %A_ScriptName%, SubMenus, Actions%A_Index%
IniRead, SubTaskList, %A_ScriptName%, SubMenus, Tasks%A_Index%
StringSplit, SubAction[%A_Index%],SubActionList,|
StringSplit, SubTask[%A_Index%],SubTaskList,|
}
Loop, %Menu0%
{
i = %A_Index%
j := SubAction[%i%]0
Menu := Menu%i%
Loop, %j%
{
Action := SubAction[%i%]%A_Index%
Menu, %Menu%, Add, %Action%, ThisItemAction
}
Menu, CoreMenu, Add, %Menu%, :%Menu%
}
Menu, CoreMenu, Show
Return
ThisItemAction:
Loop, %Menu0%
{
If ( Menu%A_Index% = A_ThisMenu )
{
i := A_Index
break
}
}
j := SubAction[%i%]0
Loop, %j%
{
If ( SubAction[%i%]%A_Index% = A_ThisMenuItem )
{
Task := SubTask[%i%]%A_Index%
break
}
}
MsgBox, %A_ThisMenu%`n%A_ThisMenuItem%`n%Task%
Return |
Tip: try to make loops simple, saves you lots of bugs _________________ Ciao
toralf  |
|
| Back to top |
|
 |
umek
Joined: 02 Oct 2004 Posts: 74
|
Posted: Wed Jun 29, 2005 7:59 pm Post subject: |
|
|
amazing !!! but in all probability done with one hand behind yours back.
at first view a little bit confusing for me but I'm busy disassembling the nature of your script ...
toralf many many thx for this fantastic sample ...
I will try to follow your tip!
regards umek _________________ Works on my machine! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|