AutoIt Snippets

196 posts in this topic

Posted (edited)

Welcome to the AutoIt Snippets thread

This section is dedicated to small reusable pieces of AutoIt code i.e. Snippets

They can be added to your script to give extra functionality without writing extra code. they are varied and cover many subjects like GUI's, Maths, Networking and many others.

Posted Image Autoit Snippets

Please visit the link above and you will find many examples to help you.

Many thanks for all the work from everybody who contributed to the original Autoit Wrappers thread created by Valuater which gave us the starting point for the Wiki, and those who added their code to it like Valuater, guinness, SmOke_N, GEOSoft, Zedna, Mhz, GaryFrost and many others.

Submitting Code Instructions

We would also like you to have a look through your saved code and if you have examples that would be usefull to others then submit them so they can be added to the wiki for the benefit of all.

After you have submitted one they will remain on the thread for a short while and after it has been added to the Wiki it will be removed from the thread shortly afterwards to keep the submissions current.

Take this example by guinness

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

; Checks To See If The Internet Is Connected

ConsoleWrite("Internet Is Connected" & " = " & _IsInternetConnected() & @CRLF) ; ( Returns "True" Or "False" )

Func _IsInternetConnected()
	Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
	If @error Then
		Return SetError(1, 0, False)
	EndIf
	Return $aReturn[0] = 0
EndFunc ;==>_IsInternetConnected

This is how we would like them submitted so that whoever uses the example can paste it in SciTE and it gives a result [MsgBox / ConsoleWrite Etc] that the user can see and understand.

They don't have to be in a Function like the above example (Although that will be the preferred option), but they must have a way of calling the code so it gives a reproducible result.

A few points to note for submissions:

1: All code to be submitted must be run with this line and have no errors or warnings.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

2: Please use Tidy on your scripts before you submit them

3: Although it is our aim to transfer all posted scripts into the Wiki listings, the final decision to do so is entirely at the discretion of the editorial panel.

Remember this is NOT a UDF thread, Snippets are small functions pieces of code not large ones, if your code has more than 2-3 functions in it, you may be better looking at making a UDF.

Instructions on how to make one are to be found here. UDF Standards

I hope you will make use of this section and add too it to make it better for all who use AutoIt

Many thanks to guinness and Melba23 for their help and advice whilst the section was being made Posted Image

As the Wiki is now open for editing this is the template ive used to add the sections so far In the Snippets Section

This code is for adding to the Wiki only it will not work in AutoIt

=== Your Title Goes Here ===

{{Snippet Header

| AuthorURL=35302-guinness <<<<< Change To Your Name Here ( Copy User Name Link Location to get the entry number e.g. forum/user/35302-guinness)

| AuthorName=guinness <<<<< Change To Your Name Here

}}

<syntaxhighlight lang="autoit">

Your AutoIt Snippet Code goes here between the syntax highlights so it shows like AutoIt would show it.

</syntaxhighlight>

