FMS

XML search get change settings.

31 posts in this topic

#1 ·  Posted (edited)

Hello ,

I've the following problem and hope somebody can push me in the right direction or have a good example on how to do it.
The problem is :I want to search / select / change /check a XML setting in a XML file.

The example XML file is as following :

<Configuration>
  <Categories>
    <Category Name="default">
      <SubCategories>
        <SubCategory Name="defaultsettings">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="defaultname" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="false" />
            <Setting Name="cmptemp" TypeName="System.String" Value="false" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="" />
          </Settings>
        </SubCategory>
      </SubCategories>
    </Category>
    <Category Name="settings">
      <SubCategories>
        <SubCategory Name="comp1">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="comp1" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="true" />
            <Setting Name="cmptemp" TypeName="System.String" Value="false" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="12" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="" />
          </Settings>
        </SubCategory>
        <SubCategory Name="comp2">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="comp2" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="false" />
            <Setting Name="cmptemp" TypeName="System.String" Value="true" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="9" />
          </Settings>
        </SubCategory>
      </SubCategories>
    </Category>
  </Categories>
</Configuration>

In this XML file I want to :

-search if subcategory whit the name "comp3" exists
-if exist change of setting "cpuspeed" value to false
-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

what i have this far is :

Func xml_test1()
   Dim $return[0]
   Local $file = @ScriptDir & "\test.xml"
   FileOpen($file, $FO_READ)
   _FileReadToArray($file,$return)
   FileClose($file)
         msg("",$return[28])
         msg("",$return[29])
EndFunc
   
func xml_test2()
   Local $file = @ScriptDir & "\test.xml"
   Local $oXML = ObjCreate("Microsoft.XMLDOM")
;~    $oXML.load("D:\___BUILDS___\___SRMT___\test.xml")
   $oXML.load($file)
   
   $oOther= $oXML.SelectSingleNode("//Configuration/Categories/Category/SubCategories/SubCategory/Settings/Setting") ; or //other
   ConsoleWrite("$oOther.text=[" & $oOther.text & "]" & @CRLF)
EndFunc

i know it is not enough what I'm trying to do but I'm realy stuk in what to do next.
I've searched in the XML.udf but could not find in the examples what to do what i want to do.
The things what i found are about <settings>false</settings> writing style of XML and not the way I've the XML.
(or I'm reading it wrong)

Is there somebody who can help me on mine way or has a good example script?

Thanks in advanced
 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

11 hours ago, FMS said:

-search if subcategory whit the name "comp3" exists

$oMatches = $oXML.selectNodes("SubCategory[Name='comp3']")
If $oMatches.Length>0 Then
    ;1 or more matches
Else
    ;no matches
EndIf

 

11 hours ago, FMS said:

-if exist change of setting "cpuspeed" value to false

For $i=0 To $oMatches.Length-1
    $oMatches.Item($i).selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "False"); Using selectSingleNode due to expectation that it only appears once withing the match?
Next

 

11 hours ago, FMS said:

-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

$oMatch = $oXML.selectSingleNode("//Category[@Name='default']//SubCategory[@Name='defaultsettings']")
$oNode = $oMatch.CloneNode( True )
$oNode.SetAttribute("Name", "comp3")
$oNode.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "false")
$oMatch = $oXML.selectSingleNode("//Category[@Name='settings']/SubCategories")
$oMatch.AppendChild( $oNode )

MsgBox(0, "", $oXML.xml); showing the xml after changes

 

Now I'm a bit lazy, so i did not add much error checking... but you can check up on the documentation, should you need it:

DOM Reference

XPath Syntax

IXMLDOMElement Members

 

Let me know if you need further help, or this makes no sense to you :)

Edited by genius257

Share this post


Link to post
Share on other sites

hello,
 

