Jump to content

Recommended Posts

Hi,

I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.

I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.

What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.

It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.

Here are the relevant part of my script:

The Custom Verification Arrays:

;Creating Arrays for INI Verification
Global $aSettingsVerify[7]
$aSettingsVerify[1] = "Conversion"
$aSettingsVerify[2] = "AIO"
$aSettingsVerify[3] = "Data"
$aSettingsVerify[4] = "Redist"
$aSettingsVerify[5] = "Split"
$aSettingsVerify[6] = "Autorun"
Global $aDataVerify[6]
$aDataVerify[1] = "Compression"
$aDataVerify[2] = "Exclude"
$aDataVerify[3] = "LangExclude"
$aDataVerify[4] = "PreCommands"
$aDataVerify[5] = "PostCommands"

The IniReadSectionNames verification part:

Case $OK
                If StringInStr($ActiveConfig, "Settings.ini") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        GUIDelete($ConfigStart)
                        SettingsGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf
                If StringInStr($ActiveConfig, "Data") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        GUIDelete($ConfigStart)
                        DataGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf

The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)

;Compares Imported INI file with the Verification array
Func _ArrayCompare(ByRef $a1, ByRef $a2)
    Local $nOldSize = UBound($a2)
    Local $a3[$nOldSize], $nNewSize = $nOldSize

    For $i = 0 To UBound($a1) - 1
        For $j = 0 To $nOldSize - 1
            If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then
                $a3[$j] = 1
                $nNewSize -= 1
            EndIf
        Next
    Next

    Local $a4[$nNewSize], $j = 0
    For $i = 0 To $nOldSize - 1
        If Not $a3[$i] Then
            $a4[$j] = $a2[$i]
            $j += 1
        EndIf
    Next

    Return $a4
EndFunc   ;==>_ArrayCompare

 

Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?

Thanks


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites

VollachR,

Run a check of the size of the array returned by IniReadSectionNames - if it is larger than the checking array there are too many entries.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

As Melba23 pointed out you can compare section name count for example:

If UBound($CheckArray1) - 1 <> UBound($aSettingsVerify) - 1 Then ... ;~ Action here

Alternatively you can get an array of incorrect names and also compare the sizes for example:

#include <Array.au3>
Global $aVerify[7]
$aVerify[1] = "Conversion"
$aVerify[2] = "AIO"
$aVerify[3] = "Data"
$aVerify[4] = "Redist"
$aVerify[5] = "Split"
$aVerify[6] = "Autorun"

;~ IniReadSection
Global $aSection[9]
$aSection[1] = "Conversion"
$aSection[2] = "AIO"
$aSection[3] = "Data"
$aSection[4] = "Redist"
$aSection[5] = "Split"
$aSection[6] = "Autorun"
$aSection[7] = "AutoRunning"
$aSection[8] = "Confersion"

Global $aCompare = _SectionCompare($aSection, $aVerify)
_ArrayDisplay($aCompare, "Error Return = " & @error)

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        ConsoleWrite($_aVerification[$i] & @CRLF)
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i])
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    Return SetError($_iError, 0, $_aSections)
EndFunc

 

Share this post


Link to post
Share on other sites
21 minutes ago, Melba23 said:

VollachR,

Run a check of the size of the array returned by IniReadSectionNames - if it is larger than the checking array there are too many entries.

M23

I thought about that but I'm not sure how to modify the existing function to include that check, as I said, I found that function online, don't remember where or who wrote it but I didn't do it myself, all I did was remove the _ArrayDisplay that was near the end of the function.

 

5 minutes ago, Subz said:

As Melba23 pointed out you can compare section name count for example:

If UBound($CheckArray1) - 1 <> UBound($aSettingsVerify) - 1 Then ... ;~ Action here

Alternatively you can get an array of incorrect names and also compare the sizes for example:

#include <Array.au3>
Global $aVerify[7]
$aVerify[1] = "Conversion"
$aVerify[2] = "AIO"
$aVerify[3] = "Data"
$aVerify[4] = "Redist"
$aVerify[5] = "Split"
$aVerify[6] = "Autorun"

;~ IniReadSection
Global $aSection[9]
$aSection[1] = "Conversion"
$aSection[2] = "AIO"
$aSection[3] = "Data"
$aSection[4] = "Redist"
$aSection[5] = "Split"
$aSection[6] = "Autorun"
$aSection[7] = "AutoRunning"
$aSection[8] = "Confersion"

