igorm Posted March 11, 2008 Posted March 11, 2008 Hi, I want to create a menu with sub-menus so I can allow users of my program to switch between languages. For example if my program detect 5 languages in its folder it need to create 5 submenus. I tried with this: $menu3 = GUICtrlCreateMenu("Language") $language = _FileListToArray(@ScriptDir, '*.lng', 1) For $i = 1 To $language[0] $menuitem4 = GUICtrlCreateMenuItem($language[$i], $menu3) Next Now when I look at this I see it is not good idea because it seems that I can control only last item created (or there is a way to control others?), and I can not figure other way to accomplish this. So any help would be appreciated. Cheers Office 2000/XP/2003/2007 Slipstreamer
Squirrely1 Posted March 11, 2008 Posted March 11, 2008 (edited) Try replacing this line: $menuitem4 = GUICtrlCreateMenuItem($language[$i], $menu3)with these: $x = GUICtrlCreateMenuItem($language[$i], $menu3) Assign("menuitem" & $i, $x) The reason only the last one seemed to be there is because after the loop was run, $menuitem4 was set to the control ID of last item created. Better yet would be to use an array for $menuitem4 (such as $MenuitemArr[1] - $MenuitemArr[n]) Dim $MenuitemArr[84] $menu3 = GUICtrlCreateMenu("Language") $language = _FileListToArray(@ScriptDir, '*.lng', 1) For $i = 1 To $language[0] $MenuitemArr[$i] = GUICtrlCreateMenuItem($language[$i], $menu3) Next Edited March 11, 2008 by Squirrely1 Das Häschen benutzt Radar
igorm Posted March 12, 2008 Author Posted March 12, 2008 (edited) Hi, Thanks for help. I liked this way with array and I understand how it works, but now I can not figure how to control each menu. I could write it like this: Case $msg = $MenuitemArr[1] my commands Case $msg = $MenuitemArr[2] my commands Case $msg = $MenuitemArr[3] my commands ............. But I don't know how many languages will my application detect. Can you help me with this as well? Thanks in advance. Cheers Edited March 12, 2008 by igorm Office 2000/XP/2003/2007 Slipstreamer
Squirrely1 Posted March 12, 2008 Posted March 12, 2008 (edited) Edit1: Here is a good way:expandcollapse popup$menu3 = GUICtrlCreateMenu("Language") $language = _FileListToArray(@ScriptDir, '*.lng', 1) $x = $language[0] + 1 Dim $MenuitemArr[$x] $MenuitemArr[0] = $language[0] Dim $FunctionArr[$x] $FunctionArr[0] = $language[0] For $i = 1 To $language[0] $MenuitemArr[$i] = GUICtrlCreateMenuItem($language[$i], $menu3) Next For $i = 1 To $language[0] $myLang = $language[$i] Select Case StringInStr($myLang, "English") $FunctionArr[$i] = "English_Func()" Case StringInStr($myLang, "French") $FunctionArr[$i] = "French_Func()" Case StringInStr($myLang, "German") $FunctionArr[$i] = "French_Func()" EndSelect Next While 1 $msg = GUIGetMsg() For $i = 1 To $language[0] If $msg == $MenuitemArr[$i] Then $x = Eval("FunctionArr" & $i) Execute($x) Sleep(40) $msg = GUIGetMsg() EndIf Next Sleep(40) WEndThis assumes that the *.lng file is a list such as this:French English Spanish German Finnish Edited March 12, 2008 by Squirrely1 Das Häschen benutzt Radar
igorm Posted March 12, 2008 Author Posted March 12, 2008 Thanks. Cheers Office 2000/XP/2003/2007 Slipstreamer
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now