Jump to content

Recommended Posts

Posted

I agree, this thread is a ridiculous katamari that encourages double posting and creates disjointed conversations about solutions.  snippets are examples.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

i thnk that maybe this should have a section in the example scripts, under snippets, and each one have its own post, otherwise this post will be like the great software thread, cannot remeber name. - a lot of great stuff lost in a 100 pages. 

But I will give my 4 cents this time, as this is the exact definition of examples. Besides the other issue with search for it in our search engine, would be nearly impossible. 

 

Please excuse any spelling mistakes, I am on a cell. 

It's called Examples or wiki.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted (edited)

Once everyone was given powers to post on the wiki, I stopped transferring them to the wiki, because you can all do it yourself now.

It even gives you the template to do so in the first post

https://www.autoitscript.com/wiki/AutoIt_Snippets

By the look of the wiki snippets i think it has some formatting issues now prob due to the forum changes.

Edited by Chimaera
  • 3 months later...
Posted

Once everyone was given powers to post on the wiki, I stopped transferring them to the wiki, because you can all do it yourself now.

It even gives you the template to do so in the first post

https://www.autoitscript.com/wiki/AutoIt_Snippets

By the look of the wiki snippets i think it has some formatting issues now prob due to the forum changes.

I agree, this thread is a ridiculous katamari that encourages double posting and creates disjointed conversations about solutions.  snippets are examples.

Benefit of posting in the Forum vs in the Wiki: Feedback, Appreciation, Comments, Update Notifications per E-Mail...

IMHO maybe there could be a "Snippets 2015", "Snippets 2015" Thread in the forum,

or maybe even "Snippets November 2015" etc. then it never gets much too long...

Personally I like checking out new posts in this thread. Just wanted to give some counter arguments to the above.

Posted

Maybe a Snippets Sub Forum for storing snippet threads? :think:

In hindsight it would have been better to have a submission sub forum and a discussion sub forum. Oh well, considering no one posts here that much, I don't see it being an issue of leaving it as it is. Ain't broke!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

  • 4 weeks later...
Posted (edited)

Finally another snippet! :D

I use this little function to check if a number is present in a number (Magic numbers)... Magic numbers are powers of 2 (like 16, 32, 64 etc.) which can be added BitORed together to form a magic number...

; #FUNCTION# ====================================================================================================================
; Name ..........: IsMgcNumPresent
; Description ...: Checks if a number is a present in a number (Magic numbers aka Powers of 2)
; Syntax ........: IsMgcNumPresent($iNumber, $iMagicNumber)
; Parameters ....: $iNumber             - Number to check if it exists in $iMagicNumber.
;                  $iMagicNumber        - The number which might contain $iNumber.
; Return values .: Success: True
;                  Failure: False
; Author ........: Damon Harris (TheDcoder)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://bit.ly/IsMgcNumPresentForAutoIt
; Example .......: Yes, see below.
; ===============================================================================================================================
Func IsMgcNumPresent($iNumber, $iMagicNumber)
    Return BitAND($iMagicNumber, $iNumber) = $iNumber
EndFunc

; Example

Global Const $NUMBER = 32
Global Const $MAGIC_NUMBER = BitOR(32, 64)

ConsoleWrite(@CRLF)
ConsoleWrite('+> Is ' & $NUMBER & ' present in ' & $MAGIC_NUMBER & '?... Its ' & IsMgcNumPresent($NUMBER, $MAGIC_NUMBER) & @CRLF)
ConsoleWrite(@CRLF)

UPDATE: I have moved this snippet to Gist, I will no longer maintain this version! please check for updates in the Gist itself!

Enjoy, TD :)

Edited by TheDcoder
UPDATE

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • 4 weeks later...
Posted (edited)
; EG---------------------------------------------- -
Local $sString = StringBetween("<test>C</test><test>B</test><test>A</test>", "<test>", "</test>")
MsgBox(0, "StringBetween", "Strings between <test> and </test>" & @CRLF & "Is: " & $sString & @CRLF & "In text: <test>C</test><test>B</test><test>A</test>")
; ------------------------------------------------ -

; #FUNCTION# ====================================================================================================================
; Name ..........: StringBetween
; Description ...: Find strings between two string delimiters
; Syntax ........: StringBetween($sString, $sStart, $sEnd)
; Parameters ....: $sString         - The string to search.
; Parameters ....: $sStart          - The beginning of the string to find.
;                  $sEnd            - The end of the string to find.
; Return values .: Success: a found string
;                  Failure: sets the @error flag to non-zero.
;                  @error: 1 - No strings found.
; Author ........: Trong
; Related .......: _StringBetween
; Example .......: Yes
; ===============================================================================================================================