Global $aCompare = _SectionCompare($aSection, $aVerify)
_ArrayDisplay($aCompare, "Error Return = " & @error)

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        ConsoleWrite($_aVerification[$i] & @CRLF)
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i])
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    Return SetError($_iError, 0, $_aSections)
EndFunc

 

I don't see how the 2nd example will work, if somebody modifies the ini file and add a section that shouldn't be there I have no way to guess what section name that person added, so I can't really create an array with incorrect names as that can be anything that isn't in the verification array.

As for the first suggestion, as I said above for Melba23's answer, I'm not sure where or how to add that into the existing _ArrayCompare function, or is there away to add it in the part of the script that calls the function without messing things up?


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites

The $aSection above was an example of an IniReadSection, it should return the differences, here is another example since I didn't  make the first a 2D Array and forgot about comparing the results after the loop.  As I only have partial piece of your script I can't test so will leave it with you.

#include <Array.au3>

Global $aSettingsVerify[7]
    $aSettingsVerify[1] = "Conversion"
    $aSettingsVerify[2] = "AIO"
    $aSettingsVerify[3] = "Data"
    $aSettingsVerify[4] = "Redist"
    $aSettingsVerify[5] = "Split"
    $aSettingsVerify[6] = "Autorun"

Global $aDataVerify[6]
    $aDataVerify[1] = "Compression"
    $aDataVerify[2] = "Exclude"
    $aDataVerify[3] = "LangExclude"
    $aDataVerify[4] = "PreCommands"
    $aDataVerify[5] = "PostCommands"

If StringInStr($ActiveConfig, "Settings.ini") Then
    $CheckArray1 = IniReadSectionNames($ActiveConfig)
    $CheckArray2 = _SectionCompare($CheckArray1, $aSettingsVerify)
    Switch @error
        Case -2, -1, 1
            GUIDelete($ConfigStart)
            SettingsGUI()
    EndSwitch
    _ArrayDisplay($CheckArray2, "Error Return = " & @error)
EndIf
If StringInStr($ActiveConfig, "Data") Then
    $CheckArray1 = IniReadSectionNames($ActiveConfig)
    $CheckArray2 = _SectionCompare($CheckArray1, $aDataVerify)
    Switch @error
        Case -2, -1, 1
            GUIDelete($ConfigStart)
            SettingsGUI()
    EndSwitch
    _ArrayDisplay($CheckArray2, "Error Return = " & @error)
EndIf

; ==================================================================================================
; Func _SectionCompare($_aSections, $_aVerification)
;
; $_aSections       := Section Names Array
; $_aVerifcation    := Verification Array
;
; Returns:
;   Success: "" with @error set to 0
;   Failure: "" if $_aSections is empty or $_vResult Array with differnces, with @error set
;       @error = -2 = $_aSections Array contains incorrect data
;       @error = -1 $_aSections Array Count less than $_aVerification Array Count
;       @error = 1 $_aSections Array Count greater than $_aVerification Array Count
;
; Author: Subz
; ==================================================================================================

Func _SectionCompare($_aSections, $_aVerification)
    Local $_iError, $_iSearch
    If (UBound($_aSections) -1) < (UBound($_aVerification) - 1) Then $_iError = -1 ;~ $_aSections Array Count less than $_aVerification Array Count
    If (UBound($_aSections) -1) = (UBound($_aVerification) - 1) Then $_iError = 0 ;~ $_aSections Array Count equal to $_aVerification Aay Count
    If (UBound($_aSections) -1) > (UBound($_aVerification) - 1) Then $_iError = 1 ;~ $_aSections Array Count greater than $_aVerification Array Count
    ;~ Check items in $_aSections that match an item in $_aVerification
    For $i = UBound($_aVerification) - 1 To 0 Step - 1
        $_iSearch = _ArraySearch($_aSections, $_aVerification[$i], 0, 0, 0, 0, 1, 0)
        If $_iSearch = -1 Then ContinueLoop
        _ArrayDelete($_aSections, $_iSearch)
    Next
    $_iError = UBound($_aSections) -1 = 0 ? 0 : -2
    $_vReturn = UBound($_aSections) = 0 ? "" : $_aSections
    Return SetError($_iError, 0, $_vReturn)
EndFunc

 

Share this post


Link to post
Share on other sites

OK, turned out I didn't need that additional check after all, my existing check was enough once I moved another part of the script from another "Case" into the "Case $OK" portion, it was probably a logic issue.

