Jump to content

AutoIt Snippets


Chimaera
 Share

Recommended Posts

$sString = StringMid($sString, StringInStr($sString, $sDelimiter) + StringLen($sDelimiter))
Edited by water

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

 

Link to comment
Share on other sites

Double post.

Edited by water

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

 

Link to comment
Share on other sites

$sString = "ThisIsATestStringOfCharacters"
$sDelimiter = "String"

msgbox(0, 'Before Delim' , _StringBefore($sString , $sDelimiter))

Func _StringBefore($sString , $sDelimiter)
Return StringLeft($sString , StringInStr($sString, $sDelimiter) - 1)
EndFunc

 

Edited by boththose

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

Link to comment
Share on other sites

When you're working in a vmware system that does not have VMTools installed and you want to paste text from your system to the virtual system, you can use this script snippet to ghetto rig paste from your clipboard into the VM system using the send function:

#RequireAdmin
AutoItSetOption('TrayAutoPause', 0)
HotKeySet("^+v", 'Sender')

While 1
    Sleep(100)
WEnd

Func Sender()
    Send(ClipGet())
EndFunc

Not at work to test this, but does requie admin rights? 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • 3 weeks later...

Second Contribution... Small but neat when you use it :)

; #FUNCTION# ====================================================================================================================
; Name ..........: CalcPercent
; Description ...: Calculates Percentage
; Syntax ........: CalcPercent($iPartDone, $iTotal[, $iRoundToDecimalPlace = 1])
; Parameters ....: $iPartDone           - Value of the part which is done.
;                  $iTotal              - The total value.
;                  $iRoundToDecimalPlace- [optional] Round upto which decimal place?. Default is 1.
; Return values .: Percentage (without % symbol)
; Author ........: TheDcoder
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://bit.ly/CalcPercentForAutoIt
; Example .......: Yes, See below
; ===============================================================================================================================
Func CalcPercent($iPartDone, $iTotal, $iRoundToDecimalPlace = 1)
    Return Round(($iPartDone / $iTotal) * 100, $iRoundToDecimalPlace) ; Calculate percentage, round it & return it!
EndFunc   ;==>CalcPercent

; Example

$iCountdown = 60 * 5 ; the value is in seconds

ProgressOn("Example for CalcPercent function", "Countdown upto " & $iCountdown & " seconds")

$hTimer = TimerInit()
For $i = 1 To $iCountdown
    ProgressSet(CalcPercent($i, $iCountdown))
    Sleep(1000)
Next
$iTime = TimerDiff($hTimer)
$iTime /= 1000

ProgressOff()

MsgBox(64, "Done!", "The countdown has ended! That took ~" & Round($iTime, 1) & " Seconds.")

Hope it may help you, TD :)

 

P.S Don't reply to this with rude reasons like "Hey! that is so simple! even a newbie can do that." or "It ain't worth posting in snippets section"

Edited by TheDcoder
Updated links with shortend Bitly links :)

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

Link to comment
Share on other sites

P.S Don't reply to this with rude reasons like "Hey! that is so simple! even a newbie can do that." or "It ain't worth posting in snippets section"

If you think this are rude commens then you should have a look at other forums and see how rude comments really look like ;)

 

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

 

Link to comment
Share on other sites

  • Moderators

P.S Don't reply to this with rude reasons like "Hey! that is so simple! even a newbie can do that." or "It ain't worth posting in snippets section"

So, you post something that is basically a rehashing of the example under ProgressSet, you're intelligent *cough* enough to foresee people are probably going to point out the snippet's lack of value, but you posted it anyway?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Maybe explain how you feel your example differs from the progressset helpfile.  You should be encouraging discourse and then logically defending your position rather than trying to preempt, as the forum is a good place to hone your debate skills in addition to your coding.

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

Link to comment
Share on other sites

@JLogan3o13 Debate: How my example differs from ProgressSet's example

Explanation: The only common thing between the two examples is that both are countdown timers... And its just a example :P.

I posted it here because the threads title reads "AutoIt Snippets" (This isn't part of the debate)...

@boththose Thanks :)

 

P.S Don't take that debate seriously :P

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

Link to comment
Share on other sites

  • Moderators

Hi all,