Func StringBetween($sString, $sStart, $sEnd)
    $sString = StringReverse(StringTrimLeft($sString, StringInStr($sString, $sStart) + StringLen($sStart) - 1))
    $sString = StringReverse(StringTrimLeft($sString, StringInStr($sString, StringReverse($sEnd)) + StringLen($sEnd) - 1))
    Return SetError(StringLen($sString) < 1, 0, $sString)
EndFunc   ;==>StringBetween

 

Edited by Trong

Regards,
 

Posted
StringLen($sString) = ""

No, this is awful, as you are relying on type coercion.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

  • 1 month later...
Posted (edited)

Hello everyone!

I want to add 2-3 simple functions, very very stupid, but because I'm very lazy I'd like them to be included in official AutoIt ;-)

They are for writing messages in a simple & concise way, without bothering if you have to deal with strings or arrays. They are mostly for debug pourpose.
 

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

#include <Array.au3>

; Functions for writing messages in the most concise way (be it strings or array)

Local $simpleMsg="Hey you!"
Local $aMsg[3]=["Hey you!", "Not you", "You!!"]

_showAnyMsg($simpleMsg, "_showAnyMsg example", 0)
_msg($simpleMsg, "_msg example")
_msg("simplest way")
_msg($aMsg, "_msg example with array")
_bye("I'm gone!")
_msg("I had something else to say...")


;====================================================================================================================
;Function that displays a message to the user, :
;  Parameters
;    message_IN: (long) text of the message
;    title_IN  : (short) title of the message
;    msgFlag_IN: tipe of message display (see MsgBox standard function)
Func _showAnyMsg (ByRef $message_IN, $title_IN, $msgFlag_IN)
    If IsArray($message_IN) Then
        _ArrayDisplay($message_IN, $title_IN)
    Else
        MsgBox($msgFlag_IN, $title_IN, $message_IN)
    EndIf
EndFunc ;==>_showAnyMsg


;====================================================================================================================
;Function that displays a message to the user, using the simplest form:
;  Parameters
;    message_IN: (long) text of the message
;    title_IN  : (short) title of the message, default is "Message".
;    msgFlag_IN: tipe of message display (see MsgBox standard function), default is 0.
Func _msg (ByRef $message_IN, $title_IN = "Message", $msgFlag_IN = 0)
    _showAnyMsg($message_IN, $title_IN, $msgFlag_IN)
EndFunc ;==>_msg


;====================================================================================================================
;Function that displays a message to the user, using the simplest form:
;  Parameters
;    message_IN: (long) text of the message
;    title_IN  : (short) title of the message, default is "Message".
;    msgFlag_IN: tipe of message display (see MsgBox standard function), default is 0.
Func _bye (ByRef $message_IN, $title_IN = "Terminate", $msgFlag_IN = 0)
    _showAnyMsg($message_IN, $title_IN, $msgFlag_IN)
    Exit
EndFunc ;==>_bye

 

Edited by NotAviable
  • Developers
Posted
5 minutes ago, NotAviable said:

I want to add 2-3 simple functions, very very stupid, but because I'm very lazy I'd like them to be included in official AutoIt ;-)

Won't happen because we are lazy too! ;)
Just add them in your own include file.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I'm even too lazy to post here ... ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

EDITED: REMOVED

I prefer to keep it

EDIT:
Edited by Guest
  • 2 weeks later...
Posted

Here an alternative to the _StringRepeat() function:

; returns the passed char (or a whole string) replicated n times
; Example1: ConsoleWrite(_StringReplicate('*', 5) & @CRLF)
; Example2: ConsoleWrite(_StringReplicate('<->', 15) & @CRLF)
;
Func _StringReplicate($sChars = "", $iRepeats = 0)
    $sChars = String($sChars)
    $iRepeats = Int(Abs(Number($iRepeats)))
    Return StringReplace(StringFormat('%' & $iRepeats & 's', ""), " ", $sChars)
EndFunc   ;==>_StringReplicate

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

  • 3 weeks later...
Posted (edited)

EnvParse - for passing strings (paths) with environment variables (e.g.: %TEMP%\test):

Func EnvParse($str)
    $vars = StringRegExp($str, "%([^%]+)%", 3)
    For $var In $vars
        $get = EnvGet($var)
        If $get Then
            $str = StringReplace($str, "%" & $var & "%", $get)
        EndIf
    Next
    Return $str
EndFunc

Example: EnvParse("%TEMP%\test") will return something like C:\Windows\Temp\test.

Edited by Jefrey

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Posted

also:

$sPath = "%TEMP%\test\subfolder1\subfolder2"
msgbox(0, '' , EnvGet(stringtrimleft(stringtrimright(stringsplit($sPath, "\" , 2)[0] , 1) , 1)) & stringmid($sPath , stringinstr($sPath , "\" , 0 , 1)))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...