thanks for the example script @genius257.
I think i got it (for a bit i must say)
I fiddeled something around whit it because it was indeed something rocky code :)
(strangly i got a error whish i don't understand - "Variable used without being declared. - > For $i=0 To $oMathes.Length-1")
But this variable was made a sentence before :
 

Local $file = @ScriptDir & "test.xml"
Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load($file)
;-if exist change of setting "cpuspeed" value to false
$oMatches = $oXML.selectNodes("SubCategory[Name='comp3']")
If $oMatches.Length>0 Then
    ConsoleWrite("hit = 1 or more" & @CRLF)
Else
    ConsoleWrite("hit = 0" & @CRLF)
EndIf

;-if exist change of setting "cpuspeed" value to false

For $i=0 To $oMathes.Length-1
    $oMatches.Item($i).selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "False"); Using selectSingleNode due to expectation that it only appears once withing the match?
Next
ConsoleWrite("setting should be changed cpuspeed = False" & @CRLF)
;-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

$oMatch = $oXML.selectSingleNode("//Category[@Name='default']//SubCategory[@Name='defaultsettings']")
$oNode = $oMatch.CloneNode( True )
$oNode.SetAttribute("Name", "comp3")
$oNode.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "false")
$oMatch = $oXML.selectSingleNode("//Category[@Name='settings']/SubCategories")
$oMatch.AppendChild( $oNode )
ConsoleWrite("section comp3 should be present" & @CRLF)
MsgBox(0, "", $oXML.xml); showing the xml after changes

anyway ,
i made 2 functions for it whish i hope u can help me whit.
The first funcion is to change the variable
Here he din't find any but i know it's there, so i fiddled around whit the $LC_hits (nothing found this far:))
if it lays on this i dont know.
 

Func XML_change()
   Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
;~    Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp1']")
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1 " & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='PosId']").SetAttribute("Value","1")
      Next
      ConsoleWrite("value should be changed" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

The second function i made is to search and make
here i get an error " The requested action with this object has failed." -> ""Local $LC_XML_node = $LC_hit.CloneNode( True )"
and possibly also that he cant find even if it exist.

Func XML_search_or_make()
   Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
   Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp3']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
      Local $LC_hit = $LC_XML_obj.SelectSingleNode("//Category[@name='default']//SubCategory[@name='defaultsettings']")
      Local $LC_XML_node = $LC_hit.CloneNode( True )
      $LC_XML_node.SetAttribute["Name","Comp3"]
      $LC_XML_node.selectSingleNode(".//Setting[@name='cpuspeed']".SetAttribute("Value","false")
      $LC_hit = $LC_XML_obj.selectSingleNode("//Category[@name='settings']/Subcategories")
      $LC_hit.AppendChild( $LC_XML_node )
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

Could somebody help whit this?

PS. Are there any includes i need for all this?

Thanks in advanced.

 


 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
5 minutes ago, FMS said:

(strangly i got a error whish i don't understand - "Variable used without being declared. - > For $i=0 To $oMathes.Length-1")

Sorry, that's my mistake :sweating:

I mispelled a variable in my second answer:

$oMathes

should be:

$oMatches

I will edit it in the post above right away :>

 

7 minutes ago, FMS said:

here i get an error " The requested action with this object has failed." -> ""Local $LC_XML_node = $LC_hit.CloneNode( True )"

That's what i was talking about with the error handling i did not do much of. "SelectSingleNode" will return a null object, if no match was found, whereas the selectNodes return a collection you can measure the length of. So the error is the result of you trying to call a function that does not exist in a null object.

 

11 minutes ago, FMS said:

PS. Are there any includes i need for all this?

For my examples? No.

Share this post


Link to post
Share on other sites

 lol I din't find that misspelling :S.
But i must say I'm a little lost in what you say.....
I tried to correct it in the code but dont know how to start.
Could u help me correct the 2 functions?
Or did you mean the code i've written will never work?
 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

20 minutes ago, FMS said:

Could u help me correct the 2 functions?

I'll give it a look :)

Edit:

Could you post the xml, if it's different than the original?

Edited by genius257

Share this post


Link to post
Share on other sites

So I've added some comments explaining some of the errors.

But mostly it's just comes down to the fact that you need to be case specific so something like "Subcategories" would fail, but "SubCategories" would work

Func XML_change()
;~    Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_file = @ScriptDir & "test.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
;~    Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp1']")
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1 " & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='PosId']").SetAttribute("Value","1")
      Next
      ConsoleWrite("value should be changed" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc
Func XML_search_or_make()
;~    Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_file = @ScriptDir & "\test.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
   Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp3']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
      Local $LC_hit = $LC_XML_obj.selectNodes("//Category[@Name='default']//SubCategory[@Name='defaultsettings']");the @Name must be case specific
      If Not ($LC_hit.Length>0) Then Return; Escape the function if no match is found
      Local $LC_XML_node = $LC_hit.Item(0).CloneNode( True )
;~       $LC_XML_node.SetAttribute["Name","Comp3"]; This should be called with parenthesis, not square brackets ^^'
      $LC_XML_node.SetAttribute("Name","Comp3")
;~       $LC_XML_node.selectSingleNode(".//Setting[@name='cpuspeed']".SetAttribute("Value","false"); you are missing a parenthesis
      $LC_XML_node.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value","false")
      $LC_hit = $LC_XML_obj.selectSingleNode("//Category[@Name='settings']/SubCategories"); Subcategories should be SubCategories
      $LC_hit.AppendChild( $LC_XML_node )
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

Sorry if i didn't remove all my garbage lines for debugging, I'm off to bed for now :)

Share this post


Link to post
Share on other sites

Thnx @genius257 I got the making part of the unknown "comp3"

unfortanyl i dont think the searching part in "change" function is working.

or is there something i dint see?

sorry to ask again but could you look again?


as finishing touch god created the dutch

Share this post


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

unfortanyl i dont think the searching part in "change" function is working.

Well

Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")

Should be

Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@Name='default']//SubCategory[@Name='comp1']")

 

I hope you noticed that yourself, and yes i know that's my mistake :)

Second, the xml you posted, I test with does not have anything that would match your query, so it's hard to know if the function succeeds or not.

That's why i said:

On 10/9/2016 at 0:04 AM, genius257 said:

Could you post the xml, if it's different than the original?

 

Share this post


Link to post
Share on other sites

thank you very mush @genius257 , everything is working fine now :)
And no i din't find that typo :S it's mine dyslectia playing around whit me :)

