kpu Posted November 20, 2006 Share Posted November 20, 2006 First, thanks for taking the time to read my post. I appreciate any help anyone can provide me.My Goal:I'm trying to read an ini section name, then a section called Name and create a tray menu item from the "Name" with a defined variable that can be called be the "TrayGetMsg()". My problem is that I don't know how to correctly create the variable for the menu item. Here's what the ini file looks like. There are multiple names...client1, client2, client3...etc.[Client1] Name=My Client Address= 10.10.10.10Heres what I have for code so far:expandcollapse popup#Include <Constants.au3> #NoTrayIcon Dim $strSettings = "settings.ini" Dim $strClient, $x, $client,$strClientMenu,$StrClientName Opt("TrayMenuMode",1) _GetRDPSessions() TrayCreateItem("") $settingsitem = TrayCreateMenu("Settings") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $aboutitem Exitloop Case $msg = $strClientMenu[$x] MsgBox(64,"Selection","You've selected " & $strClientMenu[$x]) Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func _GetRDPSessions() $var = IniReadSectionNames($strSettings) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] ;Read Name in section $strClient = IniRead($strSettings,$var[$i],"Name","") If $var[$i] = "Configuration" then Else ;Create menu item ;MsgBox(4096, "Client", "File:" & $strSettings & @CRLF & "Clientname: " & $var[$i] & @CRLF & "Name:" & $strClient) _CreateTrayMenu($strClient) EndIf Next EndIf EndFunc Func _CreateTrayMenu($StrClient) For $x = 1 To $x[0][0] $strClientMenu[$x] = TrayCreateItem($StrClient) Next EndFuncIs there any good documentation somewhere that explains what the heck For $i = 1 To $var[0]. I have a basic idea, but I'm apparently missing some basics here. Again, Thanks for any help you can provide me! http://www.kpunderground.com Link to comment Share on other sites More sharing options...
tittoproject Posted November 20, 2006 Share Posted November 20, 2006 (edited) This works expandcollapse popup#Include <Constants.au3> #NoTrayIcon Global $strSettings = @ScriptDir & "\settings.ini" Global $NumberClients = 0 Global $clientsInfo[$NumberClients + 1][2] Global $clientsMenu[$NumberClients + 1] _GetClientsInfo() Opt("TrayMenuMode",1) For $i = 1 To $clientsInfo[0][0] $clientsMenu[$i] = TrayCreateItem($clientsInfo[$i][0]) Next TrayCreateItem("") $settingsitem = TrayCreateMenu("Settings") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $aboutitem Exitloop Case $msg = $exititem ExitLoop Case Else For $i = 1 To $clientsInfo[0][0] If $msg = $clientsMenu[$i] Then MsgBox(64, "Client Nr. " & $i ,'Name: ' & $clientsInfo[$i][0] & @LF _ & 'Address: ' & $clientsInfo[$i][1]) EndIf Next EndSelect WEnd Func _GetClientsInfo() Local $sectionNames = IniReadSectionNames($strSettings) ; If error... If @error Then Return MsgBox(4096, "", "Error occurred, probably no INI file.") EndIf For $i = 1 To $sectionNames[0] If StringInStr($sectionNames[$i], 'Client', 1) Then ; Read Client Info Local $clientNumber, $clientName, $clientAddress $clientNumber = StringTrimLeft($sectionNames[$i], 6) $clientName = IniRead($strSettings, $sectionNames[$i], 'Name', '') $clientAddress = IniRead($strSettings, $sectionNames[$i], 'Address', '') ; Fill Client Info Into "$clientsInfo" Array $NumberClients += 1 ReDim $clientsInfo[$NumberClients + 1][2] ReDim $clientsMenu[$NumberClients + 1] $clientsInfo[0][0] = $NumberClients $clientsInfo[$clientNumber][0] = $clientName $clientsInfo[$clientNumber][1] = $clientAddress EndIf Next EndFunc Edited November 20, 2006 by tittoproject Link to comment Share on other sites More sharing options...
Valuater Posted November 20, 2006 Share Posted November 20, 2006 that looks real clean titto there are also numerous examples in the scripts and scraps section made just for tray menus from an ini file 8) Link to comment Share on other sites More sharing options...
kpu Posted November 20, 2006 Author Share Posted November 20, 2006 This works Thanks! What you've done is way passed my comprehension...but I like it! Now I just have to dissect it to understand what you've done. http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Rad Posted November 20, 2006 Share Posted November 20, 2006 (edited) Is there any good documentation somewhere that explains what the heck For $i = 1 To $var[0]. I have a basic idea, but I'm apparently missing some basics here. Its a loop, example: For $i = 1 To 10 Msgbox(0,"",$i) NextoÝ÷ Ù8b³¥ÊÞj×ë,j£ajÜ"Wb²ZË]·¶)b¶³]¢ç©l¢f¤z+]yÊÞjÇ¥G+ºÚ"µÍÜ ÌÍÚHHLÈHÝLBÙØÞ ][ÝÉ][ÝË ÌÍÚJB^ The Step is the method used, so instead of +1 (default, doesnt need to be included) its -1 The $i is more or less just a placeholder... you can use it too For more help look at your Autoit Help document (Start > Autoit > Autoit Help File), then select "Index" and type in For, it should give For...Next (You can also use the Search feature if your not sure what the function is) Edited November 20, 2006 by Rad Link to comment Share on other sites More sharing options...
Zedna Posted November 20, 2006 Share Posted November 20, 2006 Little optimization:Case Else For $i = 1 To $clientsInfo[0][0] If $msg = $clientsMenu[$i] Then MsgBox(64, "Client Nr. " & $i ,'Name: ' & $clientsInfo[$i][0] & @LF _ & 'Address: ' & $clientsInfo[$i][1]) ExitLoop EndIf Next EndSelectThere was added ExitLoop - when you find it you needn't do rest of FOR .. NEXT Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
tittoproject Posted November 20, 2006 Share Posted November 20, 2006 (edited) Thanks! What you've done is way passed my comprehension...but I like it! Now I just have to dissect it to understand what you've done.Don't worry, we're here to help you, and to learn Maybe, you'll like to be able to add or remove clients in "setting.ini". In this case you're really lucky: actually I'm writing a script really really close to your. My script is a launcher that starts Mozilla's apps using different profiles. It reads/writes from/to "prifiles.ini", the Mozilla's configuration file, that's exactly formatted as your "settings.ini"! Edited November 20, 2006 by tittoproject Link to comment Share on other sites More sharing options...
kpu Posted November 21, 2006 Author Share Posted November 21, 2006 (edited) Thanks everyone, see post below. Edited November 22, 2006 by kpu http://www.kpunderground.com Link to comment Share on other sites More sharing options...
kpu Posted November 21, 2006 Author Share Posted November 21, 2006 Never mind, I figured it out. I think I'm learning something. I changed: $clientNumber = StringTrimLeft($sectionNames[$i], 6) To $clientNumber = $clientNumber + 1 http://www.kpunderground.com Link to comment Share on other sites More sharing options...
tittoproject Posted November 22, 2006 Share Posted November 22, 2006 (edited) kpu, I'm sure to understand what you want to do... What is "refreash.exe"? A script you wrote? I don't like too much how you use the "If...Then" statement. Your code: If FileExists("settings.ini") Then Else MsgBox(16, "Warning!", "Couldn't find settings.ini. File must be placed at " & @ScriptDir) Exit EndIf Edited November 22, 2006 by tittoproject Link to comment Share on other sites More sharing options...
kpu Posted November 22, 2006 Author Share Posted November 22, 2006 Hey Tittoprojectkpu, I'm sure to understand what you want to do...What is "refreash.exe"? A script you wrote?I've updated my code to refresh the list based upon the settings.ini file under the configurations section. (I know, I've been spelling refresh wrong... ) Maybe there is a better way to do this, but I'm closing the app and reopening it. Basically, if this works for the person I'm writing it for, I will most likely go through the code again and clean everything up. Lets just say it's a beta for now. I coded the "IF" statements that way so if I chose to add something to it, I can easily do so. I don't see the performance difference in coded it the way you have shown. However, thank you for your help with the ini file. If I had not gotten that from you, it may have taken me a lot longer or possibly not at all to figure out the best solution. Thanks again for your help! http://www.kpunderground.com Link to comment Share on other sites More sharing options...
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