Chimaera

AutoIt Snippets

329 posts in this topic

#301 ·  Posted

I assume you are trying to check if the variable is not an empty string, so you need to add parenthesis, that was kind of what I was pointing out. I write JavaScript on a daily basis, so having case-insenstiive

// JavaScript
var str = 'some string';
if (str !== '') {
    // ...
}

; AutoIt

Local $sStr = ''
If Not ($sStr == '') Then ; Or use =, up to you what you prefer
     ; ...
EndIf

; Why your logic is incorrect
Local $var = False
If Not $var = '' Then ; This will evaluate to true, because "Not False" is evaluated before check the "evaluated result = ''", although $var is boolean and not a string data type, so it should be false

The evaluation is ...
Not $var ; Result = True
True == '' ; Result = False

Although it should be True, because False is NOT an empty string

Maybe I am wrong? I really haven't used AutoIt in a year, but I would say this is basic understanding

 


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites



#302 ·  Posted

1 minute ago, guinness said:

I assume you are trying to check if the variable is not an empty string

Yup

3 minutes ago, guinness said:

so you need to add parenthesis

parenthesis are only required to override Order of operations (AutoIt's OoO).

Quote
; Why your logic is incorrect
Local $var = False
If Not $var = '' Then ; This will evaluate to true, because "Not False" is evaluated before check the "evaluated result = ''", although $var is boolean and not a string data type, so it should be false

 

 

As I have said above, Order of Operations are important here and different programming languages have different OoO (at least I think they do...)

Not $var = '' will still evaluate to False because $var = '' is evaluated before Not

P.S I have even tested it to make sure that $var is False.


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

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#303 ·  Posted

44 minutes ago, TheDcoder said:

As I have said above, Order of Operations are important here and different programming languages have different OoO (at least I think they do...)

Not $var = '' will still evaluate to False because $var = '' is evaluated before Not

Not at all. Refering to the same source as you, one can see that unary operators have higher priority than comparisons. Hence Not $var = '' evaluates to (Not $var) = ''

2 people like this

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)

Share this post


Link to post
Share on other sites

#304 ·  Posted (edited)

:oops:

I just checked the documentation... and indeed, you are correct! Not is the first operation in the order... I have updated my snippet. Thanks for the clarification :D

Edited by TheDcoder
Dropping words again!
1 person likes this

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

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#305 ·  Posted

I was needing to create a quick GUI and what better language to do it in!

What was meant to be quick turned into getting lost in code... yes, we've all been there.

I was tired of positioning each of the controls within my container GUIs so I started writing a pad function.
I realized that ControlGetPos wasn't returning what I had expected for the control relative to its parent, but from the ancestor.

The _hwnd_GetPos() is something I had written in another language that I just translated to here.

; #FUNCTION# ====================================================================================================================
; Author ........: SmOke_N
; Modified.......:
; ===============================================================================================================================
#include-once
#include <WinAPI.au3>

Func _hwnd_GetPos($hWnd, $hParent = 0)

    $hParent = IsHWnd($hParent) ? $hParent: _WinAPI_GetParent($hWnd)

    Local $tPoint = DllStructCreate("int x;int y")

    Local $tRect = _WinAPI_GetWindowRect($hWnd)
    DllStructSetData($tPoint, "x", DllStructGetData($tRect, "left"))
    DllStructSetData($tPoint, "y", DllStructGetData($tRect, "top"))
    _WinAPI_ScreenToClient($hParent, $tPoint)

    Local $aData[4] = [ _
        DllStructGetData($tPoint, "x"), _
        DllStructGetData($tPoint, "y"), _
        DllStructGetData($tRect, "right") - DllStructGetData($tRect, "left"), _
        DllStructGetData($tRect, "bottom") - DllStructGetData($tRect, "top")]

    Return $aData
EndFunc

