Jump to content
AndreasNWWWWW

Check if ini files contains checksum and if so do an action

Recommended Posts

AndreasNWWWWW

Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.

for my test i'm looking for 100,200,300,400,500

and if any of those excits i want to pop a msgbox with the number in the section.

i can in my example find one, but it does not check everyone. why? :( what am i missing?

Local $iscore810[5] = [100,200,300,400,500]
Local $iMax800 = 5

While 1
;~     Send("{pause}")
;;func les ini fil

    $var = IniReadSection("Area.ini", "modus")
    If @error Then
        MsgBox(4096, "Error", "Unable to read section.")
    Else
         For $number = 1 To $var[0][0]
If $var[$number][1] == $iscore810[3] Then
      MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5)
EndIf

             

        Next
    EndIf
    exit
WEnd

 

Edited by AndreasNWWWWW
taggs

Share this post


Link to post
Share on other sites
AutoBert
1 hour ago, AndreasNWWWWW said:

what am i missing?

Correct data in inifile. Test changed script:

#include <MsgBoxConstants.au3>
#include <Array.au3>

Local $iscore810[5] = [100, 200, 300, 400, 500]
Local $iMax800 = 5

If Not FileExists("Area2.ini") Then IniWrite("Area2.ini","Modus","Test","400")

;While 1
    $var = IniReadSection("Area2.ini", "modus")
    If @error Then
        MsgBox(4096, "Error", "Unable to read section.")
    Else
        _ArrayDisplay($var)
        For $number = 1 To $var[0][0]
            If $var[$number][1] == $iscore810[3] Then
                MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5)
            EndIf
        Next
    EndIf
    Exit
;WEnd

it's just for demonstration when inifile holds correct data the MsgBox appears.

Share this post


Link to post
Share on other sites
AndreasNWWWWW
;Thanks! helped me alot, but still abit lost.

;in my code i need to check if checksum excits, and if so i need it to rewrite that line in the ini file.

Local $arr[9] = [1218844893, 3651583250,681492513,185647069,2160709610,3972714752,3059395736,4086222246,2699877049]

;this works:
If $var[$number][1] == 1218844893 Then
IniWrite("arenatest.ini","posisjon",$var[$number][0],"500-Paid")
endif


;this does not:

If $var[$number][1] == $arr[9] Then
IniWrite("arenatest.ini","posisjon",$var[$number][0],"500-Paid")
endif

i could just do alot of manual typing those checksums, but harder to change, reason i want it in an array so i can just pull it off the excel file direcly. 

Share this post


Link to post
Share on other sites
AndreasNWWWWW

nvm this post above, when swapping the 9 number in array to 8, it worked :)

why does this number to be one lower?

Share this post


Link to post
Share on other sites
dmob

AFAIK == is used for string comparison. Try a single = 

Share this post


Link to post
Share on other sites
Subz

why does this number to be one lower?

Your array is 0 based, i.e. it counts as 0, 1, 2, 3, 4, 5, 6, 7, 8 not 1, 2, 3, ...9

Also what you could do is something like:

Local $iscore810[5] = [100,200,300,400,500]
Local $iMax800 = 5

For $i = 0 To UBound($iscore810) - 1
    If IniRead("Area.ini", "modus", $iscore810[$i], "") = "" Then ContinueLoop
    MsgBox(4096, "Number found", "Number# " & $iscore810[$i])
Next

 

Share this post


