31290 Posted November 3, 2016 Share Posted November 3, 2016 Hi guys, I'm facing a problem that I can't solve, despite trying hard. I have an .ini file with several sections: [Latitude E5440] URL=http://downloads.dell.com/published/pages/latitude-e5440-laptop.html [Latitude E5450] URL=http://downloads.dell.com/published/pages/latitude-e5450-laptop.html [Latitude E5470] URL=http://downloads.dell.com/published/pages/latitude-e5470-laptop.html [Latitude E7240] URL=http://downloads.dell.com/published/pages/latitude-e7240-ultrabook.html [Latitude E7250] URL=http://downloads.dell.com/published/pages/latitude-e7250-ultrabook.html [Latitude E7270] URL=http://downloads.dell.com/published/pages/latitude-e7270-ultrabook.html Then I collect the computer model name and try to look if it exists in the ini file. But, when performing the search, I only got the index in the array. For example, my computer model is a "Latitude E7240". An "_ArraySearch" gives me "4" as a result and because this is also the fourth place of my search in the ini file. It works well if I move the section anywhere else in the file and always give me the correct position. Question is: How can I convert the index number to the section name so I can tell my script that if it's found in the ini file, the download URL variable will be set to the corresponding key in the ini file. Here's my code so far: Spoiler expandcollapse popup#include <String.au3> #include <Array.au3> #include <Date.au3> #include <InetConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPISys.au3> #include <TrayConstants.au3> #include <ProgressConstants.au3> #include <ScreenCapture.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Date.au3> #include <File.au3> #Include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <ColorConstants.au3> #include <ComboConstants.au3> #include <ListBoxConstants.au3> #include <AD.au3> #Include <EditConstants.au3> #include <WinAPISys.au3> #include <IE.au3> Global $Output, $sLinksBIOS, $sBIOSName, $sIniPath, $aSectionsNames $sInipath = "";to adjust for tests $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $objItem.Name Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" ) Endif $aSectionsNames = IniReadSectionNames ($sInipath) If Not @Error Then Local $iIndex = _ArraySearch ($aSectionsNames, $Output) MsgBox (0, "", $iIndex) Endif Can someone give me an hand on this? Thanks -31290- ~~~ Doom Shall Never Die, Only The Players ~~~ Link to comment Share on other sites More sharing options...
31290 Posted November 3, 2016 Author Share Posted November 3, 2016 Sorry for double posting but I found the solution 5 minutes after having posted this topic... For the record, it was: If Not @Error Then Local $iIndex = _ArraySearch ($aSectionsNames, $Output) MsgBox (0, "", $aSectionsNames[$iIndex]) Endif ~~~ Doom Shall Never Die, Only The Players ~~~ Link to comment Share on other sites More sharing options...
BrewManNH Posted November 3, 2016 Share Posted November 3, 2016 There's no need to do that, if an entry already exists in an INI file, writing it again will just overwrite the entry already there. As long as the information isn't changing, you don't need to worry about whether it's already in there or not. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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