Then I get to the combo commands and realize there's no autocomplete for _GUIComboBoxEx_* (but I did see it on the todo list in the include file).
Anyway, here's one to work with the Ex include (it's been a while since working with regex, almost switched to a for/next loop lol).

Edit:

Forgot about the AutoIt Snippets thread... moving things there!

; #FUNCTION# ====================================================================================================================
; Author ........: SmOke_N
; Modified.......:
; ===============================================================================================================================
#include-once
#include <GUIComboBoxEx.au3>
#include <GUIEdit.au3>

Func _GUICtrlComboBoxEx_AutoComplete($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    If Not __GUICtrlComboBox_IsPressed('08') And Not __GUICtrlComboBox_IsPressed("2E") Then ;backspace pressed or Del
        Local $hEXEdit = HWnd(_SendMessage($hWnd, $CBEM_GETEDITCONTROL))
        Local $sEditText = _GUICtrlEdit_GetText($hEXEdit)
        If StringLen($sEditText) Then
            Local $sList = _GUICtrlComboBoxEx_GetList($hWnd)
            Local $sDelim = "\" & Opt("GUIDataSeparatorChar")

            Local $aStr = StringRegExp($sList, "(?si)(?:^|" & $sDelim & ")(" & _
                $sEditText & ".*?)(?:\z|" & $sDelim & ")", 1)
            If IsArray($aStr) Then
                _GUICtrlEdit_SetText($hEXEdit, $aStr[0])
                _GUICtrlEdit_SetSel($hEXEdit, StringLen($sEditText), StringLen($aStr[0]))
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GUICtrlComboBoxEx_AutoComplete

 

2 people like this

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#306 ·  Posted

Great to see you, Sir Smokes a Lot :) Great snippet.


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

Share this post


Link to post
Share on other sites

#307 ·  Posted (edited)

A month generator

this function creates a month calendar into an 7x7 array,
optional parameters are:  year, month, iso
if iso is true then first day of week is monday else is sunday

(the names of the days are localized )

#include <date.au3>
#include <array.au3>

_ArrayDisplay(_GenerateMonth(1962, 5))

; #FUNCTION# ====================================================================================================================
; Author ........: Chimp
; Modified.......:
; ===============================================================================================================================
Func _GenerateMonth($iYear = @YEAR, $iMonth = @MON, $ISO = True)
    ; this function creates a month calendar into an 7x7 array
    Local $aMonth[7][7], $iDOW
    Local $iFirstDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, 1) : _DateToDayOfWeek($iYear, $iMonth, 1)
    For $iDay = 1 To 7
        $aMonth[0][$iDay - 1] = $ISO ? _DateDayOfWeek(Mod($iDay, 7) + $ISO, $DMW_LOCALE_SHORTNAME) : _DateDayOfWeek($iDay, $DMW_LOCALE_SHORTNAME)
    Next
    For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth)
        $iDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay)
        $aMonth[Int(($iFirstDOW + $iDay - 2) / 7) + 1][$iDOW - 1] = $iDay
    Next
    Return $aMonth
EndFunc   ;==>_GenerateMonth

 

Edited by Chimp

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

Share this post


Link to post
Share on other sites

#308 ·  Posted (edited)

How to count repeating #instances in an array

 

#include <Array.au3>
Local $Source[10001], $sum[11][3]
$sum[0][0] = 10

For $i = 1 To 10000
    $Source[$i] = Random(1, 10, 1)
Next

Local $ValueUnique = _ArrayUnique($Source, Default, Default, 1, 0)
_ArraySort($ValueUnique)

For $i = 1 To UBound($ValueUnique) - 1
    $sum[$i][0] = $ValueUnique[$i]
    $sum[$i][1] = "x"
    ;Backwards
    $sum[$i][2] = _ArrayCount($Source, $ValueUnique[$i], 1, 0, 1, 0)
Next
_ArrayDisplay($sum)