Link to post
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

  • Similar Content

    • argumentum
      By argumentum
      There is a _ArrayToString() but no _ArrayFromString().  ( searched in the forum and google )
      The example is based on the _ArrayToString() help file, to show the reconstruction of the array.
      #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[20] For $i = 0 To 19 $aArray[$i] = $i Next _ArrayDisplay($aArray, "1D Array") MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7)) ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString") Local $aArray[10][10] For $i = 0 To 9 For $j = 0 To 9 $aArray[$i][$j] = $i & "-" & $j Next Next _ArrayDisplay($aArray, "2D Array") MsgBox($MB_SYSTEMMODAL, "Rows 4-7, cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5)) ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString") Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ Local $m, $n, $b, $c = StringSplit($s, $sDelim_Row, 3) $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 Then For $n = 0 To UBound($b) - 1 If $b[$n] == Int($b[$n]) Then $b[$n] = Int($b[$n]) Next Return $b EndIf Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m]) $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString  
      PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies )
      #include <Array.au3>; For _ArrayDisplay() ; if you declare it, it will use it, else, use default ;Global $g_iniFile = @ScriptDir & "\ThisTest.ini" Example() Func Example() Local $n, $aTest, $aArray[3] = ["00", "one", "2"] ; if is not in the INI file, it will save it $aTest = IniGet("Test", $aArray) _ArrayDisplay($aTest, "1st") ; since is saved, it'll recall it $aTest = IniGet("Test") For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1) Next _ArrayDisplay($aTest, "2nd") EndFunc ;==>Example Func IniGet($sKey, $vDefault = Default, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1)) If $s = Chr(1) Then If $vDefault == Default Then Return SetError(1, 0, "") Else IniSet($sKey, $vDefault, $sSection) Return $vDefault EndIf EndIf $v = StringLeft($s, 1) Switch $v Case "i" Return Int(StringTrimLeft($s, 2)) Case "a" Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2)) Case "d" Return Binary(StringTrimLeft($s, 2)) Case Else Return String(StringTrimLeft($s, 2)) EndSwitch EndFunc ;==>IniGet Func IniSet($sKey, $vValue, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" If IsInt($vValue) Then $vValue = "i:" & $vValue ElseIf IsArray($vValue) Then $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2))) ElseIf IsBinary($vValue) Then $vValue = "d:" & $vValue Else $vValue = "s:" & $vValue EndIf $vValue = IniWrite($ini, $sSection, $sKey, $vValue) Return SetError(@error, @extended, $vValue) EndFunc ;==>IniSet Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ Local $m, $n, $b, $c = StringSplit($s, $sDelim_Row, 3) $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 Then For $m = 0 To UBound($b) - 1 If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m]) Next Return $b EndIf Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m]) $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString  
    • XinYoung
      By XinYoung
      Hello all! I hope everyone is enjoying their holiday festivities. 
      I'm working on a script that involves copying a string of text from an Excel workbook and searching for it in a particular website's search tool. If a result is found, it will do something. If not, it will do something else.
      So far, it can successfully execute the search -- and then it shows me the results in an array.
      Screenshot of the successful search:

      The search results in an array:

       
      Here's the code (sorry for all my comments):
      ;~ All the functions this app performs require the external files listed here. So, theyre "included". #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> #include <Excel.au3> #include <DateTimeConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIShellEx.au3> #include <Date.au3> #include <ComboConstants.au3> #include <Misc.au3> #include <WinAPIProc.au3> #include <WinAPISys.au3> #include <WinAPIConstants.au3> #include <Crypt.au3> #include <ColorConstants.au3> #include <guimenu.au3> #include <IE.au3> ;~ Kill all functions and close the app at anytime by pressing F4. HotKeySet("{F4}", "_Exit") ;~ Keep track whether or not a file is selected. When the program first opens, a file is currently not selected. Global $FileChosen = 0 ;~ The app must remember certain strings of text: ;~ 1. Login page Global $urlBBLogin = "website.com" ;~ 2. Credentials Global $bbUsername = "USER" Global $bbPassword = "PW" ;~ 3. Search page Global $urlBBCourseSearch = "website.com/search" ;~ When you launch the app, the UI gets built and is displayed to the user in the center of the screen. the "Function" buttons are disabled until a file is chosen. $MasterUI = GUICreate("Master Re-Creator", 469, 145, -1, -1) $Label1 = GUICtrlCreateLabel("Choose the Excel file", 8, 8, 103, 17) $Select = GUICtrlCreateButton("Select File", 16, 32, 75, 25) $FileName = GUICtrlCreateLabel("[No File Selected]", 104, 40, 88, 17) $Group1 = GUICtrlCreateGroup("Functions", 8, 72, 449, 65) $CheckCourse = GUICtrlCreateButton("Check Courses Exist", 24, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) $DeleteCourse = GUICtrlCreateButton("Delete Courses", 168, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) $CopyCourse = GUICtrlCreateButton("Copy Courses", 312, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) ;~ While the UI is open, it listens for triggers (in this case, button presses). While 1 $UI = GUIGetMsg() Select ;~ If the app is closed, the _Exit() function is performed (same function the F4 hotkey calls). Case $UI = $GUI_EVENT_CLOSE _Exit() ;~ The user has clicked the "Select File" button, the _LocateGetFileName() function is performed. Go there. Case $UI = $Select _LocateGetFileName() ;~ The user has clicked the "Check Courses Exist" button. Case $UI = $CheckCourse _CheckCourses() ;~ Other buttons are not ready EndSelect WEnd ;~ The user clicked the "Select File" button. This function will execute now. Func _LocateGetFileName() ;~ Prepare the app to take note of the details of a file. Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" ;~ Open a File Explorer to allow the user to select a file. Only Excel files are allowed to be chosen. Global $ChosenFileName = FileOpenDialog("Locate File", @DesktopDir, "Excel Files (*.xlsx)|Excel Macro Files (*.xlsm)", BitOR(1, 2), "") If @error Then Return 0 EndIf ;~ When an Excel file is selected, remember of the files location (path), file name, and file extension. $aPathSplit = _PathSplit($ChosenFileName, $sDrive, $sDir, $sFileName, $sExtension) ;~ Show me what file I selected in a Message Box. MsgBox(0, "Selected File", $sFileName) ;~ Display the chosen file name in the UI label (previously [No File Selected]) and make it green. GUICtrlSetData($FileName, "") $FileName = GUICtrlCreateLabel($sFileName, 104, 40) $FileName = GUICtrlSetColor($FileName, 0x32CD32) ;~ A file is now selected. The "Function" buttons are now enabled. Global $FileChosen = 1 GUICtrlSetState($CheckCourse, $GUI_ENABLE) GUICtrlSetState($DeleteCourse, $GUI_ENABLE) GUICtrlSetState($CopyCourse, $GUI_ENABLE) EndFunc ;==>_LocateGetFileName ;~ The user clicked the "Check Courses" button. This function will execute now. Func _CheckCourses() ;~ Disable the "Function" buttons again to prevent multiple processes. GUICtrlSetState($CheckCourse, $GUI_DISABLE) GUICtrlSetState($DeleteCourse, $GUI_DISABLE) GUICtrlSetState($CopyCourse, $GUI_DISABLE) ;~ Open a IE window and navigate to the login page. Global $oIE = _IECreate($urlBBLogin) ;~ Recognize the form on this page (login input boxes). Local $oForm = _IEFormGetObjByName($oIE, "login") Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id") Local $oTextPass = _IEFormElementGetObjByName($oForm, "password") ;~ Enter the Automation user credentials into the form. _IEFormElementSetValue($oTextLogin, $bbUsername) _IEFormElementSetValue($oTextPass, $bbPassword) ;~ Click the Login button. _IEFormSubmit($oForm) ;~ Now that were logged in, navigate to the course search page. _IENavigate($oIE, $urlBBCourseSearch) ;~ Change the search criteria to "Course ID" _bbCourseSearchCategoryChange("Course ID") ;~ Open the selected Excel file Local $oAppl = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oAppl, $ChosenFileName, Default, Default, True) ;~ Copy just whats in cell A1 (for now) _Excel_RangeCopyPaste($oWorkbook.Worksheets(1), "A1") Global $WhatsCopied = ClipGet() ;~ Paste whats copied into the search text box and click submit Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch") Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText") _IEFormElementSetValue($oSearchString, $WhatsCopied) _IEFormSubmit($oForm) ;~ Lets see what we got from the search Local $oBBTable = _IETableGetCollection($oIE, 2) Local $aBBTableData = _IETableWriteToArray($oBBTable) _ArrayDisplay($aBBTableData) EndFunc ;==>_CheckCourses ;~ This function allows changing the search criteria. Func _bbCourseSearchCategoryChange($sCategoryToSearch) Local $aSearchCategory[6] = ["Course ID", "Course Name", "Description", "Instructor", "Data Source Key", "Term"] Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch") Local $oSearchCategory = _IEGetObjByName($oForm, "courseInfoSearchKeyString") _IEAction($oSearchCategory, "focus") _IEFormElementOptionSelect($oSearchCategory, $aSearchCategory[$sCategoryToSearch], 1, "byText") EndFunc ;==>_bbCourseSearchCategoryChange ;~ All exit commands, including F4, calls this function Func _Exit() Exit EndFunc ;==>_Exit  
      My main question is: How do I create an If... Then based on what is found in the search results? I need additional tasks to run if Col 1, Row 2 in the array contains the exact string I searched for. (Am I going about this the right way?)
      My next question (I might make a new thread for): How do I make the whole thing loop, as in, copy the next cell in the Excel sheet and do the whole thing over again until there's no more? I understand that a For/Next loop thingy would be used. I just don't know how. Loops are really confusing to me.
      Thank you all for your guidance and have a happy new year!
    • ShakeelAhmad
      By ShakeelAhmad
      I've to upload different number of photos online in different assignments. There is a problem that all photos cannot be selected at once to upload. I have to choose and upload photos one by one. For this purpose I have made a script to automate whatever I have to do manually for choosing and uploading photos one by one.
      Please see my script below and check the last "MouseClick" command. This command clicks the button to choose and upload next photo. The problem I'm facing is; the last "MouseClick" works 1 step extra when all photos have been selected and uploaded. I mean if 7 photos are to be uploaded, this command opens the box from where next photo is selected and uploaded then it again opens the box and next photo is choosen and so on.... when last photo is selected and uploaded, this button once again opens the box. When all photos are uploaded, it should not click the button to select next photo. Please suggest how can I resolve this issue.
      #include <AutoItConstants.au3> Sleep(200) HotKeySet("{ESC}","Quit") ;Press ESC key to quit Send("{ALT DOWN}") Send("{TAB}") Send("{ALT UP}") Sleep(200) Local $photos = InputBox("Question", "How many photos to upload?", "#", "", _ - 1, -1, 0, 0) ; How many photos to upload Local $selector = 0 While $photos <> $selector MouseClick("Left", 281, 238, 1) ; mouse click on very first photo in the box. if $selector = 0 Then Send("{ENTER}") ; for selecting very first photo from "open" window. Sleep(800) Else sleep(200) Send("{RIGHT " & $selector & "}") ; for selecting 2nd to onward photos from "open" window. sleep(1000) Send("{ENTER}") sleep(1000) EndIf MouseClick("Left", 495, 198, 1) ; for clicking a button to choose next photo to upload $selector = $selector + 1 WEnd Beep(1500, 300) ; beep when all photos uploaded Exit Regards,
       
      Shakeel
    • WoodGrain
      By WoodGrain
      Hi guys,
      I'm learning about GUI's, I'm trying the below code, the idea being if I press the letter "e" while I have the GUI open I want the label color to change to green (I'm using a UDF for label colors). But every time I press "e" on my keyboard I just get a "ding" sound from my speakers and nothing changes with the label.
      I've looked at using something like "While GUIGetMsg() <> $GUI_EVENT_CLOSE" as I've seen it in other code instead of "While 1", but I don't think it's relevant.
      #include <GUIConstantsEx.au3>; for GUI... #include <GUIRichLabel.au3>; UDF for rich text label fonts #include <Misc.au3>; for _IsPressed $myLetter = "e" $hGUI = GUICreate("test", 700, 60) $lbl2 = _GUICtrlRichLabel_Create($hGUI, '<font color="purple">' & $myLetter & '</font>', 10, 10); , 260, 25 GUISetState(@SW_SHOW) Local $hDLL = DllOpen("user32.dll") While 1 if _IsPressed(Hex($myLetter), $hDLL) Then While _IsPressed(Hex($myLetter), $hDLL) Sleep(250) WEnd _GUICtrlRichLabel_SetData($lbl2, '<font color="green">' & $myLetter & '</font>') Sleep(2000) DllClose($hDLL) Exit EndIf Sleep(50) WEnd DllClose($hDLL) I am using an array of letters that I'm wanting to do this for, but as I can't get it to work I've stripped it down to the simplest code I can think of to try and get this working first. Appreciate any help.
      Thanks!
    • nacerbaaziz
      By nacerbaaziz
      hi dears
      am using an ini files as a History
      Sometimes the file size is be larger to 5 MB
      AutoIt does not recognize the full content of the file
      When I did a search to find out why, I discovered that INI files could not be read if they size larger than 64 KB.
      for that I preferred to ask here if is there any way to bypass this obstacle.
      The contents of the file are  as follows
      [filesList]
      c:\...\...\f1.mp3=00:15:20
      c:\...\...\f2.mp3=00:10:20
      c:\...\...\f3.wav=00:59:20
      ....... Etc
      This is the section for reading the file (adapted from my main script)

      case $continue     Local $aArray = IniReadSection($WaitingListFile, StringEncrypt(true, "filesList", $MyPassword))     If Not @error Then Opt("GUICloseOnESC", 1) _GUICtrlListView_DeleteAllItems($scList)         For $i = 1 To $aArray[0][0] $path = path_list(StringEncrypt(false, $aArray[$i][0], $MyPassWord), 1) if FileExists(StringEncrypt(false, $aArray[$i][0], $MyPassWord)) then GUICtrlCreateListViewItem(_GetFileName(FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord))) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord)), $scList) else $path = $path endIf         Next GUISetState(@sw_disable, $hGUI) GUISetState(@sw_show, $hGUI2) GUICtrlSetState($SClist, $GUI_FOCUS) else if $accessibilitymode = 1 then speak(str("listEmpty")) endIf endIf
      Is there any way to solve this problem, please?
      am waiting your answers...
      Greetings to All
×