Jump to content
Chimaera

AutoIt Snippets

Recommended Posts

guinness

What on earth?... I do not understand any of that code at all. What are the benefits to all that code over the code I wrote?

I can have multiple instances of the average mean during code execution, whereas your version is only for one. If I want a second instance with your version, then I have to destroy the previous first. Also I am just adding the values together and keeping note of the times the Add() function has been called. No need to store in an array, which is not only a memory hog but less efficient as you ReDim everytime an element is added. Which in the backend creates an new array and copies the old elements across.


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

Share this post


Link to post
Share on other sites
Morthawt

Well it is the only method I know that I can perform the average with the least amount of code. You have all kinds of things in yours that I don't have a hope of understanding. Including that GUID looking string. You are a developer of AutoIt so I would imagine you know it inside and out, I am not that advanced with the language. I can do a lot and it is rare for me to have an idea and not be able to make something but I ackknowledge there is still a lot to AutoIt that I would likely never get into either because the excess required knowledge per particular usage would be too high, like certain windows API things and WMI etc. But what you wrote in your example is alien to me. lol

Edited by Morthawt

Share this post


Link to post
Share on other sites
Bluesmaster

just a small one-liner contribution that came along today. Calculates the weekday based on another weekday and the diffrence in  days between them:

(I know you can do it by combining udfs but hey.. :geek: if you get very very bored you can reverse engineer the math :) )

Mod( Mod( @WDAY + 7 + Mod( $diff , 7 ) , 7 ) + 6 , 7 ) + 1

best regards 

 

Bluesmaster

 

 

 

*Update: there is a much shorter way to do this  (thanks to jchd)

$sourceDay = @WDAY
$diff =  22  ; = 22 days in the future
ConsoleWrite(   Mod($sourceDay + Mod($diff, 7) + 6, 7) + 1    & @LF)
Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites
JLogan3o13

Bluesmaster, while you explain your approach, the undeclared variable in your snippet may throw newer forum members. It is generally regarded as best practice to include completely runnable code, even for one or two-liners. That way, new folks passing by can take your code and run it, learning from it.

 

Edit: Just saw your post in Examples where jchd corrects your methodology. You may want to update your snippet.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Bluesmaster

update:

- runable

- new methodology


My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites
gil900

I'm betting this is the smallest function and the simplest here

Global $aArray[10000000]
MsgBox(0,'','') ; This take 43MB memory
CleanVar($aArray) ; Now if we want to clean the var, we use this
MsgBox(0,'','') ; Now it take about 4MB memory


; #FUNCTION# ====================================================================================================================
; Name ..........: CleanVar
; Description ...: Instead of using the ugly method - $var = '' in order to clean variable, you can use CleanVar($var)
; Syntax ........: CleanVar(Byref $var)
; Parameters ....: $var                 - [in/out] The variable to clean.
; Return values .: None
; Author ........: gil900
; Example .......: Yes
; ===============================================================================================================================
Func CleanVar(ByRef $var)
    $var = ''
EndFunc
Edited by gil900

Share this post


Link to post
Share on other sites
guinness

I'm betting this is the smallest function and the simplest here

Global $aArray[10000000]
MsgBox(0,'','') ; This take 43MB memory
CleanVar($aArray) ; Now if we want to clean the var, we use this
MsgBox(0,'','') ; Now it take about 4MB memory


; #FUNCTION# ====================================================================================================================
; Name ..........: CleanVar
; Description ...: Instead of using the ugly method - $var = '' in order to clean variable, you can use CleanVar($var)
; Syntax ........: CleanVar(Byref $var)
; Parameters ....: $var                 - [in/out] The variable to clean.
; Return values .: None
; Author ........: gil900
; Example .......: Yes
; ===============================================================================================================================
Func CleanVar(ByRef $var)
    $var = ''
EndFunc

...and the worst snippet too. Please put a little more effort into your snippets. Even something like this makes more sense e.g.

#include <Array.au3>

Example()

Func Example()
    Local $aArray[100]
    _ArrayDisplay($aArray)
    PurgeVar($aArray)
    _ArrayDisplay($aArray)
EndFunc   ;==>Example

Func PurgeVar(ByRef $vVar)
    Switch VarGetType($vVar)
        Case "Array"
            Local $aEmpty[0]
            $vVar = $aEmpty ; Default value of an array.
        Case "Binary"
            $vVar = Binary(0) ; Default value of binary.
        Case "Bool"
            $vVar = False ; Default value of a boolean.
        Case "Double"
            $vVar = 0.0 ; Default value of a double.
        Case "Int32", "Int64"
            $vVar = 0 ; Default value of an integer.
        Case "Function", "Keyword", "DLLStruct", "Object", "Ptr"
            $vVar = Null ; Default value of an object/pointer.
        Case "String"
            $vVar = "" ; Default value of a string.
    EndSwitch