Func _ArrayCount(ByRef $aArray, $vValue = "", $istart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iForward = 0, $iSubItem = 0)
    Local $count = 0
    If Not $iEnd Then $iEnd = UBound($aArray) - 1
    If $iForward Then
        $istart = _ArraySearch($Source, $vValue, $istart, $iEnd, $iCase, $iCompare, $iForward, $iSubItem)
        If Not @error Then
            $count += 1
            Do
                $istart = _ArraySearch($Source, $vValue, $istart + 1, $iEnd, $iCase, $iCompare, $iForward, $iSubItem)
                If Not @error Then
                    $count += 1
                EndIf
            Until @error
        EndIf
    Else
        $iEnd = _ArraySearch($Source, $vValue, $istart, $iEnd, $iCase, $iCompare, $iForward, $iSubItem)
        If Not @error Then
            $count += 1
            Do
                $iEnd = _ArraySearch($Source, $vValue, $istart, $iEnd - 1, $iCase, $iCompare, $iForward, $iSubItem)
                If Not @error Then
                    $count += 1
                EndIf
            Until @error Or $iEnd <= 1
        EndIf
    EndIf
    Return $count
EndFunc   ;==>_ArrayCount

 

Edited by Deye

Share this post


Link to post
Share on other sites

#309 ·  Posted

@Deye,

This is very slow. Repeatedly invoking _ArrayAdd and _ArraySearch is horrible CPU waste.
You can use a Map to speed the process tremendously. The Map datatype is available in the beta but by the time it has been available the beta hasn't been found problematic at all. Note that I process 100,000 values in the following example:

#include <Array.au3>
Local $Source[100000]

For $i = 0 To UBound($Source) - 1
    $Source[$i] = Random(0, 99, 1)
Next

Local $Histogram[]      ; use a Map datatype

For $i In $Source
    If MapExists($Histogram, $i) Then
        $Histogram[$i] += 1
    Else
        $Histogram[$i] = 1
    EndIf
Next

Local $Keys = MapKeys($Histogram)
_ArraySort($Keys)
For $i In $Keys
    ConsoleWrite($i & ' has ' & $Histogram[$i] & " occurences" & @LF)
Next

; another possibility since we can expect that all values in the range are present at least once
; this requires that the values are integers in [0. N]
Local $Counts[UBound($Keys)]
For $i = 0 To UBound($Keys) - 1
    $Counts[$i] = $Histogram[$i]
Next
_ArrayDisplay(_Array1DToHistogram($Counts))

As a bonus I also show how one can use _Array1DToHistogram in some cases.

Displaying values sorted by increasing/decreasing occurence is left as an exercise to the reader.

1 person likes this

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)

Share this post


Link to post
Share on other sites

#310 ·  Posted

jchd,

Thanks for the feedback 
Well, of course there are other choices or methods out there that I'm unaware of if speed related and such ..
I simply liked the wide possibility s this simple function can give when making it play along  ..  (as the first choice of using _ArraySearch)
If someone needs to count instances between indexes, back and forth or in Columns  .. 

Share this post


Link to post
Share on other sites

#311 ·  Posted (edited)

This code, I use to report on the Remote desktop windows state. The array returns the state of the windows, as far as if it is full screen or a window, the caveat is that this code, does not tell you if the minimized window was a full screen or was windowed. ( if you have a better idea, pitch in )