Also I've learned some new things now, many thanks for that.
The final thing I cant work out is tho exaly write it to the XML file :)

I see it now changed in the :

MsgBox(0,"",$LC_XML_obj.xml)

But not in the file itself :S , I think it is a noobisch question but working whit XML is a new thing for me :)
Is there a special function to write it back to the XML itself?

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I'm happy everyting is working :)

18 minutes ago, FMS said:

Is there a special function to write it back to the XML itself?

Yes and no :sweating:

It's not just one function, as you will have to overwrite the entire output in the file.

So something like:

$hFile = FileOpen(@ScriptDir & "\test.xml", 2);$FO_OVERWRITE
FileWrite($hFile, $LC_XML_obj.xml)
FileClose($hFile)

I would suggest looking into the help files and add error checking, if you wish to avoid problems. ^_^

They may end up wasting countless hours on debugging (i have that problem a lot :P)

Edited by genius257

Share this post


Link to post
Share on other sites

:lmao:rofl , no that can't be it.....
Stupid of me i din't think of doing that, i thought it was mush harder than that.
But what do you mean whit error checking on this 3 line of code?
maybe i don't understand it right but do u mean only check on fileopen , fileclose and filewrite?
Or do you mean if in the $LC_XML.obj is changed what i want to change?

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
Just now, FMS said:

But what do you mean whit error checking on this 3 line of code?

FileOpen may fail for various reasons, i imagine FileWrite is also worth checking, just in case. FileClose however don't need any error checking.

It's just a precaution, to avoid data not being saved before you close down the program, thinking everything is dandy ^_^

Share this post


Link to post
Share on other sites