[[#top | ReturnToContents]]

Leave the rest unchanged so they are similar and uniform.

Note:

Can we keep conversation in this thread to a minimum please, as this sections posts are deleted as they are added to the wiki, so if your chatting about a piece of code it will deleted as well.

Better to discuss elsewhere, Thanks.

Enjoy your coding

Edited by Chimaera
JScript and Jon like this

Share this post


Link to post
Share on other sites



Posted (edited)

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

; Dumps a string in three lines as character, hex and decimal. A new output block is started after $iLength characters

_StringDump("1234567890" & @CRLF & "abcdefghij", 5)
Exit

Func _StringDump($sString, $iLength)

    Local $sStringAsc, $sStringDec, $sStringHex, $sChar, $iIndex, $iPos = 1
    For $iIndex = 1 To StringLen($sString)
        $sChar = StringMid($sString, $iIndex, 1)
        If Asc($sChar) >= 32 Then
            $sStringAsc = $sStringAsc & "  " & $sChar & " "
        Else
            $sStringAsc = $sStringAsc & "  . "
        EndIf
        $sStringHex = $sStringHex & " " & Hex(Asc(StringMid($sString, $iIndex, 1)), 2) & " "
        $sStringDec = $sStringDec & StringRight("00" & Asc(StringMid($sString, $iIndex, 1)), 3) & " "
    Next
    While $iPos < StringLen($sString)
        ConsoleWrite(StringStripWS(StringMid($sStringAsc, ($iPos * 4) - 3, $iLength * 4), 2) & @LF)
        ConsoleWrite(StringStripWS(StringMid($sStringHex, ($iPos * 4) - 3, $iLength * 4), 2) & @LF)
        ConsoleWrite(StringStripWS(StringMid($sStringDec, ($iPos * 4) - 3, $iLength * 4), 2) & @LF & @LF)
        $iPos += $iLength
    WEnd

EndFunc   ;==>_StringDump

Edited by water
BrewManNH likes this

Share this post


Link to post
Share on other sites

Posted (edited)

A couple of small tweaks to the function Random()

MsgBox(0, "", _Random(-1)) ; Example

Func _Random($nNum1 = 0, $nNum2 = 0, $iFlag = 0)
    If Not IsNumber($nNum1) Then Return SetError(1, 0, 0) ; Invalid 1st parameter
    Switch @NumParams
        Case 0
            Return Random()
        Case 1
            If $nNum1 < 0 Then Return -Random(-$nNum1)
            Return Random($nNum1)
        Case Else
            If Not IsNumber($nNum1) Or ($iFlag <> 0 And $iFlag <> 1) Then Return SetError(2, 0, 0) ; Invalid 2nd or 3rd parameter
            If $nNum1 = $nNum2 Then Return $nNum1
            If $nNum2 > $nNum1 Then Return Random($nNum1, $nNum2, $iFlag)
            Return Random($nNum2, $nNum1, $iFlag)
    EndSwitch
EndFunc

One parameter returns a value between that number and zero. Two parameters return a random number between the two numbers - the order they appear is irrelevant. Two equal parameters return the actual number. The flag behaves exactly as it does with the native AutoIt function.

Edited by czardas

Share this post


Link to post
Share on other sites

Posted

UDFs to write and/or remove comments from an INI file.

#include-once
#include <File.au3>
#include <array.au3>
;Test function to write comments to an ini file
Global $IniFile = @ScriptDir & "\Test.ini"
FileOpen($IniFile, 2)
IniWrite($IniFile, "Test1", 1, 1)
IniWrite($IniFile, "Test1", 2, 2)
IniWrite($IniFile, "Test1", 3, 3)
IniWrite($IniFile, "Test1", 4, 4)
IniWrite($IniFile, "Test2", 1, 1)
IniWrite($IniFile, "Test2", 2, 2)
IniWrite($IniFile, "Test2", 3, 3)
IniWrite($IniFile, "Test3", 1, 1)
IniWrite($IniFile, "Test3", 2, 2)
IniWrite($IniFile, "Test3", 3, 3)
Global $Test = _IniWriteSectionComment($IniFile, "Test1", "This is a comment that comes before a section name", 1)
$Test = _IniWriteSectionComment($IniFile, "Test2", "This is a comment that comes after a section name", 0)
$Test = _IniWriteSectionComment($IniFile, "Test3", "This is a multi-line comment|that comes after a section name", 0)
$Test = _IniWriteSectionComment($IniFile, "Test4", "This will cause an error by referencing a non-existent section name", 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Test = ' & $Test & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$Test = _IniWriteSectionComment($IniFile, "Test3", "This is a NEW multi-line comment|that comes after a section name", 0)
$Test = _IniWriteSectionComment($IniFile, "Test3", "This is a multi-line comment|that comes before a section name", 1)
;~ $Test = _IniStripComments($IniFile, 0, "Test3", 1) ; This will strip the comments from before the section Test3
; #FUNCTION# ====================================================================================================================
; Name...........: _IniWriteSectionComment
; Description ...: Writes comment(s) to an .ini file
; Syntax.........: _IniWriteSectionComment($IWSC_FileName, $IWSC_SectionName, $IWSC_Comment[, $IWSC_ForeAft = 1])
; Parameters ....: $IWSC_FileName	   - String path of the file to write to.
;				  $IWSC_SectionName    - The section of the ini file to comment.
;				  $IWSC_Comment	    - String that contains the comment for the section name.
;				  $IWSC_ForeAft	    - Optional: Specifies where to put the comment in relation to the section name
;										 default is before the section name.
; Return values .: Success - Returns a 1
;				  Failure - Returns a 0
;				  @Error  - 0 = No error.
;				  |1 = file not found
;				  |2 = Could not read/split file
;				  |3 = Not an .ini file
;				  |4 = Section Name not found
; Author ........: Bob Marotte (BrewManNH)
; Modified.......:
; Remarks .......: $IWSC_ForeAft specifies whether to put the comments before or after the section name, 1 = before/0 = after
;				  To write multiline comments, separate the lines with the "|" (pipe) character, see example below.
; Related .......:
; Link ..........:
; Example .......: $Test = _IniWriteSectionComment($IniFile, "Settings", "Now is the time for all good|men to come to the aid of their country", 1)
; ===============================================================================================================================
Func _IniWriteSectionComment($IWSC_FileName, $IWSC_SectionName, $IWSC_Comment, $IWSC_ForeAft = 1)
 Local $aFileRead
 If FileExists($IWSC_FileName) Then
  Local $IWSC_fHnd = FileOpen($IWSC_FileName, 0)
  If $IWSC_fHnd = -1 Then
   Return SetError(2, 0, 0)
  EndIf
  Local $Return = _FileReadToArray($IWSC_FileName, $aFileRead)
  If $Return = 0 Then
   Return SetError(2, 0, 0)
  EndIf
  Local $aSectionNames = IniReadSectionNames($IWSC_FileName)
  If @error Then
   Return SetError(3, 0, 0)
  EndIf
  If _ArraySearch($aSectionNames, $IWSC_SectionName) < 0 Then
   Return SetError(4, 0, 0)
  EndIf
  Local $aTempArray = StringSplit($IWSC_Comment, "|")
  Local $IWSC_Index = _ArraySearch($aFileRead, "[" & $IWSC_SectionName & "]")
  Local $aHolder[UBound($aFileRead) + UBound($aTempArray) - 1]
  If $IWSC_ForeAft Then
   For $I = 0 To $IWSC_Index - 1
	$aHolder[$I] = $aFileRead[$I]
   Next
   For $I = $IWSC_Index To $aTempArray[0] + $IWSC_Index - 1
	$aHolder[$I] = "; " & $aTempArray[$I - ($IWSC_Index - 1)]
   Next
   For $I = $IWSC_Index To $aFileRead[0]
	$aHolder[$I + $aTempArray[0]] = $aFileRead[$I]
   Next
  Else
   For $I = 0 To $IWSC_Index
	$aHolder[$I] = $aFileRead[$I]
   Next
   For $I = $IWSC_Index + 1 To $aTempArray[0] + $IWSC_Index
	$aHolder[$I] = "; " & $aTempArray[$I - ($IWSC_Index)]
   Next
   For $I = $IWSC_Index + 1 To $aFileRead[0]
	$aHolder[$I + $aTempArray[0]] = $aFileRead[$I]
   Next
  EndIf
  _ArrayDelete($aHolder, 0)
  _FileWriteFromArray($IWSC_FileName, $aHolder)
 Else
  Return SetError(1, 0, 0)
 EndIf
 Return SetError(0, 0, 1)
EndFunc   ;==>_IniWriteSectionComment
; #FUNCTION# ====================================================================================================================
; Name...........: _IniStripComments
; Description ...: Strips comment(s) from an .ini file
; Syntax.........: _IniStripComments($ISC_FileName[, $ISC_All = 1[, $ISC_SectionName=""[, $ISC_ForeAft = 1]]])
; Parameters ....: $ISC_FileName	    - String path of the file to work with
;				  $ISC_All			 - Strip all comments in the ini file (default is yes)
;				  $ISC_SectionName	 - The section of the ini file to strip comments from, can not be left blank.
;				  $ISC_ForeAft		 - Optional: Specifies where to strip the comments in relation to the section name
;										 default is before the section name.
; Return values .: Success - Returns a 1
;				  Failure - Returns a 0
;				  @Error  - 0 = No error.
;				  |1 = file not found
;				  |2 = Could not read/split file
;				  |3 = Not an .ini file
;				  |4 = Section Name not found or not specified
; Author ........: Bob Marotte (BrewManNH)
; Modified.......:
; Remarks .......: $ISC_ForeAft specifies whether to strip the comments before or after the section name, 1 = before/0 = after
;				  If you use the $ISC_All = 1 option, then the other parameters after it are ignored.
; Related .......:
; Link ..........:
; Example .......: $Test = _IniWriteSectionComment($IniFile, "Settings", "Now is the time for all good|men to come to the aid of their country", 1)
; ===============================================================================================================================
Func _IniStripComments($ISC_FileName, $ISC_All = 1, $ISC_SectionName="", $ISC_ForeAft = 1)
 Local $aFileRead
 If FileExists($ISC_FileName) Then
  Local $ISC_fHnd = FileOpen($ISC_FileName, 0)
  If $ISC_fHnd = -1 Then
   Return SetError(2, 0, 0)
  EndIf
  Local $Return = _FileReadToArray($ISC_FileName, $aFileRead)
  If $Return = 0 Then
   Return SetError(2, 0, 0)
  EndIf
  Local $aSectionNames = IniReadSectionNames($ISC_FileName)
  If @error Then
   Return SetError(3, 0, 0)
  EndIf
  If $ISC_All = 1 Then
   For $I = $aFileRead[0] To 1 Step -1
	If StringLeft($aFileRead[$I], 1) = ";" Then
	 _ArrayDelete($aFileRead, $I)
	EndIf
   Next
   _ArrayDelete($aFileRead, 0)
   _FileWriteFromArray($ISC_FileName, $aFileRead)
   Return 1
  EndIf
  If _ArraySearch($aSectionNames, $ISC_SectionName) < 0 Or $ISC_SectionName = "" Then
   Return SetError(4, 0, 0)
  EndIf
  Local $aSectionNames = IniReadSectionNames($ISC_FileName)
  If @error Then
   Return SetError(3, 0, 0)
  EndIf
  If _ArraySearch($aSectionNames, $ISC_SectionName) < 0 Then
   Return SetError(4, 0, 0)
  EndIf
  Local $ISC_Index = _ArraySearch($aFileRead, "[" & $ISC_SectionName & "]")
  Local $aHolder[$aFileRead[0] + 1]
  If $ISC_ForeAft Then
   For $I = 0 To $ISC_Index - 1
	$aHolder[$I] = $aFileRead[$I]
   Next
   For $I = $ISC_Index - 1 To 0 Step -1
	If StringLeft($aHolder[$I], 1) = ";" Then
	 _ArrayDelete($aHolder, $I)
	 _ArrayDelete($aFileRead, $I)
	 $aFileRead[0] = $aFileRead[0] - 1
	 $ISC_Index -= 1
	Else
	 ExitLoop
	EndIf
   Next
   For $I = $ISC_Index To $aFileRead[0]
	$aHolder[$I] = $aFileRead[$I]
   Next
  Else
   Local $tmpIndex = $ISC_Index
   For $I = 0 To $ISC_Index
	$aHolder[$I] = $aFileRead[$I]
   Next
   For $I = $ISC_Index + 1 To $aFileRead[0]
	If StringLeft($aFileRead[$I], 1) = ";" Then
	 $ISC_Index += 1
	Else
	 ExitLoop
	EndIf
   Next
   For $I = $ISC_Index + 1 To $aFileRead[0]
	$aHolder[$I] = $aFileRead[$I]
   Next
   For $I = $aFileRead[0] To $tmpIndex Step -1
	If $aHolder[$I] = "" Then
	 _ArrayDelete($aHolder, $I)
	EndIf
   Next
  EndIf
  _ArrayDelete($aHolder, 0)
  _FileWriteFromArray($ISC_FileName, $aHolder)
 Else
  Return SetError(1, 0, 0)
 EndIf
 Return SetError(0, 0, 1)
EndFunc   ;==>_IniStripComment

This script will create an INI file and then insert comments into it. There is a commented out line that will also demonstrate the removal of comments from an INI file. The headers for both function should tell you all you need to know in how to use it. Everything after the last #include line and the first comment line, for the first function, are only needed as a demo of how it works and should be removed if you're going to use this.

header127 likes this

Share this post


Link to post
Share on other sites

Posted

Those who post vague questions are not only wasting their own time but also the time of those replying. So please provide the following to help those who help you.

#include <Misc.au3>

; Version: 1.00. AutoIt: V3.3.8.1
; Retrieve the recommended information of the current system when posting a support question.
Local $sSystemInfo = 'I have a valid AutoIt support question and kindly provide the details of my system:' & @CRLF & @CRLF & _
		'AutoIt Version: V' & @AutoItVersion & ' [' & _Iif(@AutoItX64, 'X64', 'X32') & ']' & @CRLF & _
		'Windows Version: ' & @OSVersion & ' [' & @OSArch & ']' & @CRLF & _
		'Language: ' & @OSLang & @CRLF & @CRLF & _
		'The following information has been copied to the clipboard. Use Ctrl + V to retrieve the following information.'
MsgBox(4096, 'System Info', $sSystemInfo)
ClipPut($sSystemInfo)
BrewManNH likes this

Share this post


Link to post
Share on other sites

Posted

A minor modification of the above snippet, which by the way is excellent. It moves the instructions about CTRL-V to the title of the MsgBox and translates the language code. I borrowed the language code conversion function from the help file. The reason I moved the line about CTRL-V to the title is because that was also being sent to the clipboard when generating the information, now only the relevant info is being sent to it.

#include 

; Version: 1.00. AutoIt: V3.3.8.1
; Retrieve the recommended information of the current system when posting a support question.
Local $sSystemInfo = 'I have a valid AutoIt support question and kindly provided the details of my system:' & @CRLF & @CRLF & _
          'AutoIt Version: V' & @AutoItVersion & ' [' & _Iif(@AutoItX64, 'X64', 'X32') & ']' & @CRLF & _
          'Windows Version: ' & @OSVersion & ' [' & @OSArch & ']' & @CRLF & _
          'Language: ' & _Language() & ' (' & @OSLang & ')' & @CRLF & @CRLF
MsgBox(4096, 'This info has been copied to the clipboard. Use Ctrl + V to retrieve it.', $sSystemInfo)
ClipPut($sSystemInfo)

Func _Language()
     Select
          Case StringInStr("0413 0813", @OSLang)
               Return "Dutch"
          Case StringInStr("0409 0809 0c09 1009 1409 1809 1c09 2009 2409 2809 2c09 3009 3409", @OSLang)
               Return "English"
          Case StringInStr("040c 080c 0c0c 100c 140c 180c", @OSLang)
               Return "French"
          Case StringInStr("0407 0807 0c07 1007 1407", @OSLang)
               Return "German"
          Case StringInStr("0410 0810", @OSLang)
               Return "Italian"
          Case StringInStr("0414 0814", @OSLang)
               Return "Norwegian"
          Case StringInStr("0415", @OSLang)
               Return "Polish"
          Case StringInStr("0416 0816", @OSLang)
               Return "Portuguese"
          Case StringInStr("040a 080a 0c0a 100a 140a 180a 1c0a 200a 240a 280a 2c0a 300a 340a 380a 3c0a 400a 440a 480a 4c0a 500a", @OSLang)
               Return "Spanish"
          Case StringInStr("041d 081d", @OSLang)
               Return "Swedish"
          Case Else
               Return "Other (can't determine with @OSLang directly)"
     EndSelect
EndFunc   ;==>_Language

I hope you don't mind the modifications. :)

Share this post


Link to post
Share on other sites

Posted

I hope you don't mind the modifications. :)

I don't mind at all, I did think about posting something similar using _GetOSLanguage (see signature) but didn't bother.

Thanks for the comments, I just realised today those that post generally lack the basic information required to help them.

#include <Misc.au3>

; Version: 1.00. AutoIt: V3.3.8.1
; Retrieve the recommended information of the current system when posting a support question.
Local $sSystemInfo = 'I have a valid AutoIt support question and kindly provide the details of my system:' & @CRLF & @CRLF & _
		'AutoIt Version: V' & @AutoItVersion & ' [' & _Iif(@AutoItX64, 'X64', 'X32') & ']' & @CRLF & _
		'Windows Version: ' & @OSVersion & ' [' & _GetOSLanguage() & ']' & @CRLF & _
		'Language: ' & @OSLang & @CRLF & @CRLF
MsgBox(4096, 'This info has been copied to the clipboard. Use Ctrl + V to retrieve it.', $sSystemInfo)
ClipPut($sSystemInfo)

; #FUNCTION# ====================================================================================================================
; Name ..........: _GetOSLanguage
; Description ...: Retrieves the language of the OS, this supports 19 of the most popular languages.
; Syntax ........: _GetOSLanguage()
; Parameters ....: None
; Return values .: None
; Author ........: guinness
; Link ..........: http://www.autoitscript.com/forum/topic/131832-getoslanguage-retrieve-the-language-of-the-os/
; Example .......: No
; ===============================================================================================================================
Func _GetOSLanguage()
	Local $aString[20] = [19, "0409 0809 0c09 1009 1409 1809 1c09 2009 2409 2809 2c09 3009 3409", "0404 0804 0c04 1004 0406", "0406", "0413 0813", "0425", _
			"040b", "040c 080c 0c0c 100c 140c 180c", "0407 0807 0c07 1007 1407", "040e", "0410 0810", _
			"0411", "0414 0814", "0415", "0416 0816", "0418", _
			"0419", "081a 0c1a", "040a 080a 0c0a 100a 140a 180a 1c0a 200a 240a 280a 2c0a 300a 340a 380a 3c0a 400a 440a 480a 4c0a 500a", "041d 081d"]

	Local $aLanguage[20] = [19, "English", "Chinese", "Danish", "Dutch", "Estonian", "Finnish", "French", "German", "Hungarian", "Italian", _
			"Japanese", "Norwegian", "Polish", "Portuguese", "Romanian", "Russian", "Serbian", "Spanish", "Swedish"]
	For $i = 1 To $aString[0]
		If StringInStr($aString[$i], @OSLang) Then
			Return $aLanguage[$i]
		EndIf
	Next
	Return $aLanguage[1]
EndFunc   ;==>_GetOSLanguage
mLipok likes this

Share this post


Link to post
Share on other sites

Posted (edited)

:D My contribution :D

#include <Array.au3>
Local $aArray = _StringEqualSplit('abcdefghijklmnopqrstuvwxyz', 5)
_ArrayDisplay($aArray)
$aArray = _StringEqualSplit(1234567890, 5)
_ArrayDisplay($aArray)

; By czardas & modified by guinness >> [url="http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149"]http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149[/url]
; Version: 1.00. AutoIt: V3.3.8.1
; Splits a string into an equal number of characters. The 0th index returns the number of items.
Func _StringEqualSplit($sString, $iNumChars)
	 Local $aArray = StringRegExp($sString, '(?s).{1,' & $iNumChars & '}', 3)
	 Local $aArray1[UBound($aArray) + 1]
	 For $I = 1 To UBound($aArray)
		 $aArray1[$I] = $aArray[$I - 1]
	 Next
	 $aArray1[0] = UBound($aArray) 
	 Return SetError(@error, 0, $aArray1)
EndFunc ;==>_StringEqualSplit

EDIT: Typo in the script.

Edited by BrewManNH

Share this post


Link to post
Share on other sites

Posted (edited)

:D My contribution :D

#include <Array.au3>
Local $aArray = _StringEqualSplit('abcdefghijklmnopqrstuvwxyz', 5)
_ArrayDisplay($aArray)
$aArray = _StringEqualSplit(1234567890, 5)
_ArrayDisplay($aArray)

; By czardas & modified by guinness >> [url="http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149"]http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149[/url]
; Version: 1.00. AutoIt: V3.3.8.1
; Splits a string into an equal number of characters. The 0th index returns the number of items.
Func _StringEqualSplit($sString, $iNumChars)
     Local $aArray = StringRegExp($sString, '(?s).{1,' & $iNumChars & '}', 3)
     Local $aArray1[UBound($aArray) + 1]
     For $I = 1 To UBound($aArray)
          $aArray1[$I] = $aArray[$I - 1]
     Next
     $aArray1[0] = UBound($aArray) - 1
     Return SetError(@error, 0, $aArray1)
EndFunc   ;==>_StringEqualSplit

And this too...

#include <Array.au3>

Local $aArray = _StringEqualSplitEx('abcdefghijklmnopqrstuvwxyz', 5)
_ArrayDisplay($aArray)

$aArray = _StringEqualSplitEx(1234567890, 5)
_ArrayDisplay($aArray)

; By czardas & modified by guinness >> [url="http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149"]http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__st__20#entry992149[/url]
; Version: 1.00. AutoIt: V3.3.8.1
; Splits a string into an equal number of characters. The 0th index returns the number of items.
Func _StringEqualSplitEx($sString, $iNumChars)
     Local $aArray = StringRegExp(String($sString), '(?s).{1,' & $iNumChars & '}', 3)
     Local $aReturn[UBound($aArray) + 1] = [UBound($aArray)]
     For $i = 1 To $aReturn[0]
          $aReturn[$i] = $aArray[$i - 1]
     Next
     Return SetError(@error, 0, $aReturn)
EndFunc   ;==>_StringEqualSplitEx
Would be interested to see the differences in time. Edited by guinness

Share this post


Link to post
Share on other sites

Posted

; WARNING: This will erase the contents of the drive.
; Version: 1.00. AutoIt: V3.3.8.1
; Format a drive.
Func _FormatDrive($sDrive, $sLabel = '', $iIsNTFS = 1, $iQuickFormat = 0)
	Local $aFileSystem[2] = ['FAT', 'NTFS'], $sQuickFormat = ''
	If $iQuickFormat Then
		$sQuickFormat = ' /Q'
	EndIf
	If StringStripWS($sLabel, 8) <> '' Then
		$sLabel = ' /V:' & StringStripWS($sLabel, 3)
	Else
		$sLabel = ''
	EndIf
	Return RunWait(@ComSpec & ' /c format ' & StringLeft($sDrive, 1) & ' /FS:' & $aFileSystem[$iIsNTFS] & $sLabel & $sQuickFormat & ' /X /Y', @SystemDir, @SW_HIDE)
EndFunc   ;==>_FormatDrive

Share this post


Link to post
Share on other sites

Posted

#include <Date.au3>

ConsoleWrite(_IsDateOrAbove(@YEAR & @MON & '29') & @CRLF) ; Returns false if the date is less than the 29th of the month.
ConsoleWrite(_IsDateOrAbove(@YEAR & @MON & '3') & @CRLF) ; Returns true if the date is greater than the 3rd of the month.

; Version: 1.00. AutoIt: V3.3.8.1
; Check if a date is equal to/or has passed the current date. Pass the string YYYYMMDD e.g. 20121225.
Func _IsDateOrAbove($sDateString)
	Local $aArray = StringRegExp($sDateString, '(d{4})(d{2})(d{2})', 3)
	If @error = 0 Then
		$sDateString = $aArray[0] & '/' & $aArray[1] & '/' & $aArray[2]
	EndIf
	Return (_DateDiff('D', $sDateString, @YEAR & '/' & @MON & '/' & @MDAY) >= 0)
EndFunc   ;==>_IsDateOrAbove

Share this post


Link to post
Share on other sites

Posted (edited)

#include <GDIPlus.au3>

_ConvertImage(@ScriptDir & '\Example.jpg', 4) ; Pass an integer as the file format you would like to convert to.
_ConvertImage(@ScriptDir & '\Example.jpg', '4') ; Pass an integer string as the file format you would like to convert to.
_ConvertImage(@ScriptDir & '\Example.jpg', 'PNG') ; Pass a valid CLSID as the file format you would like to convert to.

; Version: 1.01. AutoIt: V3.3.8.1
; Convert an image to a different file format.
Func _ConvertImage($sFilePath, $vFileType = 1)
	Local $aFileType[6][2] = [[5, 2], _
			['BMP', 'bmp;dib;rle'],['GIF', 'gif'],['JPEG', 'jpg;jpeg;jpe;jfif'],['PNG', 'png'],['TIFF', 'tif;tiff']]
	If FileExists($sFilePath) = 0 Then
		Return SetError(1, 0, 0)
	EndIf
	If IsInt($vFileType) = 0 And StringIsInt($vFileType) = 0 Then
		For $i = 1 To $aFileType[0][0]
			If $aFileType[$i][0] = $vFileType Then
				$vFileType = $i
				ExitLoop
			EndIf
		Next
	Else
		$vFileType = Int($vFileType)
	EndIf
	If IsInt($vFileType) = 0 Or $vFileType < 1 Or $vFileType > $aFileType[0][0] Then
		Return SetError(2, 0, 0)
	EndIf
	If Not _GDIPlus_Startup() Then
		Return SetError(@error, @extended, 0)
	EndIf
	Local $iExtension = StringInStr($sFilePath, '.', 2, -1), $sFileString = StringLeft($sFilePath, $iExtension - 1)
	If StringInStr($aFileType[$vFileType][1], StringMid($sFilePath, $iExtension + 1), 2) = 0 Then
		Local $hImage = _GDIPlus_ImageLoadFromFile($sFilePath)
		Local $sCLSID = _GDIPlus_EncodersGetCLSID($aFileType[$vFileType][0])
		_GDIPlus_ImageSaveToFileEx($hImage, $sFileString & '.' & StringMid($aFileType[$vFileType][1], 1, StringInStr($aFileType[$vFileType][1], ';', 2) - 1), $sCLSID)
		_GDIPlus_ImageDispose($hImage)
	EndIf
	_GDIPlus_Shutdown()
EndFunc   ;==>_ConvertImage

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

ConsoleWrite(_NameCount('Example') & @CRLF) ; Returns 76 as e = 5, x = 24, a = 1, m = 13, p = 16, l = 12 and e = 5.
ConsoleWrite(_NameCount('A') & @CRLF) ; Returns 1 as 'A' or 'a' is the 1st letter of the alphabet.
ConsoleWrite(_NameCount('Qwerty') & @CRLF) ; Returns 108.

; Version: 1.00. AutoIt: V3.3.8.1
; Find the value of a string where a = 1, b = 2, c = 3 etc.
Func _NameCount($sData)
	$sData = StringStripWS(StringLower($sData), 8)
	Local $aStringSplit = StringSplit($sData, ''), $iReturn = 0
	For $i = 1 To $aStringSplit[0]
		For $j = 97 To 122
			If $aStringSplit[$i] == Chr($j) Then
				$iReturn += ($j - 96)
				ExitLoop
			EndIf
		Next
	Next
	Return $iReturn
EndFunc   ;==>_NameCount

Share this post


Link to post
Share on other sites

Posted

ConsoleWrite(_StripQuotes('"' & @ScriptDir & '"') & @CRLF)
ConsoleWrite(_StripQuotes("'" & @ScriptFullPath & "'") & @CRLF)
ConsoleWrite(_StripQuotes(@ScriptDir) & @CRLF)

; Version: 1.00. AutoIt: V3.3.8.1
; Strip quotation marks from a filepath.
Func _StripQuotes($sFilePath)
	Return StringRegExpReplace($sFilePath, '^("|'')*([^"'']+)("|'')*$', '2')
EndFunc   ;==>_StripQuotes

Share this post


Link to post
Share on other sites

Posted

ConsoleWrite(_GetExchangeRate('1', 'GBP', 'EUR') & @CRLF) ; Returns the same value in Euros.
ConsoleWrite(_GetExchangeRate('1', 'EUR', 'GBP') & @CRLF) ; Returns the same value in British pounds.

; Version: 1.00. AutoIt: V3.3.8.1
; Convert from one currency to the other using Google's Calculator API.
Func _GetExchangeRate($iAmount, $sFromExchange, $sToExchange)
	Local $sData = BinaryToString(InetRead('http://www.google.com/ig/calculator?hl=en&q=' & $iAmount & $sFromExchange & '=?' & $sToExchange))
	Local $aArray = StringRegExp($sData, 'rhs:s"(d+(?:.d*)?s+[w.s]*)', 3)
	If @error Then
		Return SetError(1, 0, '')
	EndIf
	Return StringStripWS($aArray[0], 3)
EndFunc   ;==>_GetExchangeRate

Share this post


Link to post
Share on other sites

Posted (edited)

#include <Array.au3>

Local $aCodes = _GetExhangeRateCodes()
_ArrayDisplay($aCodes)

; Version: 1.00. AutoIt: V3.3.8.1
; Display an array of exhange rate codes.
Func _GetExhangeRateCodes()
	Local $aArray[95] = [94, _
			'AED', 'ANG', 'ARS', 'AUD', 'BDT', 'BGN', 'BHD', 'BND', 'BOB', 'BRL', _
			'BWP', 'CAD', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CZK', 'DKK', 'DOP', _
			'DZD', 'EEK', 'EGP', 'EUR', 'FJD', 'GBP', 'HKD', 'HNL', 'HRK', 'HUF', _
			'IDR', 'ILS', 'INR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KRW', 'KWD', _
			'KYD', 'KZT', 'LBP', 'LKR', 'LTL', 'LVL', 'MAD', 'MDL', 'MKD', 'MUR', _
			'MVR', 'MXN', 'MYR', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', _
			'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', _
			'SAR', 'SCR', 'SEK', 'SGD', 'SKK', 'SLL', 'SVC', 'THB', 'TND', 'TRY', _
			'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VEF', 'VND', _
			'XOF', 'YER', 'ZAR', 'ZMK']
	Return $aArray
EndFunc   ;==>_GetExhangeRateCodes

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

#NoTrayIcon ; So no icon is displayed in the trayicon menu.
#include <GUIConstants.au3>

Example()

Func Example()
	Local $hGUI = _GUICreateNoTaskBar('Example of a GUI with no TaskBar icon/button', 500, 500, -1, -1)
	Local $iClose = GUICtrlCreateButton('Close', 410, 470, 85, 25)
	GUISetState(@SW_SHOW, $hGUI)

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE, $iClose
				ExitLoop
		EndSwitch
	WEnd
	GUIDelete($hGUI)
EndFunc   ;==>Example

; Version: 1.00. AutoIt: V3.3.8.1
; Create a GUI without a taskbar icon/button, this uses AutoIt's internal hidden window as the parent GUI.
Func _GUICreateNoTaskBar($sTitle, $iWidth, $iHeight = Default, $iLeft = Default, $iTop = Default, $bStyle = Default, $bStyleEx = Default)
	Return GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $bStyle, $bStyleEx, WinGetHandle(AutoItWinGetTitle()))
EndFunc   ;==>_GUICreateNoTaskBar

Share this post


Link to post
Share on other sites

Posted (edited)

#include <StringConstants.au3>

Local $sTinyURL = _GetTinyURLFromURL('http://www.google.com/') ; Retrieve the TinyURL of google.com.
ConsoleWrite('TinyURL: ' & $sTinyURL & @CRLF) ; Display the TinyURL.
ConsoleWrite('LongURL: ' & _GetURLFromTinyURL($sTinyURL) & @CRLF) ; Retrieve the 'LongURL' of the TinyURL. This should be the same URL from before.

; Version: 1.00. AutoIt: V3.3.10.2
; Rerieve the TinyURL of a 'LongURL.' Please read the 'terms of usage' on TinyURL's site http://tinyurl.com/#terms.
Func _GetTinyURLFromURL($sURL)
	Return StringStripWS(BinaryToString(InetRead('http://tinyurl.com/api-create.php?url=' & $sURL)), $STR_STRIPALL)
EndFunc   ;==>_GetTinyURLFromURL

; Version: 1.00. AutoIt: V3.3.10.2
; Rerieve the 'LongURL' from a TinyURL. Please read the 'terms of usage' on TinyURL's site http://tinyurl.com/#terms.
Func _GetURLFromTinyURL($sURL)
	Local $sRead = BinaryToString(InetRead('http://preview.tinyurl.com/' & StringRegExpReplace($sURL, '^\V*\/', '')))
	Return StringStripWS(StringRegExp($sRead & @CRLF & _
			'id="redirecturl" href=" "', '(?:id="redirecturl"\s*href="(.*?)")', $STR_REGEXPARRAYGLOBALMATCH)[0], $STR_STRIPALL)
EndFunc   ;==>_GetURLFromTinyURL

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

#include <File.au3> ; For demonstration purposes only.
#include <WinAPIEx.au3>

Example()

Func Example() ; To demonstrate there is very little difference in terms of execution time.
	Local $hTimer = TimerInit()
	For $i = 1 To 5000
		_TempFile()
	Next
	ConsoleWrite(TimerDiff($hTimer) / 5000 & @CRLF)

	$hTimer = TimerInit()
	For $i = 1 To 5000
		_TempFileEx(Default, Default, 'tmp')
	Next
	ConsoleWrite(TimerDiff($hTimer) / 5000 & @CRLF)

	ConsoleWrite('Example Output: ' & _TempFileEx(@TempDir & '', Default, 'temp.file') & @CRLF) ; The $sFileExtension doesn't have to have the dot (.) at the start of the file extension.
	ConsoleWrite('Example Output: ' & _TempFileEx(@TempDir & '', ';', '.....prefix') & @CRLF) ; The $sFileExtension doesn't have to have the dot (.) at the start of the file extension, but in this example there are many!
EndFunc   ;==>Example

; Version: 1.00. AutoIt: V3.3.8.1
; A different approach to creating a temporary file. See the documentation for _TempFile.
Func _TempFileEx($sDirectoryName = @TempDir, $sFilePrefix = '~', $sFileExtension = '.tmp')
	If $sDirectoryName = Default Or FileExists($sDirectoryName) = 0 Then
		$sDirectoryName = @TempDir
	EndIf
	If FileExists($sDirectoryName) = 0 Then
		$sDirectoryName = @ScriptDir
	EndIf
	If $sFileExtension = Default Then
		$sFileExtension = '.tmp'
	EndIf
	If $sFilePrefix = Default Then
		$sFilePrefix = '~'
	EndIf
	$sDirectoryName = StringRegExpReplace($sDirectoryName, '+$', '') ; Remove the backslash from the file path - Or _WinAPI_PathRemoveBackslash in WinAPIEx.
	$sFileExtension = '.' & StringRegExpReplace($sFileExtension, '^.+', '') ; Remove the initial dot (.) from the file extension.
	$sFilePrefix = StringRegExpReplace($sFilePrefix, '[/:*?"<>|]', '') ; Remove any non-supported characters in the file prefix.
	Local $sReturn = ''
	Do
		$sReturn = FileGetShortName($sDirectoryName & '' & $sFilePrefix & StringRegExpReplace(_WinAPI_CreateGUID(), 'V*(w{12})}', '1') & $sFileExtension)
	Until FileExists($sReturn) = 0
	Return $sReturn
EndFunc   ;==>_TempFileEx

Share this post


Link to post
Share on other sites

Posted (edited)

Here's one for simply create a unique tmp file

MsgBox(0, 0, _CreateUniqueTmpFile())

; Create a unique tmp file, optional path and prefix
Func _CreateUniqueTmpFile($sPath = @TempDir, $sPreFix = '999')
	Local Const $ERROR_PATH_LENGTH = 6

	If StringLen($sPath) > 256 - 14 Then ;MAX_PATH - 14
		Return SetError($ERROR_PATH_LENGTH)
	EndIf

	Local $Struct = DllStructCreate("char[256]") ; MAX_PATH
	Local $StructPointer = DllStructGetPtr($Struct)

	Local $aRtn = DllCall("Kernel32.dll", 'uint', 'GetTempFileName', 'str', $sPath, 'str', $sPreFix, 'uint', 0, 'ptr', $StructPointer)
	If @error Then
		Return SetError(@error)
	EndIf

	Return DllStructGetData($Struct, 1)
EndFunc   ;==>_CreateUniqueTmpFile
Edited by JohnOne

Share this post


Link to post
Share on other sites

Posted

Here's one for simply create a unique tmp file

MsgBox(0, 0, _CreateUniqueTmpFile())

; Create a unique tmp file, optional path and prefix
Func _CreateUniqueTmpFile($sPath = @TempDir, $sPreFix = '999')
    Local Const $ERROR_PATH_LENGTH = 6

    If StringLen($sPath) > 256 - 14 Then ;MAX_PATH - 14
        Return SetError($ERROR_PATH_LENGTH)
    EndIf

    Local $Struct = DllStructCreate("char[256]") ; MAX_PATH
    Local $StructPointer = DllStructGetPtr($Struct)

    Local $aRtn = DllCall("Kernel32.dll", 'uint', 'GetTempFileName', 'str', $sPath, 'str', $sPreFix, 'uint', 0, 'ptr', $StructPointer)
    If @error Then
        Return SetError(@error)
    EndIf

    Return DllStructGetData($Struct, 1)
EndFunc   ;==>_CreateUniqueTmpFile

Nice, a little different to the one in WinAPIEx. Thanks for posting, was getting a little lonely here!

Share this post


Link to post
Share on other sites

Posted

Output(@YEAR & @MON & @MDAY)
Output(@YEAR & '-' & @MON & '-' & @MDAY)
Output(@YEAR & '' & @MON & '-' & @MDAY)
Output(@YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & '-' & @MIN & '-' & @SEC)
Output(@YEAR & '/   ' & @MON & '/  ' & @MDAY & '         ' & @HOUR & ':' & @MIN & ':' & @SEC)

; Version: 1.00. AutoIt: V3.3.8.1
; Parse a date string to the format of YYYY/MM/DD HH:MM:SS as certain formats can use '.' or '-' in certain system locales.
Func _ParseDateString($sDateString)
	Return StringReplace(StringRegExpReplace(StringStripWS($sDateString, 8), '(d{4})D?(d{2})D?(d{2})(d{0,2})D?(d{0,2})D?(d{0,2})', '1/2/3 4:5:6'), ' ::', '') ; Can this be improved in anyway?
EndFunc   ;==>_ParseDateString

Func Output($sString)
	Return ConsoleWrite('[' & $sString & '] >> ' & _ParseDateString($sString) & @CRLF)
EndFunc   ;==>Output

Share this post


Link to post
Share on other sites

Posted

#include <Date.au3>
#include <Misc.au3>

ConsoleWrite('Is "' & @ScriptFullPath & '" newer (modified date) than "' & @AutoItExe & '": ' & _
		_Iif(_IsFileNewer(@ScriptFullPath, @AutoItExe), 'Yes', 'No') & '.' & @CRLF)

; Version: 1.00. AutoIt: V3.3.8.1
; Check if a file is newer than another file.
Func _IsFileNewer($sFilePath_1, $sFilePath_2, $iOption = 0) ; $iOption - Refer to the help file for FileGetTime and the option parameter.
	Local $aArray[3] = [2, $sFilePath_1, $sFilePath_2]
	For $i = 1 To $aArray[0]
		$aArray[$i] = StringRegExpReplace(FileGetTime($aArray[$i], $iOption, 1), '(d{4})(d{2})(d{2})(d{2})(d{2})(d{2})', '1/2/3 4:5:6')
	Next
	Return Number(_DateDiff('s', $aArray[1], $aArray[2]) < 0)
EndFunc   ;==>_IsFileNewer

Share this post


Link to post
Share on other sites

Posted

ConsoleWrite(_Rot13('Example use of applying ROT13 to a string of text.') & @CRLF)

; Version: 1.00. AutoIt: V3.3.8.1
; Convert a string into ROT13. [https://en.wikipedia.org/wiki/ROT13]
Func _Rot13($sString) ; Joke758 >> http://www.autoitscript.com/forum/topic/51400-rot13-encoding/#entry389256
	Local $iPosition = 0, _
			$sAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', _
			$sCharacter = '', _
			$sRotAlphabet = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm', _
			$sReturn = ''

	For $i = 1 To StringLen($sString)
		$sCharacter = StringMid($sString, $i, 1)
		$iPosition = StringInStr($sAlphabet, $sCharacter, 1)
		If $iPosition Then
			$sReturn &= StringMid($sRotAlphabet, $iPosition, 1)
		Else
			$sReturn &= $sCharacter
		EndIf
	Next
	Return $sReturn
EndFunc   ;==>_Rot13

Share this post


Link to post
Share on other sites

Posted (edited)

After some pontification I came up with an advanced heuristic word identification algorithm. I hope it's useful to someone. Any suggestions for improvements are welcome.

; Search for words based on specified criteria
; Default flag = 3 which includes the English alphabet, apostrophe and hyphen

; Match expressions containing:
; 1. English alphabet (Forced)
; 2. apostrophe (flag = 1)
; 3. hyphen (flag = 2)
; 4. numbers (flag = 4)
; 5. underscore (flag = 8)
; 6. Extended Latin alpha chars - ascii (flag = 16)
; 7. Any non white space character (flag = 32) - overrides all other flags

; Example =========================================================
#include <Array.au3> ; For array_Display
$sTestString = "`I'm just sayin'', I said `I'm æåñÿ ju-st e_bay-'bout ___sayin' -alright' r---t''ytr '''yt ' y  m-o-r-e- ---hyphen---s"
Local $aWords = _GetWords($sTestString, 3)
_ArrayDisplay($aWords, @extended & " words found")
;==================================================================

Func _GetWords($sString, $dFlag = 3)
    If Not IsString($sString) Then Return SetError(1, 0, 0) ; Not a string
    If Not IsInt($dFlag) Or $dFlag < 0 Then Return SetError(2, 0, 0) ; Invalid flag

    If BitAND($dFlag, 32) = 32 Then ; Override all other flags
	    $aWordArray = StringRegExp($sString, "S+", 3)
	    If Not @error Then
		    SetExtended(UBound($aWordArray)) ; Set the extended flag to the number of words found
		    Return $aWordArray
	    EndIf

	    Return SetError(3, 0, 0) ; No matches found
    EndIf

    ; Get English alphabet (Forced inclusion)
    $sAlphaEx = ""
    For $i = 65 To 122
	    $sAlphaEx &= Chr($i)
	    If $i = 90 Then $i += 6
    Next

    ; All valid alpha characters are needed to continue
    If BitAND($dFlag, 16) = 16 Then ; Conditional inclusion of extended latin alphabet
	    $sAlphaEx &= Chr(138) & Chr(140) & Chr(142) & Chr(154) & Chr(156) & Chr(158) & Chr(159)
	    For $i = 196 To 255
		    If $i <> 215 And $i <> 247 Then $sAlphaEx &= Chr($i)
	    Next
    EndIf

    ; Disambiguation between apostrophe and closing quote is impossible - `I'm just sayin''
    If BitAND($dFlag, 1) = 1 Then ; Include apostrophe
	    $sAlphaEx &= Chr(39) ; Add apostrophe to the search criteria
	    $sString = StringRegExpReplace($sString, "'{2,}", "' '") ; Consequtive apostrophes are illegal
	    ; Apostrophies must always occur adjacent to an alpha character - one side or the other.
	    $sString = StringRegExpReplace($sString, "([^" & $sAlphaEx & "][']+[^" & $sAlphaEx & "])" , " ")
    EndIf

    If BitAND($dFlag, 2) = 2 Then ; Include hyphens
	    ; Hyphens must always occur between alpha characters or apostrophes - on both sides.
	    $sString = StringRegExpReplace($sString, "([^" & $sAlphaEx & "][-]+)" , " ")
	    $sString = StringRegExpReplace($sString, "([-]+[^" & $sAlphaEx & "])" , " ")
	    $sAlphaEx &= "-" ; Add hyphen to the search criteria
    EndIf

    If BitAND($dFlag, 4) = 4 Then ; Include Numbers
	    For $i = 0 To 9
		    $sAlphaEx &= $i
	    Next
    EndIf

    If BitAND($dFlag, 8) = 8 Then $sAlphaEx &= "_" ; Include Underscore

    $aWordArray = StringRegExp($sString, "[" & $sAlphaEx & "]+", 3) ; Split into words
    If Not @error Then
	    SetExtended(UBound($aWordArray)) ; Set the extended flag to the number of words found
	    Return $aWordArray
    EndIf

    Return SetError(3, 0, 0) ; No matches found
EndFunc

Fixed a small bug

Edited by czardas

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