As I read the post which started all of this, I get the impression that it is the CalcPercent function which was the point of the exercise, not the ProgressSet section. To which end I feel some of the resultant comments are a little OTT - although I also feel that a snippet to calculate a percentage is also not exactly earthshattering in and of itself.  So please let us all decide to drop the matter - even though the OP was silly enough to make that ridiculous statement at the end of the post which quite frankly just begged the response it quite rightly got.

M23

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

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

  • 2 weeks later...

as vbscript do no like 64 bit :) i needed something to replace "unescape()"

Func decodeURIComponent($sURIComponent)
    If StringRegExp($sURIComponent, "%[0-9A-Fa-f]{2}", 0) Then
        $sURIComponent = Execute('"' & StringRegExpReplace($sURIComponent,"(%)([0-9A-Fa-f]{2})",'" & Chr(Dec(''$2'')) & "') & '"')
    EndIf
    Return $sURIComponent
EndFunc   ;==>decodeURIComponent

at first glance result is identical to vbscript's "unescape()"

Link to comment
Share on other sites

[0-9A-Fa-f]

you can make that [[:xdigit:]]

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Third Contribution! Maybe useful when you need to convert an 1D Array to an 2D Array :)

#include-once
#include <Array.au3> ; <----- ONLY NEEDED FOR EXAMPLE, REMOVE BEFORE USING!!!
#include <StringConstants.au3>


; #FUNCTION# ====================================================================================================================
; Name ..........: ArraySplit
; Description ...: Similar to StringSplit, Converts an 1D Array to an 2D Array based on delimiters
; Syntax ........: ArraySplit(ByRef $aArray, $sDelimiter)
; Parameters ....: $aArray              - Array to process.
;                  $sDelimiter          - Delimiter to split array.
; Return values .: Success: An 2D Array
;                  Failure: 0 & sets @error to:
;                  @error : 1 = Not an array
;                           2 = Delimiter was not found in an element (@extended contains the element's index no.)
; Author ........: TheDcoder
; Modified ......: N/A
; Remarks .......: There should be only 1 delimiter in each element of the Array!!! Only Text before & after the first delimiter will be present in col 1 & col 2
; Related .......: StringSplit
; Link ..........: bit.ly/ArraySplitForAutoIt
; Example .......: Yes
; ===============================================================================================================================
Func ArraySplit(ByRef $aArray, $sDelimiter)
    If Not IsArray($aArray) Then Return SetError(1, 0, 1) ; The statment itself states what it does 
    $iArrayLen = Ubound($aArray) ; We need Array's length (or no. of elements)
    Local $aReturn[$iArrayLen][2] ; Delare a 2D Array with 2 coloumns for returning
    For $i = 0 To $iArrayLen - 1 ; Loop through Array
        $aTempArray = StringSplit($aArray[$i], $sDelimiter, $STR_ENTIRESPLIT) ; StringSplit the string & store it in an array
        If $aTempArray[0] = 1 Then Return SetError(2, $i, 0)
        $aReturn[$i][0] = $aTempArray[1] ; Put the first string in Coloumn 0
        $aReturn[$i][1] = $aTempArray[2] ; Put the second string in Coloumn 1
    Next
    Return $aReturn ; Return the Array 
EndFunc

; Example

Local $aArray[3] = ["x=1", "y=2", "z=3"] ; Declare the Array
$aArray = ArraySplit($aArray, '=') ; Convert an 1D Array to an 2D Array based on a delimiter
_ArrayDisplay($aArray) ; Display the array 

#cs ---------------------- Visual example ----------------------

This is our $aArray:

    |    Data     |
-----------------------
0.  |   "x=1"     |
-----------------------
1.  |   "y=2"     |
-----------------------
2.  |   "z=3"     |
-----------------------

This is our $aArray after ArraySplit (with delimiter as "=" (Equal Sign)):

    |  Column 0  | Column 1 |
---------------------------------
0.  |    "x"      |     1     |
---------------------------------
1.  |    "y"      |     2     |
---------------------------------
2.  |    "z"      |     3     |
---------------------------------

#ce ---------------------- Visual example ----------------------

Hope you may find it useful, TD ;)

Edited by TheDcoder
Added "Error Checking" & Minor Improvements, TD :D

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

Link to comment
Share on other sites

Great. Array UDF has this by the way if people are interested.

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

Link to comment
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
 Share

  • Recently Browsing   0 members

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