o is that all :)
that's what i always do but thank you for pointing out :)
(even i check on fileclose , why i should't i don't now)
I probaly check everything i do i must say.
But final question i've got on mine mind if you are up for that.
Do i need also to properly dispose of the $LC_XML_obj because it's now loaded in ?
Or because it's locale in the function it's cleaning up itself?

That was mine final question , many thanks for helping me around this subject.
10.000 points for grifindor!


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

12 minutes ago, FMS said:

Do i need also to properly dispose of the $LC_XML_obj because it's now loaded in ?
Or because it's locale in the function it's cleaning up itself?

Well honestly I'm not 100% sure, i believe the local variables gets cleaned up by the garbage collector when the function ends. Personally i just leave it like that, but that question might be worth searching for in the forum, i believe I've seen it discussed.

12 minutes ago, FMS said:

That was mine final question , many thanks for helping me around this subject.
10.000 points for grifindor!

It was fun for me too :)
Haha! Why thank you :lol:

Edited by genius257
1 person likes this

Share this post


Link to post
Share on other sites

humm I'm very sorry to disturb you again @genius257 but when i thought i got it  , a error was lurking around :>
I hope u can help me once more because i realy don't understand why it gives me this error.
When I was making this "Beta" function :

Func XML_change();hidden button 1
   Local $LC_XML_file = @ScriptDir & "\forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@Name='settings']//SubCategory[@Name='comp1']")
;~    MsgBox(0,"",$LC_XML_obj.xml)
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
      Next
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

At first I thought it was the <settings> between <subcategory> and <setting> , but in no case it got me another error then this.
If I'm not mistaking it can't find the attribute value? (but can find //SubCategory[@Name='comp1'])


 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
9 hours ago, FMS said:

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

 

Yeah no match is returned from you query.

I bet if you notice the attribute name is all lower case, you find your answer. :)

hint:

@name

 

Share this post


Link to post
Share on other sites
10 hours ago, FMS said:

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

 

You can not use such long onliner, you should pares it for each method to separate lines and check for errors  after each line.


NEW:     ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2016-11-12
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, The Art of Computer Programming
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

pfff was that it the uppercase N :)
thanks, all works fine (again) @genius257

also thanks for pointing that out @mLipok , but i must say I'm rather new to XML searches and changes.
And realy don't know where you are talking about.
Could u show me what u mean>?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
$step1 = $LC_hits.Item($i)
If @error ....
$step2 = $step1.SelectSingleNode(".//Setting[@name='cmptemp_set']")
If @error ....
$step3 = $step2.SetAttribute("Value","1")
If @error ....

 


