Jump to content

creating many based on number of found files


 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 by igorm
Link to comment
Share on other sites

Edit1: Here is a good way:

$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)
WEnd

This assumes that the *.lng file is a list such as this:

French
English
Spanish
German
Finnish
Edited by Squirrely1

Das Häschen benutzt Radar

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