#include <Array.au3>
Local $a = rdpWindowsStatus()
_ArrayDisplay($a, "rdpWindowsStatus")
Func rdpWindowsStatus()
    Local $i, $c, $a = WinList("[TITLE:BBar;CLASS:BBarWindowClass;]")
    Local $b = WinList("[CLASS:TscShellContainerClass;]")
    ReDim $a[UBound($a)][10]
    For $n = 1 To $a[0][0]
        $a[$n][2] = WinGetProcess($a[$n][1])
    Next
    ReDim $b[UBound($b)][10]
    For $n = 1 To $b[0][0]
        $b[$n][2] = WinGetProcess($b[$n][1])
    Next
    $a[0][1] = "BBarWindow"
    $a[0][2] = "PID"
    $a[0][3] = "TscShellContainer"
    $a[0][4] = "Full Screen"
    $a[0][5] = "Minimized"
    $a[0][6] = "X"
    $a[0][7] = "Y"
    $a[0][8] = "W"
    $a[0][9] = "H"
    For $n = 1 To $a[0][0]
        For $m = 1 To $b[0][0]
            If $a[$n][2] = $b[$m][2] Then ; same PID
                $a[$n][3] = $b[$m][1]
                $a[$n][0] = $b[$m][0]
            EndIf
        Next
    Next
    For $n = 1 To $a[0][0]
        $i = WinGetState($a[$n][1])
        $a[$n][4] = (BitAND($i, 2) = 2)
        $c = WinGetPos($a[$n][1])
        $i = WinGetState($a[$n][3])
        $a[$n][5] = (BitAND($i, 16) = 16)
        $c = WinGetPos($a[$n][3])
        $a[$n][6] = $c[0]
        $a[$n][7] = $c[1]
        $a[$n][8] = $c[2]
        $a[$n][9] = $c[3]
    Next
    Return $a
EndFunc   ;==>rdpWindowsStatus

 

Edited by argumentum
better code

Share this post


Link to post
Share on other sites

#312 ·  Posted

On 4/28/2017 at 4:18 AM, SmOke_N said:

 

; #FUNCTION# ====================================================================================================================
; Author ........: SmOke_N
; Modified.......:
; ===============================================================================================================================
#include-once
#include <GUIComboBoxEx.au3>
#include <GUIEdit.au3>

Func _GUICtrlComboBoxEx_AutoComplete($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    If Not __GUICtrlComboBox_IsPressed('08') And Not __GUICtrlComboBox_IsPressed("2E") Then ;backspace pressed or Del
        Local $hEXEdit = HWnd(_SendMessage($hWnd, $CBEM_GETEDITCONTROL))
        Local $sEditText = _GUICtrlEdit_GetText($hEXEdit)
        If StringLen($sEditText) Then
            Local $sList = _GUICtrlComboBoxEx_GetList($hWnd)
            Local $sDelim = "\" & Opt("GUIDataSeparatorChar")

            Local $aStr = StringRegExp($sList, "(?si)(?:^|" & $sDelim & ")(" & _
                $sEditText & ".*?)(?:\z|" & $sDelim & ")", 1)
            If IsArray($aStr) Then
                _GUICtrlEdit_SetText($hEXEdit, $aStr[0])
                _GUICtrlEdit_SetSel($hEXEdit, StringLen($sEditText), StringLen($aStr[0]))
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GUICtrlComboBoxEx_AutoComplete

@SmOke_N

How to use/call function?

 

Share this post


Link to post
Share on other sites

#313 ·  Posted (edited)

@dmob

I assume like _GUICtrlComboBox_AutoComplete ;)

Edited by nobbitry

Share this post


Link to post
Share on other sites

#314 ·  Posted

Here is something that I created while _IELoadWait wasn't working with the job in hand. Some explanation first, I was working on a website automation project, I decided to use the IE UDF naturally. The website that I am trying to automate uses Javascript to log me in (no page refresh, no submitting form to new page etc.) so _IELoadWait do any good for me :(.

Thanks to @TheSaint's excellent idea of checking for a piece of text that only appears after logging in (usually the username or the logout text). I present you _IEWaitForTagText!

