Jump to content

How do you pull from an ini to a menu item array?


Recommended Posts

I want to be able to have my script save the a recent settings list to an ini. That part was not hard, but loading it back seems very hard. I can only get it to return the first value in the ini.

CODE
Func loadini()

Local $IniRead

If FileExists($FileName) Then

GUISetState(@SW_HIDE, $gui)

ProgressOn("Loading Hosts from Ini", "", "", Default, Default)

ProgressSet(20)

Sleep(200)

For $i = 0 To UBound($loaded,1) -1

$loaded[$i] = IniRead($FileName, "Hostlist", "Host." & $i, "")

Next

ProgressSet(60)

Sleep(200)

GUICtrlCreateMenuitem ($loaded[uBound($loaded,1)-1],$loadedlist)

ProgressSet(100)

Sleep(200)

ProgressOff()

GUISetState(@SW_SHOW, $gui)

Else

MsgBox(64, "Error", "File does not exist, failed to load hosts", 3)

Return

EndIf

EndFunc

Link to comment
Share on other sites

Is it that you need a For/Next loop for creating the menu items too?

For $i = 0 To UBound($loaded, 1) - 1
            GUICtrlCreateMenuItem($loaded[$i], $loadedlist)
        Next

:)

P.S. Another option is just to put the GUICtrlCreateMenuItem() inside the same loop where you read them out of the INI file. ;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Func loadini()
Local $IniRead
If FileExists($FileName) Then
GUISetState(@SW_HIDE, $gui)
ProgressOn("Loading Hosts from Ini", "", "", Default, Default)
ProgressSet(20)
Sleep(200)
For $i = 0 To UBound($loaded,1) -1
GUICtrlCreateMenuItem(IniRead($FileName, "Hostlist", "Host." & $i, ""))
ProgressSet(Round ($i / UBound($loaded) - 1))
Sleep(10)
Next
Sleep(200)
ProgressOff()
GUISetState(@SW_SHOW, $gui)
Else
MsgBox(64, "Error", "File does not exist, failed to load hosts", 3)
Return
EndIf
EndFunc

It might jump from 20 to like 10 or something (ProgressBar)

Link to comment
Share on other sites

Thanks for the replies, but it still gives me 1 return. This is where I get the initial list that goes to the ini. I basically need a way to get the ini back to that type of array, but redim and dim keep giving me errors no matter where I put it in the code in the first post.

CODE
If $hostlist[0] <> "none" Then

ReDim $hostlist[uBound($hostlist)+1]

$hostlist[uBound($hostlist)-1] = $host

Else

$hostlist[0] = $host

EndIf

GUICtrlCreateMenuitem ($hostlist[uBound($hostlist)-1],$recentfilemenu)

Link to comment
Share on other sites

Thanks for the replies, but it still gives me 1 return. This is where I get the initial list that goes to the ini. I basically need a way to get the ini back to that type of array, but redim and dim keep giving me errors no matter where I put it in the code in the first post.

CODE
If $hostlist[0] <> "none" Then

ReDim $hostlist[uBound($hostlist)+1]

$hostlist[uBound($hostlist)-1] = $host

Else

$hostlist[0] = $host

EndIf

GUICtrlCreateMenuitem ($hostlist[uBound($hostlist)-1],$recentfilemenu)

What? :)

All you gave before was a function to read from an INI and create menu items. Nothing in this code writes to the INI. In the first code the $loaded array already existed and was already magically the right size for the number of menuitems. Nothing in this code creates or sizes that array.

Quit posting random unrelated fragments and show what's needed to answer your question.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Sorry I keep posting snippets. My intentions were only to work out that one function. I have a mess of coding for the whole thing, so that's I don't care to post it. I already have it writing to the ini, so I don't need help there. I know I have everything else working great. The second piece of code was just to see if that was the track that I sould be heading down.

Basically it is that the function is not giving a list when I create the menu. It only gives one selection.

Link to comment
Share on other sites

Sorry I keep posting snippets. My intentions were only to work out that one function. I have a mess of coding for the whole thing, so that's I don't care to post it. I already have it writing to the ini, so I don't need help there. I know I have everything else working great. The second piece of code was just to see if that was the track that I sould be heading down.

Basically it is that the function is not giving a list when I create the menu. It only gives one selection.

As I pointed out in post #2, GUICtrlCreateMenuItem() is only being called once, so why should there be more than one selection?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What I have done in the past is to put the INI file info into a two dimension array, removing the deminsion that I don't need by making a new array, and then putting the array to a string where it can be used for a list or menu item.

this may not be the most efficient way of doing this, but it works in my case.

$Family_list = IniReadSection($inifile, "Model Family")
    $count = 0
    
    Dim $family_list2[$Family_list[0][0]]
; put 2 dimensional array into 1 dimension to be able to sort correctly
    While $count <> $Family_list[0][0]
        $family_list2[$count] = $Family_list[$count][1]
        $count = $count + 1
    WEnd
    _ArraySort($family_list2)
    $family_list_unique = _ArrayUnique($family_list2)
    $Family_list_all = _ArrayToString($family_list_unique, "|")

;
;
Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 1, $iUnique = 1); Written By SmOke_N
    If $vDelim = '' Then $vDelim = Chr(01)
    Local $sHold
    For $icc = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$icc] & $vDelim, $iUnique) Then _
                $sHold &= $aArray[$icc] & $vDelim
    Next
    Return StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
EndFunc ;==>_ArrayUnique
Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

I want to be able to have my script save the a recent settings list to an ini. That part was not hard, but loading it back seems very hard. I can only get it to return the first value in the ini.

Your .ini probably looks like this;

[MyFriends]
Names=John
Bobby
Ray
Kurt

If that's so, then yes, you'll only get one selection. I'm assuming that when you saved your "recent settings list", you saved it as an array, rather than converting it to a string separated by a delimiter (i.e. ",")

Here's what I would do.

Example:

If you have an $array with [John, Bobby, Ray, Kurt] as elements, it will save it into your .ini as;

John

Bobby

Ray

Kurt

Therefore, a command;

IniWrite("myfile.ini", "MyFriends", "Names", $array)oÝ÷ Ùh¥·¬º[pØmç±jjey¦è½ä¨Â­Ê§yçm¡Ú"²Ú¢{Þ®Ûa{MújºÚÊë"+­¬¡+kx"Ú,¶¸§Ø^ƯzØZ¶)í£*.®)âN¬Ê«x°Ye¢%G­+"Ë^(uïu3!kéݳÝÍjg¬

Only then the suggestions above can work...as far as I can tell.

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

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