EndFunc   ;==>PurgeVar
Edited by guinness

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

Share this post


Link to post
Share on other sites
gil900

What is the point to check this (VarGetType) if you anyway use it to delete the data in variable?

It really matter if you use 0 or "" when the goal is to clear memory that the variable use?

"" and 0 Cleaning almost the same amount of memory and from what you said, "" use less memory so it cleaning a bit more memory.

 

 

...and the worst snippet too.

Maybe :sweating:

Edited by gil900

Share this post


Link to post
Share on other sites
guinness

What is the point to check this (VarGetType) if you anyway use it to delete the data in variable?

It really matter if you use 0 or "" when the goal is to clear memory that the variable use?

"" and 0 Cleaning almost the same amount of memory and from what you said, "" use less memory so it cleaning a bit more memory.

 

Maybe :sweating:

Because good practice would be to "clear" with the datatype the variable is holding. Mine isn't fully working snippet. Just a idea.

JohnOne,

VarGetType does work with arrays,


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

Share this post


Link to post
Share on other sites
guinness

Yeah, sorry I thought your code was complete.

Now it is.

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

Share this post


Link to post
Share on other sites
JohnOne

Not sure it is, I'm not 100% but I don't think you can pass type Object ByRef...

$obj = ObjCreate("scripting.dictionary")

_Check($obj)

PurgeVar($obj)

_Check($obj)

Func PurgeVar(ByRef $vVar)
    Switch VarGetType($vVar)
        Case "Array"
            Local $aEmpty[0]
            $vVar = $aEmpty ; Default value of an array.
        Case "Binary"
            $vVar = Binary(0) ; Default value of binary.
        Case "Bool"
            $vVar = False ; Default value of a boolean.
        Case "Double"
            $vVar = 0.0 ; Default value of a double.
        Case "Int32", "Int64"
            $vVar = 0 ; Default value of an integer.
        Case "Function", "Keyword", "DLLStruct", "Object", "Ptr"
            $vVar = Null ; Default value of an object/pointer.
        Case "String"
            $vVar = "" ; Default value of a string.
    EndSwitch
EndFunc   ;==>PurgeVar

Func _Check($obj)
    Static $num = 0
    $num += 1
    ConsoleWrite($num & " " & VarGetType($obj) & @LF)
    If Not IsObj($obj) Then
        Exit MsgBox(0, "Error:" & " " & $num, VarGetType($obj) & @CRLF & $obj)
    EndIf
EndFunc   ;==>_Check

Oddly though, it does convert it to the Keyword.

EDIT: So Is Null, really Null, or Just a Keyword, and does AutoIt need it's types updating?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
guinness

Null is just a keyword. I used it here because in C# dedault(object) is null.


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

Share this post


Link to post
Share on other sites
Morthawt

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

Share this post


Link to post
Share on other sites
GhostLine

Hey guys,

Here's a little something I've coded this morning for my job :

#include <Date.au3>

MsgBox(0,"",_YDay_To_Date("90", "2015"))


; #FUNCTION# ====================================================================================================================
; Name ..........: YDay_To_Date
; Description ...: Give the date of the xxxth day of a given year
; Syntax ........: YDay_To_Date($yday, $year)
; Parameters ....: $yday    : the day number you want to "convert" to date
;                : $year    : the concerned year
; Return values .: If there's no error, the date in standard format (YYYY/MM/DD) ; otherwise, nothing.
; Author ........: GhostLine
; Example .......: Yes
; ===============================================================================================================================
Func _YDay_To_Date($yday, $year)
    If _DateIsLeapYear($year) And $yday > 364 Or $yday > 365 Then Exit
    $month = 1
    For $day = 1 To $yday
        If $day = $yday Then ExitLoop
        If _DateIsValid($year & "/" & StringRight(0 & $month, 2) & "/" & StringRight(0 & $day, 2)) <> 1 Then
            $yday = $yday - ($day - 1)
            $day = 1
            $month = $month + 1
        EndIf
    Next
    Return($year & "/" & StringRight(0 & $month, 2) & "/" & StringRight(0 & $yday, 2))
EndFunc   ;==>_YDay_To_Date

I hope it's not too bad :)

Edit : after posting this on the french forum, jchd has answered me, and opened my eyes about the fact I've totally missed the use of _DateAdd :)

Edited by GhostLine

Share this post


Link to post
Share on other sites
TheDcoder

My First Submission:

; #FUNCTION# ====================================================================================================================
; Name ..........: StringTrimLeftUntil
; Description ...: Trim a string left until it reaches the delimiter charecter
; Syntax ........: StringTrimLeftUntil($sDelimiter, $sString)
; Parameters ....: $sDelimiter          - Charecter(s) to trim until
;                  $sString             - A string value.
;                  $iOccurrence         - Trim until which occurrence of the delimiter [Default = 1st occurrence]
;                  $bTrimDelimiter      - Do you want to trim the delimiter? Use True or False [Default = True]
; Return values .: Trimmed String
; Author ........: TheDcoder
; Modified ......: Thanks to water for the Idea
; Remarks .......: This function is not case sensitive meaning "DeLiMiTeR" is same as "Delimiter"
; Related .......: StringTrimLeft
; Link ..........: http://bit.ly/StringTrimUntilForAutoIt
; Example .......: No
; ===============================================================================================================================
Func StringTrimLeftUntil($sDelimiter, $sString, $iOccurrence = 1, $bTrimDelimiter = True)
    $iDelimiterLen = StringLen($sDelimiter)
    $sString = StringTrimLeft($sString, StringInStr($sString, $sDelimiter, 2, $iOccurrence) + ($iDelimiterLen - 1)) ; This is a little hard to explain:
    #cs =========================================================================================================================================|
    | What it does is:                                                                                                                           |
    | 1. Find the delimiter's position in the string (StringInStr)                                                                               |
    | 2. Add delimiter's Length to delimiters position (I remove 1 for delimiter's length because StringInStr already contains that 1 charecter) |
    | 3. Trim the string :)                                                                                                                      |
    #ce =========================================================================================================================================|
    If $bTrimDelimiter = False Then $sString = $sDelimiter & $sString ; Look at the comment in StringTrimRightUntil ;)
    Return $sString ; Return the String :D
EndFunc   ;==>StringTrimLeftUntil


; #FUNCTION# ====================================================================================================================
; Name ..........: StringTrimRightUntil
; Description ...: Trim a string right until it reaches the delimiter charecter
; Syntax ........: StringTrimRightUntil($sDelimiter, $sString)
; Parameters ....: $sDelimiter          - Charecter(s) to trim until
;                  $sString             - A string value.
;                  $iOccurrence         - Trim until which occurrence of the delimiter [Default = 1st occurrence]
;                  $bTrimDelimiter      - Do you want to trim the delimiter? Use True or False [Default = True]
; Return values .: Trimmed String
; Author ........: TheDcoder
; Modified ......: Me
; Remarks .......: This function is not case sensitive meaning "DeLiMiTeR" is same as "Delimiter".
;                  PLEASE USE StringTrimLeftUntil WHENEVER POSSIBLE! StringTrimRightUntil is slightly slower than StringTrimLeftUntil (62.2% slower to be exact)
; Related .......: StringTrimRight
; Link ..........: http://bit.ly/StringTrimUntilForAutoIt
; Example .......: No
; ===============================================================================================================================
Func StringTrimRightUntil($sDelimiter, $sString, $iOccurrence = 1, $bTrimDelimiter = True)
    $iStringLen = StringLen($sString) ; We need string's len
    $iDelimiterLen = StringLen($sDelimiter) ; We need delimiter's len too
    $iOccurrence -= $iOccurrence * 2 ; Convert to negitive integer so that we can find the delimiter from the right-side
    $sString = StringTrimRight($sString, ($iStringLen - StringInStr($sString, $sDelimiter, 2, $iOccurrence)) - ($iDelimiterLen - 1) + $iDelimiterLen) ; Explanation:
    #cs ===========================================================================================================================================================|
    | 1. Find the delimiter's postion in the string from the right-side (StringInStr) & remove string's length to get the no. of chars to trim from te right-side  |
    | 2. Substract (delimiter's len - 1) in the no. of char to trim                                                                                                |
    | 3. Again add delimiter's len                                                                                                                                 |
    | 4. Trim the string!!!                                                                                                                                        |
    #ce ===========================================================================================================================================================|
    If $bTrimDelimiter = False Then $sString &= $sDelimiter ; This way simplest way to do it without messing with the complex algorithm (Also even I can't understand the algorithm cleary! Even though I got it working somehow :-/)
    Return $sString ; Return the String
EndFunc   ;==>StringTrimRightUntil

Hope it may help someone, TD :)

 

Edited by TheDcoder
Added "$bTrimDelimiter" parameter, TD :)

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
water

Wouldn't

$sString = StringMid(StringInStr($sString, $sDelimiter) + 1)

do the same but faster?
And RegExp will be faster too.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Double post.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
TheDcoder

@water Will not work for delimiter with multiple characters


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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

×