; #FUNCTION# ====================================================================================================================
; Name ..........: _IEWaitForTagText
; Description ...: Waits for a HTML tag to appear with the specified text
; Syntax ........: _IEWaitForTagText($oObject, $sTagName, $sTagText[, $iTimeout = 0[, $bNoError = True]])
; Parameters ....: $oObject             - Object related to IE (Any Window, Frame, IFrame or any DOM object).
;                  $sTagName            - Name of the HTML tag (p, img, tr, etc).
;                  $sTagText            - The (inner) text of the tag to wait for.
;                  $iTimeout            - [optional] Timeout for the wait in milliseconds. Default is 0 (No timeout).
;                  $bNoError            - [optional] Temporarily disable IE errors messages in the console. Default is True.
; Return values .: Success: The DOM element's object
;                  Failure: False and @error is set to 1
; Author ........: Damon Harris (TheDcoder)
; Remarks .......: 1. Failure is impossible if $iTimeout is set to 0
;                  2. This is how $bNoError works:
;                     * If $bNoError is True, then _IEErrorNotify(False) is called and _IEErrorNotify(True) is called after the wait.
;                     * If $bNoError is True and _IEErrorNotify() is False, nothing will be changed.
;                     * If $bNoError is False, nothing will be changed.
; Related .......: _IELoadWait
; Link ..........: https://git.io/vHxOT
; Example .......: _IEWaitForTagText($oIE, "p", "logout")
; ===============================================================================================================================
Func _IEWaitForTagText($oObject, $sTagName, $sTagText, $iTimeout = 0, $bNoError = True)
    Local $oTags, $hTimer, $sText, $bTurnOnNotify = False
    If Not $iTimeout = 0 Then $hTimer = TimerInit()
    If $bNoError And _IEErrorNotify() Then
        _IEErrorNotify(False)
        $bTurnOnNotify = True
    EndIf
    Do
        $oTags = _IETagNameGetCollection($oObject, $sTagName)
        For $oTag In $oTags
            $sText = _IEPropertyGet($oTag, "innertext")
            If @error Then ContinueLoop
            If ($sText = $sTagText) Then
                If $bTurnOnNotify Then _IEErrorNotify(True)
                Return $oTag
            EndIf
            Sleep(10)
        Next
    Until ($iTimeout = 0) ? False : (TimerDiff($hTimer) >= $iTimeout)
    If $bTurnOnNotify Then _IEErrorNotify(True)
    Return SetError(1, 0, False)
EndFunc

I only did some basic testing, I would appreciate if someone could code a simple HTML page with Javascript which can create a new element after 3 secs and test this function in that page to see if it works. That would make a great example! :thumbsup:

Enjoy, TD :)

2 people like this

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

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#315 ·  Posted

9 hours ago, TheDcoder said:

Thanks to @TheSaint's excellent idea of checking for a piece of text that only appears after logging in (usually the username or the logout text).

Just pure logic dear Watson. :D

1 person likes this

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

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#316 ·  Posted (edited)

just for kicks,

 ALT+TAB a way for doing it simple
Compile if you will to test as is .. (pinned to the taskbar, best way to test this out)

#include <WindowsConstants.au3>
#include <WinAPI.au3>

WinActivate(_LastHWnd())

Func _LastHWnd() ;Simulate ALT+TAB
 $a = WinList('[REGEXPTITLE:(.+)]')
    For $x = 1 To UBound($a) - 1
        If BitAND(_WinAPI_GetWindowLong($a[$x][1], $GWL_EXSTYLE), $WS_EX_TOPMOST) Then ContinueLoop
        If Not BitAND(WinGetState($a[$x][1]), 2) Then ContinueLoop
        Do
            $x += 1
        Until BitAND(WinGetState($a[$x][1]), 2)
        Return $a[$x][1]
    Next
EndFunc   ;==>_AltTab

Edit: A more coherent example :

#include <WinAPI.au3>
Global $hWnd = WinGetHandle(AutoItWinGetTitle())

; Last active from hidden Hwnd
_LastHWnd()

; Last active from focussed Hwnd
_LastHWnd(1)

Func _LastHWnd($i = 0)
    For $i = $i To 1
        $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT)
        While Not BitAND(WinGetState($hWnd), 2) Or _WinAPI_GetClassName($hWnd) = "Alternate Owner"
            $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT)
        WEnd
    Next
    WinActivate($hWnd)
EndFunc   ;==>_LastHWnd

 

