Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/07/2021 in all areas

  1. This is a simple func I made to write colored text to a rich edit, and I thought someone else might find it useful. What it does is format the text into RTF syntax so you don't need to mess with selecting and setting the color and such with multiple commands. ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncAn example of it's use: #include <GuiRichEdit.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 331, 303, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 8, 240, 313, 21) $ButtonBob = GUICtrlCreateButton("Bob", 8, 264, 75, 25) $ButtonMar = GUICtrlCreateButton("Mary", 88, 264, 75, 25) $ButtonSus = GUICtrlCreateButton("Susan", 168, 264, 75, 25) $ButtonJoe = GUICtrlCreateButton("Joe", 248, 264, 75, 25) $RichEdit = _GUICtrlRichEdit_Create($Form1, "", 8, 8, 313, 225, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_READONLY)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $lastuser = "" demo() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonBob If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Bob", "993333", GUICtrlRead($Input1)) Case $ButtonJoe If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Joe", "339933", GUICtrlRead($Input1)) Case $ButtonSus If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Susan", "333399", GUICtrlRead($Input1)) Case $ButtonMar If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Mary", "339999", GUICtrlRead($Input1)) EndSwitch WEnd Func demo() _Chat_SendMessage("Bob", "993333", "Testin 123") _Chat_SendMessage("Bob", "993333", "Example script here") _Chat_SendMessage("Susan", "333399", "Enter something in the input and press a button") _Chat_SendMessage("Susan", "333399", "Try experimenting with it a bit") _Chat_SendMessage("Mary", "339999", "Messages between the same user are less spaced out than between other people") EndFunc ;use a function for wrapping messages with multiple parts of different formattings Func _Chat_SendMessage($user, $color, $text) Local $temp = ControlGetFocus($Form1) _GUICtrlRichEdit_AppendTextEx($RichEdit, $user&":", "Arial", $color, 10, 1) If $lastuser <> $user and $lastuser <> "" Then ; Add line spacing between users by using a taller font size for the space _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 15) Else ; Same width as 15, but only as tall as 10 :P _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 10) _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 5) EndIf _GUICtrlRichEdit_AppendTextEx($RichEdit, $text&@CRLF, "Arial", "000000", 10) $lastuser = $user ControlFocus($Form1, "", $temp) EndFunc ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncIf this was useful to you, or if you have any ideas / suggestions to make it better, let me know.
    1 point
  2. 1 point
  3. water -- that's it! Thank you!
    1 point
  4. in a more detailed fashion: Global $sResult = _TimeConvert('2021-03-30T21:01:05+00:00', _ ; your source time $__TIMECONVERT_CONVERT_UTC_TO_LOCAL, _ ; what you want to do with it - convert from UTC to local 'YYYY-MM-DDTHH:NN:SS', _ ; your source time format $__TIMECONVERT_FORMAT_LOGICAL) ; the desired output format (this is my favorite; choose your own, or omit for 14-digit string) ConsoleWrite($sResult & @CRLF) hope the comments deliver sufficient explanation.
    1 point
  5. Try the following -- Open your spreadsheet in Excel Press Ctrl+End Note that the selected cell changes to G10. This indicates that Excel thinks there is data somewhere other than A1, so IMO the behavior you are experiencing is correct. Edit: See here for details on how to fix
    1 point
  6. Then use caseless option : Local $a = ["7341S7","7341sX","D187sx"] For $s in $a If StringRegExp($s,"(?i)^[[:alnum:]]{4}s[\dx]$") then MsgBox(0, "", "This is ok.") Next
    1 point
  7. Not at all !
    1 point
  8. ... StringRegExp($x,'^[A-Za-z0-9]{4}S(X|[0-9])$') seems to work better . After the S, only the letter X or a number is allowed. If only capital letters should be permitted, then you can omit a-z : ... StringRegExp($x,'^([A-Z]|\d){4}S(X|\d)$') (the pattern can also be shortened)
    1 point
  9. $x = ClipGet() If StringRegExp($x,'^[a-z0-9]{4}S[a-z0-9]$') then MsgBox(0, "", "This is ok.") EndIf seems to work
    1 point
  10. I see If _Excel_BookAttach is successful (returning $oWorkbook) I use $oWorkbook.Application to get the correct Excel object for further processing. Excel allows to have multiple instances of Excel running at the same time. _Excel_BookAttach can return the workbook object from any of this instances.
    1 point
  11. How about now... #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Misc.au3> Local $hGui, $hRichEdit, $iMsg Local $hUser32 = DllOpen("user32.dll") $hGui = GUICreate("Hide caret example", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY )) _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text") GUISetState(@SW_SHOW) Local $aResult = DllCall($hUser32, "int", "HideCaret", "hwnd", $hRichEdit) ; <--- this hides caret While True $iMsg = GUIGetMsg() If _IsPressed("01", $hUser32) Then DllCall($hUser32, "int", "HideCaret", "hwnd", $hRichEdit) EndIf Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd
    1 point
  12. It look's like you've been hit by this bug: https://www.autoitscript.com/trac/autoit/ticket/3167 To work around the problem in your code, your code should look's like this: Local $oTemp = $sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]") $oTemp.caretPosition = 7 instead: $sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7
    1 point
  13. 1 point
  14. It's doable with the appropriate Rich Edit style : ... Global Const $ES_DISABLENOSCROLL = 0x2000 ; "Disables scroll bars instead of hiding them when they are not needed." (msdn) ... $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 40, 460, 200, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_DISABLENOSCROLL)) ;, $WS_EX_TRANSPARENT) ... This Rich Edit control style isn't found in AutoIt help file and it's commented in EditConstants.au3, maybe because it has the same value as another Edit control style. This is how I added it in Yashied's script (now maintained by argumentum) : Global Const $Style_RichEdit[8][2] = _ ; will also use plenty (not all) of Edit styles [[0x01000000, 'ES_SELECTIONBAR'], _ [0x00400000, 'ES_VERTICAL'], _ ; Asian-language support only (msdn) [0x00080000, 'ES_NOIME'], _ ; ditto [0x00040000, 'ES_SELFIME'], _ ; ditto [0x00008000, 'ES_SAVESEL'], _ [0x00004000, 'ES_SUNKEN'], _ [0x00002000, 'ES_DISABLENOSCROLL'], _ ; same value as 'ES_NUMBER' => issue ? [0x00000008, 'ES_NOOLEDRAGDROP']] ; same value as 'ES_UPPERCASE' but RichRdit controls do not support 'ES_UPPERCASE' style (msdn)
    1 point
  15. After Several Minutes searching the forums for a simple solution to calculating for the Unix Time, as required for another project I am working on, I was astonished to not find one clean and universal solution. After looking over the helpfile, I noticed one simple solution given in the example with _DateDiff(). However it did not account for my current timezone or daylight savings time. Without further ado... This is my example of Calculating for a current Unix Time stamp or seconds since Jan, 1st, 1970 00:00:00 GMT. This function will account for your timezone as well as for daylight savings time. Update: v0.3 -Added Function to revert a Unix Time stamp into Date form. -Added parameter to original _GetUnixTime() allowing for a custom date since Jan 1st 1970 to be passed and converted to Unix Time. #include <Date.au3> #include <Array.au3> #include <Constants.au3> Local $iUnixTime1 = _GetUnixTime() MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds Since Jan, 1st, 1970 00:00:00 GMT" & @CRLF & $iUnixTime1) Local $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp in Local Time" & @CRLF & $sUnixDate1) $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1, False) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp with $iReturnLocal = False which returns UTC Time" & @CRLF & $sUnixDate1) Local $iUnixTime2 = _GetUnixTime('2013/01/01 00:00:00') MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds since 2013/01/01 00:00:00" & @CRLF & $iUnixTime2) ; Get timestamp for input datetime (or current datetime). Func _GetUnixTime($sDate = 0);Date Format: 2013/01/01 00:00:00 ~ Year/Mo/Da Hr:Mi:Se Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $utcTime = "" If Not $sDate Then $sDate = _NowCalc() If Int(StringLeft($sDate, 4)) < 1970 Then Return "" If $aSysTimeInfo[0] = 2 Then ; if daylight saving time is active $utcTime = _DateAdd('n', $aSysTimeInfo[1] + $aSysTimeInfo[7], $sDate) ; account for time zone and daylight saving time Else $utcTime = _DateAdd('n', $aSysTimeInfo[1], $sDate) ; account for time zone EndIf Return _DateDiff('s', "1970/01/01 00:00:00", $utcTime) EndFunc ;==>_GetUnixTime ;$blTrim: Year in short format and no seconds. Func _GetDate_fromUnixTime($iUnixTime, $iReturnLocal = True) Local $aRet = 0, $aDate = 0 Local $aMonthNumberAbbrev[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] Local $timeAdj = 0 If Not $iReturnLocal Then Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $timeAdj = $aSysTimeInfo[1] * 60 If $aSysTimeInfo[0] = 2 Then $timeAdj += $aSysTimeInfo[7] * 60 EndIf $aRet = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $iUnixTime + $timeAdj ) If @error Or Not $aRet[0] Then Return "" $aDate = StringSplit(StringTrimRight($aRet[0], 1), " ", 2) Return $aDate[4] & "/" & StringFormat("%.2d", _ArraySearch($aMonthNumberAbbrev, $aDate[1])) & "/" & $aDate[2] & " " & $aDate[3] EndFunc ;==>_GetUnixDate Enjoy! Realm Update: >Added some functionality and a suggestion from FireFox
    1 point
  16. Wow, nice, i didn't knew this, thanks! MISIIM See this example (wich is corrected using Siao's tip): #include <GuiConstants.au3> $GUI = GUICreate("Test Edit") $Edit = GUICtrlCreateEdit("", 20, 50, 150, 150) $Button = GUICtrlCreateButton("Button", 20, 210) GUICtrlSetState(-1, $Gui_Focus) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit EndSwitch If _IsFocused($GUI, $Edit) Then Sleep(20) HotKeySet("{TAB}", "TabPress") Else HotKeySet("{TAB}") EndIf WEnd Func TabPress() ;$OldClip = ClipGet() ;ClipPut(@TAB) ;Send("+{INSERT}") ;ClipPut($OldClip) Send("^{TAB}") ;This is the tip from Siao - Thanks! EndFunc Func _IsFocused($hWnd, $nCID) Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd)) EndFunc
    1 point
  17. 1 point
×
×
  • Create New...