I accidentally made the script import the in sections (with IniReadSection) to Arrays before performing the check instead of after, which caused my problem, now that I moved it to be done after the check is performed I get the error message at every situation it needs to be without any additional checks.

That's the change I made:

Case $OK
                If StringInStr($ActiveConfig, "Settings.ini") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        Global $aConversion = IniReadSection($ActiveConfig, "Conversion")
                        Global $aAIO = IniReadSection($ActiveConfig, "AIO")
                        Global $aData = IniReadSection($ActiveConfig, "Data")
                        Global $aRedist = IniReadSection($ActiveConfig, "Redist")
                        Global $aSplit = IniReadSection($ActiveConfig, "Split")
                        Global $aAutorun = IniReadSection($ActiveConfig, "Autorun")
                        GUIDelete($ConfigStart)
                        SettingsGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf
                If StringInStr($ActiveConfig, "Data") Then
                    $CheckArray1 = IniReadSectionNames($ActiveConfig)
                    $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1)
                    $CheckArray3 = UBound($CheckArray2, 1)
                    If $CheckArray3 = 1 Then
                        Global $aCompression = IniReadSection($ActiveConfig, "Compression")
                        Global $aExclude = IniReadSection($ActiveConfig, "Exclude")
                        Global $aLangExclude = IniReadSection($ActiveConfig, "LangExclude")
                        Global $aPreCommands = IniReadSection($ActiveConfig, "PreCommands")
                        Global $aPostCommands = IniReadSection($ActiveConfig, "PostCommands")
                        GUIDelete($ConfigStart)
                        DataGUI()
                    EndIf
                    If $CheckArray3 > 1 Then
                        WrongIni()
                    EndIf
                EndIf

Before I had these IniReadSection lines in a previous Case for a ComboBox that let the user select the Ini file to edit before enabling the OK button, now it's in the OK button case after the check if it's correct.