Edited by Deye

Share this post


Link to post
Share on other sites

#317 ·  Posted (edited)

; #FUNCTION# ====================================================================================================================
; Name ..........: ConvertTime12To24
; Description ...: Converts 12 hour time to 24 hour time, made while keeping _DateDiff's format in mind :) 
; Syntax ........: ConvertTime12To24($sTime, $sPeriod[, $sDelimiter = ':'])
; Parameters ....: $sTime               - Timestamp. (Can be a single digit or a pattern like H:M:S)
;                  $sPeriod             - AM or PM.
;                  $sDelimiter          - [optional] Separator between units of time. Default is ':'.
; Return values .: $sTime in 24 hour format with 0 padding
; Author ........: Damon Harris (TheDcoder)
; Remarks .......: Ensures that the first 3 parts have 0 padding if the time unit is single digit (Example 09 instead of 9)
; Link ..........: https://git.io/vdWnY
; Example .......: ConvertTime12To24('8:07:22', 'PM')
; ===============================================================================================================================
Func ConvertTime12To24($sTime, $sPeriod, $sDelimiter = ':')
    $aTime = StringSplit($sTime, ':')
    For $iElement = 1 To ($aTime[0] > 3 ? 3 : $aTime[0])
        $aTime[$iElement] = StringFormat('%.2i', Number($aTime[$iElement]))
    Next
    If $sPeriod = 'PM' Then $aTime[1] = StringFormat('%.2i', Number($aTime[1]) + 12)
    Return _ArrayToString($aTime, $sDelimiter, 1)
EndFunc

 

Edited by TheDcoder

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

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#318 ·  Posted (edited)

@TheDcoder

That can be reworked, probably one-lined even.  Here's part-way, working on zero-filling the seconds if not provided (and staying in one-line as to be competitive)

edit:  ive never seen a format when some provides a single digit minute or single digit second that seems like some edgy-ass edge cases

msgbox(0, '' , _ConvertTime12to24("8:34:23" , "PM"))

Func _ConvertTime12to24($sTime , $sPeriod)

 return StringRegExpReplace($sTime , "(\d+?)" , execute('$sPeriod = "AM" ? StringFormat("%.2i", Number(StringSplit($sTime, ":" , 2)[0])) : Number(StringSplit($sTime, ":" , 2)[0]) + 12') , 1)

EndFunc

 

Edited by iamtheky

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

Share this post


Link to post
Share on other sites

#319 ·  Posted

Not really a fan of one liners, I prefer more simple and understandable code :)

50 minutes ago, iamtheky said:

edit:  ive never seen a format when some provides a single digit minute or single digit second that seems like some edgy-ass edge cases

LOL :lol:. Yes, that is true. But my inner perfectionist wanted to handle all cases, you never know what a user might throw at you :P.

I made this snippet while working on a freelance project which I have to complete tomorrow, so it is a half-baked attempt :D


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

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#320 ·  Posted

ok, a couple of lines, no UDFs, no regex.

  

msgbox(0, '' , _ConvertTime12to24("8:34:30" , "PM"))  ;121
  msgbox(0, '' ,  _ConvertTime12to24("12:34:3" , "PM")) ;221
  msgbox(0, '' , _ConvertTime12to24("8:3:3" , "AM")) ;111

Func _ConvertTime12to24($sTime , $sPeriod)

    local $sOut

        for $i = 1 to 2
            $sOut &= $sPeriod = "AM" ? StringFormat("%.2i", stringleft($sTime , StringInStr($sTime , ":" , 0 , 1))) & ":" : StringFormat("%.2i", mod(stringleft($sTime , StringInStr($sTime , ":" , 0 , 1)) + 12 , 24)) & ":"
            $sTime = stringtrimleft($sTime , StringInStr($sTime , ":" , 0 , 1))
        next


    return $sOut & StringFormat("%.2i" , $sTime)  & " hrs"

EndFunc

 


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

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