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.

  Reveal hidden contents

Posted
  On 8/13/2015 at 9:38 PM, nitekram said:

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:

  Reveal hidden contents

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
  On 8/14/2015 at 7:01 AM, Chimaera said:

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.

  On 8/13/2015 at 10:02 PM, boththose said:

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
  On 11/17/2015 at 4:59 PM, TheDcoder said:

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:

  Reveal hidden contents

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
  On 1/7/2016 at 4:18 PM, Trong said:
StringLen($sString) = ""

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

UDF List:

  Reveal hidden contents

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
  On 2/15/2016 at 4:15 PM, 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 ;-)

Expand  

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:

  Reveal hidden contents

 

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

  Reveal hidden contents

 

Posted

also:

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

 

  Reveal hidden contents

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...