mr-es335 Posted January 20 Posted January 20 (edited) Good day, I need to perform the following: 1) Have a function [Main] that calls another function [ReadIniData] 2) [ReadIniData] reads an .ini file at [C:\TestMe\Data\params.ini], the contents of which are: [Parameters] InitDir1=C:\TestMe\Backup InitDir2=C:\TestMe\Restore 3) Be able to select either value from [ReadIniData] and return that value to the calling function [Main] • The current contents of [ReadIniData] are: ; ----------------------------------------------- #include <FileConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- ReadIniData() ; ----------------------------------------------- Func ReadIniData() Local $sFilePath = "C:\TestMe\Data\params.ini" Local $aArray = IniReadSection($sFilePath, "Parameters") ; ----------------------------------------------- If Not @error Then For $i = 1 To $aArray[0][0] MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1]) ; Select either $aArray[1][1] or $aArray[2][1] and return that value ; $aArray[1][1] = C:\TestMe\Backup ; $aArray[2][1] = C:\TestMe\Restore Next EndIf Return $sReturnValue EndFunc ;==>ReadIniData ; ----------------------------------------------- 4) Employ the return value from [ReadIniData] in the following: ; ----------------------------------------------- #include <MsgBoxConstants.au3> ; ----------------------------------------------- Main() ; ----------------------------------------------- Func Main() Local $sReturnValue = ReadIniData() ConsoleWrite($sReturnValue & @CRLF) Local $sSelectTxtFile = FileOpenDialog($sMessage1, $sReturnValue, "All Files (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT)) ; ----------------- EndFunc ;==>Main ; ----------------------------------------------- I have been working on this for days with no resolve|solution! Any assistance in this matter would be greatly appreciated! Edited January 20 by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted January 20 Posted January 20 here you say you have two functions but this looks more like you have two scripts which of the two is correct, unless there is a serious reason, you avoid calling a function from another script, because it creates extra work preference instead to have the necessary functions in the same script in the function ReadIniData() you have a parameter $sReturnValue which does not exist, what do you want the function to return? in the function Main() you have a parameter $sMessage1 which does not exist, and what do you expect from $sReturnValue = ReadIniData() the .ini file has two values which of the two? all values in one array? here is a simple version #include <FileConstants.au3> #include <MsgBoxConstants.au3> Main() ; ----------------------------------------------- Func Main() Local $sIniPath = @ScriptDir & "\params.ini" Local $sBackupDir = IniRead($sIniPath, "Parameters", "BackupDir", @DesktopDir) ConsoleWrite($sBackupDir & @CRLF) $sMessage1 = "choose file to Backup" Local $sSelectTxtFile = FileOpenDialog($sMessage1, $sBackupDir, "All Files (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT)) EndFunc ;==>Main ; ----------------------------------------------- #cs params.ini [Parameters] BackupDir=C:\TestMe\Backup RestoreDir=C:\TestMe\Restore #CE I know that I know nothing
argumentum Posted January 20 Posted January 20 I use Func IniReadOrInit($ini, $sec, $key, $def) Local $vRet = IniRead($ini, $sec, $key, @CRLF) If $vRet = @CRLF Then $vRet = $def IniWrite($ini, $sec, $key, $def) EndIf If StringInStr($vRet, ";") Then $vRet = StringStripWS(StringLeft($vRet, StringInStr($vRet, ";") - 1), 3) Return $vRet EndFunc ;==>IniReadOrInit , that way when I first run the code, IniReadOrInit() sets the default value in the ini file and is easier to work with. Int(IniReadOrInit("c:\test\myIni.ini", "section", "key", "1 ; zero = no, one = yes")) IniReadOrInit("c:\test\myIni.ini", "section", "key", "this value ; any value or whatever") ..that way you can leave a comment in the ini file. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ad777 Posted January 22 Posted January 22 (edited) add to your main au3 file:#include "ReadIniData.au3". you need to add #include "ReadIniData.au3" in the same folder. ; ----------------------------------------------- #include <MsgBoxConstants.au3> #include "ReadIniData.au3" ; ----------------------------------------------- Main() ; ----------------------------------------------- Func Main() Local $sReturnValue = ReadIniData() ConsoleWrite($sReturnValue & @CRLF) Local $sSelectTxtFile = FileOpenDialog($sMessage1, $sReturnValue, "All Files (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT)) ; ----------------- EndFunc ;==>Main ; ----------------------------------------------- ReadIniData.au3: ; ----------------------------------------------- #include <FileConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- ReadIniData() ; ----------------------------------------------- Func ReadIniData() Local $sFilePath = "C:\params.ini" Local $aArray = IniReadSection($sFilePath, "Parameters") ; ----------------------------------------------- If Not @error Then For $i = 1 To $aArray[0][0] MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1]) ; Select either $aArray[1][1] or $aArray[2][1] and return that value ; $aArray[1][1] = $sReturnValue ; $aArray[2][1] = C:\TestMe\Restore Next EndIf Return $sReturnValue EndFunc ;==>ReadIniData ; ----------------------------------------------- Edited January 22 by ad777 none
mr-es335 Posted January 22 Author Posted January 22 Hello, Thanks to all whom has responded. I will get back to you when I have absorbed the information!! Appreciated...very much! mr-es335 Sentinel Music Studios
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