NEW:     ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2016-11-12
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, The Art of Computer Programming
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

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

    • CT83
      Is it possible to Use Selenium Commands in AutoIt? (I don't mean the other way round)
      By CT83
      I recently discovered Selenium, and in theory it sounds awesome if there were a way to use my existing autoit project's code, in Selenium. is this possible? if not, is there a way to import my au3s to Selenium project without having to rewrite all of the code.?
    • OldGuyWalking
      Dummy Control Not Triggering
      By OldGuyWalking
      I wanted a quick way to identify screen coordinates and created a simple form.  I also wanted to collect the information. Goal was to move the mouse to different locations, hit a key combination and have the program  collect info for that position and write it to a file.
      I couldn't use a button on the form and HotKeys was not recommended (according to some posts I'd read on here).
      I discovered GUIAccelerators but I'm stuck on what triggers the accelerator key.  I've looked at the help file for GUISetAccelerators which references GUICtrlCreateDummy and used the code from both of those.  I'm not getting any errors and everything seems to run okay except when I press Ctrl + [F3] nothing is captured. 
      This is a work in progress so there's extra code that I haven't cleaned up yet.
      Any help would be appreciated. 
      Bill
      ; Displays the Window Handle, Window Text, Control Handle, and mouse position. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_Res_Comment=Show screen coordinates. #AutoIt3Wrapper_Res_Description=Show screen coordinates. #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> Global $Debug = 0 Dim $sWinTitle Dim $sWinText Dim $sWinHnd Dim $sWinCtrlRef Dim $sWinCtrlText Dim $sWinCtrlHnd Dim $aPos Dim $mPos Dim $sMousePos Dim $sControlPos Dim $iFile Dim $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log" Dim $sReport ; HotKeySet("!{Esc}", "Terminate") ; HotKeySet("!{F3}", "WriteLogFile") #Region ### START Koda GUI section ### Form=F:\AutoIT Apps\Misc Mini Utilities\Coordinates\Coordinates.kxf Global $Coordinates = GUICreate("Coordinates", 340, 225, 1, 750, -1, $WS_EX_TOPMOST) Global $lblXPos = GUICtrlCreateLabel("XPos:", 7, 16, 39, 20, $SS_RIGHT) Global $XPos = GUICtrlCreateLabel("XPos", 95, 16, 36, 20, $SS_RIGHT) Global $lblYPos = GUICtrlCreateLabel("YPos:", 7, 34, 40, 20, $SS_RIGHT) Global $YPos = GUICtrlCreateLabel("YPos", 95, 34, 37, 20, $SS_RIGHT) Global $lblWinTitle = GUICtrlCreateLabel("Window Title:", 7, 61, 84, 20, $SS_RIGHT) Global $WinTitle = GUICtrlCreateLabel("WinTitle", 95, 61, 250, 20) Global $lblHandle = GUICtrlCreateLabel("Handle:", 7, 78, 51, 20, $SS_RIGHT) Global $WinHandle = GUICtrlCreateLabel("Win Handle", 95, 78, 100, 20) Global $lblCtrlID = GUICtrlCreateLabel("Control ID:", 7, 104, 65, 20, $SS_RIGHT) Global $ControlID = GUICtrlCreateLabel("ControlID", 95, 104, 100, 20) Global $lblCtrlText = GUICtrlCreateLabel("Control Text:", 7, 125, 78, 20, $SS_RIGHT) Global $ControlText = GUICtrlCreateLabel("Control Text", 95, 125, 120, 20) Global $lblCtrlPos = GUICtrlCreateLabel("Control Pos:", 7, 144, 76, 20, $SS_RIGHT) Global $ControlPos = GUICtrlCreateLabel("Control Pos", 95, 144, 73, 20) Global $btnExit = GUICtrlCreateButton("Exit", 8, 192, 75, 25) Global $sKey1 = GUICtrlCreateDummy() ; Set GUIAccelerators for the button controlID Ctrl + [F3] Global $aAccelKeys[1][2] = [["^{F3}", $sKey1]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() If $nMsg <> 0 Then ConsoleWrite("GUIGetMsg = " & $nMsg & @CRLF) ConsoleWrite("$sKey1 = " & $sKey1 & @CRLF) EndIf Switch $nMsg Case $GUI_EVENT_CLOSE If $nMsg <> 0 Then ConsoleWrite("Event Close = " & $nMsg & @CRLF) EndIf Exit Case $btnExit If $nMsg <> 0 Then ConsoleWrite("Terminate = " & $nMsg & @CRLF) EndIf Terminate() Case $sKey1 If $nMsg <> 0 Then ConsoleWrite("Report = " & $nMsg & @CRLF) EndIf $iFile = FileOpen($sFileLogName, 1) If $iFile = -1 Then MsgBox(0, "Error", "Unable to Open WinfoFile") EndIf $sWinTitle = WinGetTitle("", "") $sWinText = WinGetText($sWinTitle) $sWinHnd = WinGetHandle($sWinTitle) $sWinCtrlRef = ControlGetFocus($sWinHnd) $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef) $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef) ControlFocus($sWinHnd, "", $sWinCtrlRef) $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef) $mPos = MouseGetPos() If IsString($sWinText) Then GUICtrlSetData($WinTitle, $sWinTitle) Else GUICtrlSetData($WinTitle, "") EndIf If IsHWnd($sWinHnd) Then GUICtrlSetData($WinHandle, $sWinHnd) Else GUICtrlSetData($WinHandle, "") EndIf GUICtrlSetData($ControlID, $sWinCtrlRef) GUICtrlSetData($ControlText, $sWinCtrlText) If IsArray($aPos) Then GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1]) $sControlPos = $aPos[0] & "," & $aPos[1] Else GUICtrlSetData($ControlPos, "") $sControlPos = "" EndIf If IsArray($mPos) Then GUICtrlSetData($XPos, $mPos[0]) GUICtrlSetData($YPos, $mPos[1]) $sMousePos = $mPos[0] & "," & $mPos[1] Else GUICtrlSetData($XPos, "") GUICtrlSetData($YPos, "") $sMousePos = "" EndIf $sReport = $sReport & "Window Title : " & $sWinTitle & @CRLF $sReport = $sReport & "Window Text : " & $sWinText & @CRLF $sReport = $sReport & "Window Handle : " & $sWinHnd & @CRLF $sReport = $sReport & "Control Refer : " & $sWinCtrlRef & @CRLF $sReport = $sReport & "Control Text : " & $sWinCtrlText & @CRLF $sReport = $sReport & "Control Handle : " & $sWinCtrlHnd & @CRLF $sReport = $sReport & "Control Position : " & $sControlPos & @CRLF $sReport = $sReport & "Mouse Position : " & $sMousePos & @CRLF If $Debug = 1 Then ConsoleWrite($sReport & @CRLF) EndIf FileWriteLine($iFile, "=====================================================") FileWriteLine($iFile, $sReport) FileWriteLine($iFile, "=====================================================") FileClose($iFile) If @error = -1 Then MsgBox(0, "Error", "Failed") Else MsgBox(0, "Report", "Report Completed") EndIf EndSwitch $sWinTitle = WinGetTitle("", "") $sWinText = WinGetText($sWinTitle) $sWinHnd = WinGetHandle($sWinTitle) $sWinCtrlRef = ControlGetFocus($sWinHnd) $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef) $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef) ControlFocus($sWinHnd, "", $sWinCtrlRef) $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef) $mPos = MouseGetPos() If IsString($sWinText) Then GUICtrlSetData($WinTitle, $sWinTitle) Else GUICtrlSetData($WinTitle, "") EndIf If IsHWnd($sWinHnd) Then GUICtrlSetData($WinHandle, $sWinHnd) Else GUICtrlSetData($WinHandle, "") EndIf GUICtrlSetData($ControlID, $sWinCtrlRef) GUICtrlSetData($ControlText, $sWinCtrlText) If IsArray($aPos) Then GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1]) $sControlPos = $aPos[0] & "," & $aPos[1] Else GUICtrlSetData($ControlPos, "") $sControlPos = "" EndIf If IsArray($mPos) Then GUICtrlSetData($XPos, $mPos[0]) GUICtrlSetData($YPos, $mPos[1]) $sMousePos = $mPos[0] & "," & $mPos[1] Else GUICtrlSetData($XPos, "") GUICtrlSetData($YPos, "") $sMousePos = "" EndIf ;Sleep(500) WEnd Func WriteLogFile() Local $iFile Local $sFileLogName Local $sReport $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log" $iFile = FileOpen($sFileLogName, 1) If $iFile = -1 Then MsgBox(0, "Error", "Unable to Open WinfoFile") Return -1 EndIf $sReport = $sReport & "Window Title : " & $sWinTitle & @CRLF $sReport = $sReport & "Window Text : " & $sWinText & @CRLF $sReport = $sReport & "Window Handle : " & $sWinHnd & @CRLF $sReport = $sReport & "Control Refer : " & $sWinCtrlRef & @CRLF $sReport = $sReport & "Control Text : " & $sWinCtrlText & @CRLF $sReport = $sReport & "Control Handle : " & $sWinCtrlHnd & @CRLF $sReport = $sReport & "Control Position : " & $aPos[0] & "," & $aPos[1] & @CRLF $sReport = $sReport & "Mouse Position : " & $mPos[0] & "," & $mPos[1] & @CRLF FileWriteLine($iFile, "=====================================================") FileWriteLine($iFile, $sReport) FileWriteLine($iFile, "=====================================================") FileClose($iFile) MsgBox(0, "Report", "Report Completed") Return EndFunc ;==>WriteLogFile ;====================================================================================== ; Function: Terminate Hot Key = Alt+Esc ;====================================================================================== Func Terminate() ; Hot Key = Alt+Esc GUIDelete($Coordinates) Exit 0 EndFunc ;==>Terminate  
    • newcoding
      Generating Unique Combinations From Fixed Data
      By newcoding
      #include <Excel.au3> #include <File.au3> #include <String.au3> #include <Array.au3> Local $sku_array[0] ;13640 Local $name_array[0] ;13640 Local $sku_string Local $name = "Name Here"; hardcoded, iterate through final list Local $name_sku = "E001" ; hardcoded, iterate through final list For $size = 0 to 3 Step 1 For $mg = 0 to 30 Step 1 For $b = 0 to 1 Step 1 For $menthol = 0 to 4 Step 1 For $vg = 0 to 10 Step 1 $sku_string = String($name_sku & $size & $mg & $b & $menthol & $vg) _ArrayAdd($sku_array, $sku_string) _ArrayAdd($name_array, $name) Next Next Next Next Next ;_ArrayDisplay($name_sku_array, "Array Data:") Local $oExcel = _Excel_Open() Local $sWorkbook = @ScriptDir & "\FURLS_TRLM_Product_Listing_Eliquid.xls" Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, Default, Default, True) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $sku_array, "B2:B13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "J2:J13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "A2:A13641") ;A2 or Column 1 - $name_string ;B2 or Column 2 - $sku_string ;J2 or Column 10 - $name_string So I am trying to generate every unique combination using 1 value from each set and then place each generated value into an array and then write to an excel sheet.
      Edit: Functional Code, F#CK THE FDA!
       
      I have the following data sets:
      Size: 10, 30, 50, 100
      MG: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30  (shortened in the above code for time constraints while testing)
      VG: 0,1,2,3,4,5,6,7,8,9,10
      Boost: 0,1
      Menthol: 0,1,2,3,4
    • afallenhope
      AutoitExe not working on Win 10
      By afallenhope
      Hello all! 
      I am having a bit of trouble and was wondering if anyone may have a workaround for my issue. I made a script that would automatically install a piece of software each night on a Windows 7 Box. Now I have been instructed to do the same with a Windows 10 box since the application is now being tested on Windows 10. 
      The way I did the win7 installation was that I made a script and then made an executable that I call with a batch file along with the Installer. So the process is 
      AutoitMainFile calls batch file, batch file opens Installer, and the automatedinstaller.exe  The automatedinstlaller waits 10-20 seconds to make sure the Installer has been fully loaded.
      When I try to do the same both get loaded but the automatedinstallation.exe does not send commands to the installer. The code does work and nothing from the program we are wanting to install has changed as our Windows 7 runs every night no problem. 
       
      Do I need to make a new automatedinstall script for windows 10? 
      Any advice is appreciated 
      Thanks,
      Richard
    • aa2zz6
      Load program from CMD
      By aa2zz6
      I have a .ini file that holds my path for our mapping software. I can't seem to get the CMD function to read the file path. I removed everything but the file path but it doesn't work.
      [ArcGIS Desktop]
      Path=C:\Users\<user name>\AppData\Local\ESRI\Desktop10.1\Launcher.exe
      Local Const $sFilePath = @ScriptDir & "\Mapping\Path\ " & "Path" & ".ini" Local $sFilewrite = IniWrite($sFilePath, "ArcGIS Desktop", "Path=", "C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\Launcher.exe") Start() Func Start() $MyCommand = $sFilewrite Run(@ComSpec & " /c " & $MyCommand, @SystemDir, @SW_HIDE) EndFunc ;==>Start