These IniReadSection arrays are used to later fill the edit fields in the GUI, don't know why creating them earlier caused a problem but it works now.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

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

    • By plankton
      Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area.  Here is the example of my code. But it doesnt stop when color is disappeared.
       
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If Not  @Error Then
      While 1
      Sleep(1000)
      Send("{ESC}")
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If @Error Then Exitloop
       
    • By nooneclose
      Good morning, I have been thinking about trying to make my Autoit script run in the background. I found out today that it is impossible due to the UIA and mouseclick functions that I use. However, while reading other posts about running Autoit scripts in the background I saw a reply mentioning how a script like mine might be able to run on a VM while still giving me the ability to work on my Host OS. Can someone confirm this? 
      Here is a link to the thread where I saw VM mentioned. 
      the person who mentioned it was @ViciousXUSMC 
    • By nooneclose
      Good morning, all. I am having a very hard time figuring out why my code "breaks" every second (and every time after) iteration in the loop. 
      I am trying to automate the process of filling out a form for work. I need to find and send data to seven fields and get data from one field. 
      Here are a couple of pictures of the fields I am interacting with. The fields are on the same forum/page. (the green boxed ones)
       


      Here is my code so far. 
       
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist) #include <AD.au3> ;Allows Active Directory functions #include <Array.au3> ;Allows special Array functions #include <Constants.au3> ;Allows constants to be used #include <Date.au3> ;Allows Date and Time functions #include <DateTimeConstants.au3> ;Allows Date and Time constant functions #include "DTC.au3" ;Allows Custom Date and Time functions #include <IE.au3> ;Allows Internet Explorer functions #include <Misc.au3> ;Allows the "is pressed" function to be used #include <MsgBoxConstants.au3> ;Allows Message box function to be used #include <OutlookEX.au3> ;Allows the Outlook functions #include <String.au3> ;Allows special string functions #include <StringConstants.au3> ;Allows String constant functions #include <Timers.au3> ;Allows timer functions ;#RequireAdmin ;Requests admin privliges before starting program ; Special UDFs for UIA automation #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <debug.au3> #include <WinAPI.au3> #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ;******************************************************************************* ; Format and send the vaild E-mail's contents ;******************************************************************************* Func SendEmailData() ConsoleWrite("Action 16: Send E-mail Data to it's proper fields" & " at line: " & @ScriptLineNumber & @CRLF) ;=============================================================================== ; Store the Elements ;=============================================================================== ; Description _UIA_setVar("oDescription","Title:=Description:;controltype:=UIA_EditControlTypeId;class:=") ; Long Description OK Button _UIA_setVar("oLongButton","Title:=Long Description;controltype:=UIA_ImageControlTypeId;class:=") _UIA_setVar("oLongOk","Title:=OK;controltype:=UIA_ButtonControlTypeId;class:=") ; Work Order Number _UIA_setVar("oWorkOrderNum","Title:=Work Order:;controltype:=UIA_EditControlTypeId;class:=") ; Location _UIA_setVar("oLocation","Title:=Location:;controltype:=UIA_EditControlTypeId;class:=") ; Work Type _UIA_setVar("oWorkType","Title:=Work Type:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Date _UIA_setVar("oDate","Title:=Reported Date:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Person _UIA_setVar("oCustomer","Title:=Reported By:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Email _UIA_setVar("oEmail","Title:=Reported By Email:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Phone _UIA_setVar("oPhone","Title:=Reported By Phone:;controltype:=UIA_EditControlTypeId;class:=") Local $WorkType = "CM" ; Send the stored data to the proper field Local $stringSplitter = ", " Local $conCateStrings = $eDescription & $stringSplitter & $eComments Local $ComStringLen = StringLen($eComments) Local $TrimedDesc = StringTrimLeft($eDescription, 1) ;=============================================================================== ; Check to see if the Description and the Long Description can be concatenated If StringLen($conCateStrings) <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $conCateStrings) _UIA_action("oDescription","highlight") ; Wipes the long description so no duplication happens $eComments = "" ;=============================================================================== ; Send the Long Description in place of the Description ElseIf $TrimedDesc = "Other" AND $ComStringLen <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eComments) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Long Description in place of the Description and Send the rest of it to the Long Description field ElseIf $TrimedDesc = "Other" AND $ComStringLen >= 100 Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(500) _UIA_Action("oDescription","setfocus") Sleep(500) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Description and some of the Long Description ElseIf StringLen($eDescription) <= 80 AND $eComments <> "" Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the original Description Else Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) EndIf ;=============================================================================== ; Click the long description button Sleep(2000) _UIA_action("oLongButton","highlight") Sleep(300) _UIA_Action("oLongButton","setfocus") Sleep(300) _UIA_action("oLongButton", "click") _UIA_action("oLongButton", "highlight") _UIA_action("oLongButton", "click") Sleep(2000) ;=============================================================================== ; Send the long description Sleep(1000) if StringLen($eComments) >= 250 Then Sleep(500) Send($eComments) Sleep(10000) ElseIf StringLen($eComments) >= 150 Then Sleep(500) Send($eComments) Sleep(6000) ElseIf StringLen($eComments) <= 10 Then Sleep(500) Send($eComments) Sleep(1500) Else Sleep(500) Send($eComments) Sleep(4000) EndIf ;=============================================================================== ; Click the ok button Sleep(2000) _UIA_action("oLongOk","highlight") Sleep(300) _UIA_Action("oLongOk","setfocus") Sleep(300) _UIA_action("oLongOk", "click") _UIA_action("oLongOk", "highlight") Sleep(2000) ;=============================================================================== ; The work order number _UIA_action("oWorkOrderNum","highlight") Sleep(300) _UIA_Action("oWorkOrderNum","setfocus") Sleep(300) _UIA_action("oWorkOrderNum", "getvalue", $WoNum) _UIA_action("oWorkOrderNum","highlight") ;MsgBox("", "Work order number", $WoNum[2]) ;=============================================================================== ; The Location field Sleep(2000) _UIA_action("oLocation","highlight") Sleep(300) _UIA_Action("oLocation","setfocus") Sleep(300) _UIA_action("oLocation", "setvalue", $eLocation) _UIA_action("oLocation","highlight") ;=============================================================================== ; The Work Type field Sleep(2000) _UIA_action("oWorkType","highlight") Sleep(300) _UIA_Action("oWorkType","setfocus") Sleep(300) _UIA_action("oWorkType", "setvalue", $WorkType) _UIA_action("oWorkType","highlight") ;=============================================================================== ; The Reported By Date Sleep(2000) _UIA_action("oDate","highlight") Sleep(300) _UIA_Action("oDate","setfocus") Sleep(300) _UIA_action("oDate", "setvalue", $eSentOn) _UIA_action("oDate","highlight") ;=============================================================================== ; The Requested by field Sleep(2000) _UIA_action("oCustomer","highlight") Sleep(300) _UIA_Action("oCustomer","setfocus") Sleep(300) _UIA_action("oCustomer", "setvalue", $eReportedBy) _UIA_action("oCustomer","highlight") ;=============================================================================== ; The Requested by E-mail Sleep(2000) _UIA_action("oEmail","highlight") Sleep(300) _UIA_Action("oEmail","setfocus") Sleep(300) _UIA_action("oEmail", "setvalue", $eSenderAddress) _UIA_action("oEmail","highlight") ;=============================================================================== ; The Requested by Phone Sleep(2000) _UIA_action("oPhone","highlight") Sleep(300) _UIA_Action("oPhone","setfocus") Sleep(300) _UIA_action("oPhone", "setvalue", $eRoomPhone) _UIA_action("oPhone","highlight") MouseClick("left", 1843, 437, 2) Sleep(1500) Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Sleep(1000) MouseClick("left", 591, 279, 2) Sleep(3000) $lCount += 1 ConsoleWrite("Action 16: Finished" & " at line: " & @ScriptLineNumber & @CRLF) Sleep(2000) EndFunc  
      That is not all the code but that is the function that keeps "breaking" and by "breaking" I mean the program acts like it doesn't know where the description field is after the first iteration.
      My code will just click somewhere in the far top left corner and somehow shrink the browser in the process of finding the description field.  
       
      The code works perfectly the first iteration but after that, it "breaks" (doesn't know where to click/send data to). 
      As always any help is greatly appreciated. 
       
      NOTE: By the time 'Action 16' runs Chrome has already been opened and has navigated to the proper webpage.  I am trying to loop 'Action 16' multiple times. I do not leave that webpage while looping. 
    • By nooneclose
      Good morning, I am having a hard time figuring out how to read or get the valve (628850) from the red squared box in the picture below. 

      Here is what I have tried so far. (see code below. Also, I'm very sorry my code is sloppy.)
       
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist) #include <AD.au3> ;Allows Active Directory functions #include <Array.au3> ;Allows special Array functions #include <Constants.au3> ;Allows constants to be used #include <Date.au3> ;Allows Date and Time functions #include <DateTimeConstants.au3> ;Allows Date and Time constant functions #include "DTC.au3" ;Allows Custom Date and Time functions #include <IE.au3> ;Allows Internet Explorer functions #include <Misc.au3> ;Allows the "is pressed" function to be used #include <MsgBoxConstants.au3> ;Allows Message box function to be used #include <OutlookEX.au3> ;Allows the Outlook functions #include <String.au3> ;Allows special string functions #include <StringConstants.au3> ;Allows String constant functions #include <Timers.au3> ;Allows timer functions ;#RequireAdmin ;Requests admin privliges before starting program #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <debug.au3> #include <WinAPI.au3> #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ; Sets the script to accept coordinates off the program window and not the screen AutoItSetOption('MouseCoordMode', 0) ; Defines the time it takes to send text to the software/program AutoItSetOption('SendKeyDelay', 10) ;******************************************************************************* ; Close the script if "End" is pressed ;******************************************************************************* Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") HotKeySet("{END}", "Terminate") Func Terminate() MsgBox($MB_ICONINFORMATION, "DEATH", "AI Stoped!", 5) Exit EndFunc ;******************************************************************************* ; Script has started ;******************************************************************************* Sleep(2000) MsgBox($MB_ICONINFORMATION, "WO_AI", "AI Started!", 5) Sleep(1500) ;******************************************************************************* ; Main functions of the program ;******************************************************************************* test() ;=============================================================================== ; Function Definitions ;=============================================================================== Func test() MsgBox("", "TESTing", "Timer Started") Sleep(15000) MsgBox("", "TESTing", "timer Finished") ;~ *** Standard code maintainable *** AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Work Order Tracking - Google Chrome;controltype:=UIA_PaneControlTypeId;class:=Chrome_WidgetWin_1") ;Work Order Tracking - Google Chrome _UIA_setVar("oP2","Title:=Work Order Tracking;controltype:=UIA_DocumentControlTypeId;class:=Chrome_RenderWidgetHostHWND") ;Work Order Tracking _UIA_setVar("oP3","Title:=  Work Order Tracking;controltype:=UIA_CustomControlTypeId;class:=") ;  Work Order Tracking _UIA_setVar("oP4","Title:=main form;controltype:=UIA_GroupControlTypeId;class:=") ;main form _UIA_setVar("oP5","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP6","Title:=View Work Details;controltype:=UIA_CustomControlTypeId;class:=") ;View Work Details _UIA_setVar("oP7","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP8","Title:=Location: Location description Long Description Include Children? Include Children: unchecked Include Ancestors? Include Ancestors: unchecked Include History? Include History: unchecked Work Scope Minimize Work Scope Section Minimize Work Scope Section Work Scope Work Close Filter CTRL+Z Close Filter CTRL+Z Filter Filter Table Filter Table Next Row [CTRL+Down Arrow] Next Row [CTRL+Down Arrow] 1 - 4 of 4 Download Hide Table: Work Hide Table: Work Work Work Table Button Group;controltype:=UIA_CustomControlTypeId;class:=") ;Location: Location description Long Description Include Children? Include Children: unchecked Include Ancestors? Include Ancestors: unchecked Include History? Include History: unchecked Work Scope Minimize Work Scope Section Minimize Work Scope Section Work Scope Work Close Filter CTRL+Z Close Filter CTRL+Z Filter Filter Table Filter Table Next Row [CTRL+Down Arrow] Next Row [CTRL+Down Arrow] 1 - 4 of 4 Download Hide Table: Work Hide Table: Work Work Work Table Button Group _UIA_setVar("oP9","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP10","Title:=Work;controltype:=UIA_TableControlTypeId;class:=") ;Work _UIA_setVar("oP11","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP12","Title:=Record Detail Menu;controltype:=UIA_DataItemControlTypeId;class:=") ;Record Detail Menu ; Clicks on the main record field _UIA_setVar("oUIElement","Title:=Record ;controltype:=UIA_EditControlTypeId;class:=") ;ControlType:=UIA_EditControlTypeId;classname:=") ; Trying to click on / get value from the 3rd from top record field (this is me trying to use the id to access the record box) Local $otest =_UIA_getObjectByFindAll("Record.mainwindow", "id:=ma9038468_tdrow_[C\:1]_txt-tb[R\:3].;ControlType:=UIA_DataItemControlTypeId", $treescope_subtree) ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") ;~_UIA_Action("oP5","highlight") _UIA_Action("oP5","setfocus") ;~_UIA_Action("oP6","highlight") _UIA_Action("oP6","setfocus") ;~_UIA_Action("oP7","highlight") _UIA_Action("oP7","setfocus") ;~_UIA_Action("oP8","highlight") _UIA_Action("oP8","setfocus") ;~_UIA_Action("oP9","highlight") _UIA_Action("oP9","setfocus") ;~_UIA_Action("oP10","highlight") _UIA_Action("oP10","setfocus") ;~_UIA_Action("oP11","highlight") _UIA_Action("oP11","setfocus") ;~_UIA_Action("oP12","highlight") _UIA_Action("oP12","setfocus") _UIA_action("oUIElement","highlight") _UIA_Action("oUIElement","setfocus") _UIA_action("oUIElement","click") Sleep(2500) _UIA_action($otest,"highlight") _UIA_Action($otest,"setfocus") _UIA_action($otest,"click") MsgBox("", "End of program", "death") EndFunc I'm using $otest to try and click on the box, through the id that chrome gives it, with the UIA functions. I am kind of completely new to the UIA UDF but I do find it capable of doing a lot of cool things.   
      as always any help would be greatly appreciated. I know how hard you people hard. Thank you for taking the time to help us. 
    • By Valnurat
      I have this code and I want to control the size of the picture that is being showing on the GUI not matter how big the source of the picture is.
      To draw the picture you just add the x and y position, but I would like a end position too.
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <AD.au3> Global $sUsername = 'shortname' Example() Func Example() _GDIPlus_Startup() ;initialize GDI+ Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0xFFE8FF ;$iBgColor format RRGGBB Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle Local $hBitmap = _GDIPlus_BitmapCreateFromMemory(_ADO_USERIMAGE($sUsername)) ;load binary saved GIF image and convert it to GDI+ bitmap format if Not @error Then Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap) MsgBox(0, $iW, $iH) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 15, 20) ;display image in GUI EndIf Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example Func _ADO_USERIMAGE($sUsename) _AD_Open() Local $oADO_USERIMAGE = _AD_GetObjectAttribute($sUseName, 'thumbnailPhoto') If @error Then Exit _AD_Close() Return $oADO_USERIMAGE EndFunc  
×
×
  • Create New...