Jump to content

Recommended Posts

Posted (edited)

This "cow" seems funny to me,

JS9x1hc.png      vJ807at.png
At this link (https://dodona.ugent.be/en/activities/1605325419/#) a brief rough description of what this script can do (sorry for the laziness, but that description may be fine).
You can use the _CowSayWin() function to display a message formatted in a comic along with an ascii art figure in a standalone window,
or
you can use _String_CowSay() function to format a plain string in a comic along with an ascii art figure and have it returned in a string for your own purposes, you will probably use it in Consolewrite () or whatever ...

The script makes use of the _StringSize() function written by @Melba23 (thanks Melba) of the StringSize.au3 udf that you can extract from the zip file located at this link: https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/. You have to save that udf file in the same directory along with this script.
It also makes use of the _WinSetClientSize() function written by @KaFu. (thanks kafu) This function is already built into the main script.

I hope you have fun

#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <array.au3>
#include <String.au3>
#include "StringSize.au3" ; <-- https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/

_Example()

Func _Example()
    SRandom(@SEC)
    Local $hCowWin, $aMsg = 0
    Local $sMessage, $iWidth, $iClipart, $iTextAlig
    Local $aMessages[] = ["Bottled water companies don’t produce water, they produce plastic bottles.", _
            "The greatest glory in living lies not in never falling, but in rising every time we fall.", _
            "Your time is limited, so don't waste it living someone else's life. " & _
            "Don't be trapped by dogma which is living with the results of other people's thinking.", _
            "Insanity is doing the same thing over and over again and expecting different results", _
            "The way to get started is to quit talking and begin doing."]
    For $i = 1 To 6
        $sMessage = $aMessages[Random(0, UBound($aMessages) - 1, 1)]
        $iWidth = Random(21, 90, 1)
        $iClipart = Random(0, 3, 1)
        $iTextAlign = 1 ; Random(0, 2, 1) Left and right alignments are a bit ugly.
        ;                 they are allowed however if you need them
        ;
        ; You can use the _CowSayWin() function to create the "cowsay" message in a window
        $hCowWin = _CowSayWin($sMessage, $iWidth, $iClipart, $iTextAlign)
        ;
        ; or you can use the _String_CowSay() function to get a string of the "cowsay ascii clipart"
        ; so that you can use it however you like, probably in a Consolewrite () for example ...
        ConsoleWrite(_String_CowSay($sMessage, $iWidth, $iClipart, $iTextAlign) & @CRLF)
        While 1
            $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
            Switch $aMsg[1]
                Case $hCowWin
                    Switch $aMsg[0]
                        Case -3 ; $GUI_EVENT_CLOSE
                            ExitLoop
                    EndSwitch
            EndSwitch
        WEnd
        GUIDelete(HWnd($hCowWin))
    Next
EndFunc   ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _CowSayWin
; Description ...: Display a message in a standalone windows formatted in a balloon along with an ascii art figure
; Syntax ........: _CowSayWin($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The message to display (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The handle of the created window
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _CowSayWin($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1)
    If $iBoxLen < 21 Then $iBoxLen = 21
    Local $iSize = 12
    Local $iWeight = $FW_NORMAL
    Local $iAttrib = $GUI_FONTNORMAL
    Local $sFont = "Courier new"
    Local $sSay = _String_CowSay($sMsg, $iBoxLen, $iShape, $iAlign)
    Local $aMsgReturn = _StringSize($sSay, $iSize, $iWeight, $iAttrib, $sFont)
    Local $iXpos = (@DesktopWidth - $aMsgReturn[2]) / 2
    If $iXpos < 0 Then $iXpos = 0
    Local $iYpos = (@DesktopHeight - $aMsgReturn[3]) / 2
    If $iYpos < 0 Then $iYpos = 0
    Local $hCow = GUICreate("Cowsay", -1, -1, $iXpos, $iYpos, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ;0x94C803C5, 0x00010101) ; , $WS_EX_DLGMODALFRAME) ;0x94C803C5,  0x00010101) ; Style & ExStyle same as msgbox
    GUISetFont($iSize, $FW_NORMAL, $GUI_FONTNORMAL, $sFont)
    _WinSetClientSize($hCow, $aMsgReturn[2], $aMsgReturn[3])
    GUICtrlCreateLabel($sSay, 0, 0, $aMsgReturn[2], $aMsgReturn[3])
    GUISetState(@SW_SHOW, $hCow)
    #cs
    While 1
        Switch GUIGetMsg()
            Case -3 ; $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    #ce
    Return $hCow
EndFunc   ;==>_CowSayWin

; By kafu
; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141
Func _WinSetClientSize($hWnd, $iW, $iH)
    Local $aWinPos = WinGetPos($hWnd)
    Local $sRect = DllStructCreate("int;int;int;int;")
    DllStructSetData($sRect, 3, $iW)
    DllStructSetData($sRect, 4, $iH)
    _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE))
    WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize


; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToColumn
; Description ...: passing a (long) string and a value, it returns that same string
;                  formatted in a column as wide as the value (string is split by @CRs).
;                  Whenever possible, it tries not to break the words but to split
;                  lines in between two words
; Syntax ........: _StringToColumn($sString[, $x = 21])
; Parameters ....: $sString             - a string value. The string to format
;                  $iColumnWidth        - [optional] an integer value. Default is 21.
;                                         The wanted width of the text column
; Return values .: The string formatted as required
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToColumn($sString, $iColumnWidth = 21)
    If $iColumnWidth < 1 Then $iColumnWidth = 1
    Local $iPreviousSplit = 1
    Local $i = $iColumnWidth
    While $i <= StringLen($sString)
        $iSplitPoint = StringInStr($sString, " ", 0, -1, $i + 1)
        If $iSplitPoint = 0 Or $iSplitPoint <= $iPreviousSplit Then
            $iSplitPoint = $i
            $sString = StringLeft($sString, $iSplitPoint) & @CR & StringMid($sString, $iSplitPoint + 1)
            $i = $iSplitPoint + 1
        Else
            $sString = StringReplace($sString, $iSplitPoint, @CR)
            $i = $iSplitPoint
        EndIf
        $iPreviousSplit = $iSplitPoint
        $i += $iColumnWidth
    WEnd
    If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1)
    Return $sString
EndFunc   ;==>_StringToColumn

; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToFrame
; Description ...: places borders only to the left and to the right of the passed string block
; Syntax ........: _StringToFrame($sStr, $iFrameWidth[, $iAlign = 1[, $sV = "|"]])
; Parameters ....: $sStr                - The string to format; multiline string must be splitted by a @cr.
;                  $iFrameWidth         - wanted Width of the frame
;                                         If the desired width is less than the length of the string, the exceeding part is cut off
;                                         If the desired width is wider than the length of the string, spaces are added
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         The string is justified within the frame based on the value of the $iAlign variable, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
;                  $sV                  - [optional] a string value. Default is "|".
;                                         This is the character used to draw the two vertical edges
; Return values .: The formatted string
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToFrame($sStr, $iFrameWidth, $iAlign = 1, $sV = "|") ; $iAlign: 0=Left; 1=Center; 2=Right
    If $iFrameWidth < 1 Then $iFrameWidth = 1
    Local $a = StringSplit($sStr, @CR, 2) ; 2 =  $STR_NOCOUNT
    For $i = 0 To UBound($a) - 1
        Switch $iAlign
            Case 1 ; Center string
                $a[$i] = $sV & _StringSetLen(_StringCenter($a[$i], $iFrameWidth), $iFrameWidth) & $sV
            Case 2 ; Align to right
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth * -1) & $sV
            Case Else ; otherwise Align to left
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth) & $sV
        EndSwitch
    Next
    Return _ArrayToString($a, @CR)
EndFunc   ;==>_StringToFrame

; passing a string and a value it returns that string with a len as required
; By Gianni Addiego
Func _StringSetLen($sString, $iWantedLen = 1, $sFillChr = " ")
    If $iWantedLen = 0 Then Return ""
    Local $iLen = StringLen($sString)
    Local $iKeepLeft = $iWantedLen > 0 ; else keep the right side of the string
    $iWantedLen = Abs($iWantedLen)
    If $iLen >= $iWantedLen Then ; reduce the string length
        If $iKeepLeft Then
            Return StringLeft($sString, $iWantedLen)
        Else
            Return StringRight($sString, $iWantedLen)
        EndIf
    Else ; add chars to the string to reach the wanted len
        If $iKeepLeft Then
            Return $sString & _StringRepeat($sFillChr, $iWantedLen - $iLen)
        Else
            Return _StringRepeat($sFillChr, $iWantedLen - $iLen) & $sString
        EndIf
    EndIf
EndFunc   ;==>_StringSetLen

; place a string in the middle of a given space
; By Gianni Addiego
Func _StringCenter($sString, $iSpace)
    Local $iLen = StringLen($sString)
    $iHloc = Int($iSpace / 2) - Int($iLen / 2)
    If $iHloc < 0 Then
        Return StringMid($sString, Abs($iHloc) + 1, $iSpace)
    Else
        Return _StringRepeat(" ", $iHloc) & $sString
    EndIf
EndFunc   ;==>_StringCenter

; #FUNCTION# ====================================================================================================================
; Name ..........: _String_CowSay
; Description ...: Formats a string in a balloon along with an ascii art figure
; Syntax ........: _String_CowSay($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The String to format (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The passed string formatted in the required format.
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _String_CowSay($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) ; minimum $iBoxLen is 21
    If $iBoxLen / 2 = Int($iBoxLen / 2) Then $iBoxLen += 1
    If $iBoxLen < 22 Then
        $x = 0
    Else
        $x = Ceiling(($iBoxLen - 21) / 2)
    EndIf
    Local $sS = _StringRepeat(" ", $x), $sT = _StringRepeat("~", $x)
    Local $sHeader, $sFooter
    Switch $iShape
        Case 1
            $sHeader = _
                    $sS & "         \|||/" & @CRLF & _
                    $sS & "         (o o)" & @CRLF & _
                    "," & $sT & "oo0~~~~~~(_)~~~~~~~~~" & $sT & "," & @CRLF ; header

            $sFooter = _
                    "'" & $sT & "~~~~~~~~~~~~~~~~~~oo0" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "        |__|__|" & @CRLF & _
                    $sS & "         || ||" & @CRLF & _
                    $sS & "        oo0 0oo"
        Case 2
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \    .--." & @CRLF & _
                    "         \  |o_o |" & @CRLF & _
                    "            |:_/ |" & @CRLF & _
                    "           //   \ \" & @CRLF & _
                    "          (|     | )" & @CRLF & _
                    "         /'\_   _/`\" & @CRLF & _
                    "         \___)=(___/"
        Case 3
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'" & $sT & "oo0~~~~~~~~~~~~~~~0oo" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "  \\               //" & @CRLF & _
                    $sS & "  > \   \\|||//   / <" & @CRLF & _
                    $sS & "   > \   _   _   / <" & @CRLF & _
                    $sS & "    > \ / \ / \ / <" & @CRLF & _
                    $sS & "     > \\_o_o_// <" & @CRLF & _
                    $sS & "      > ( (_) ) <" & @CRLF & _
                    $sS & "       >|     |<" & @CRLF & _
                    $sS & "      / |\___/| \" & @CRLF & _
                    $sS & "      / (_____) \" & @CRLF & _
                    $sS & "       /   o   \" & @CRLF & _
                    $sS & "        ) ___ (" & @CRLF & _
                    $sS & "       / /   \ \" & @CRLF & _
                    $sS & "      ( /     \ )" & @CRLF & _
                    $sS & "      ><       ><" & @CRLF & _
                    $sS & "     ///\     /\\\" & @CRLF & _
                    $sS & "     '''       '''"
        Case Else
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \   ^__^" & @CRLF & _
                    "         \  (oo)\_______" & @CRLF & _
                    "            (__)\       )\/\" & @CRLF & _
                    "                ||----w |" & @CRLF & _
                    "                ||     ||"
    EndSwitch

    Return $sHeader & _StringToFrame(_StringToColumn($sMsg, $iBoxLen), $iBoxLen, $iAlign) & @CRLF & $sFooter
EndFunc   ;==>_String_CowSay

 

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
Posted (edited)

Nice.
Thanks for sharing.

Some minior fix:

;~ https://www.autoitscript.com/forum/topic/205659-cow-say/

#include <array.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
;~ #include "StringSize.au3" ; <-- https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/
#include "Z:\!!!_SVN_AU3\UDF_Forum\Other_Members\StringSize.au3" ; < - -https : / / www.autoitscript.com / forum / topic / 114034 - stringsize - m23 - new - version - 16 - aug - 11 /

_Example()

Func _Example()
    SRandom(@SEC)
    Local $hCowWin, $aMsg = 0
    Local $sMessage, $iWidth, $iClipart, $iTextAlign
    Local $aMessages[] = ["Bottled water companies don’t produce water, they produce plastic bottles.", _
            "The greatest glory in living lies not in never falling, but in rising every time we fall.", _
            "Your time is limited, so don't waste it living someone else's life. " & _
            "Don't be trapped by dogma which is living with the results of other people's thinking.", _
            "Insanity is doing the same thing over and over again and expecting different results", _
            "The way to get started is to quit talking and begin doing."]
    For $i = 1 To 6
        $sMessage = $aMessages[Random(0, UBound($aMessages) - 1, 1)]
        $iWidth = Random(21, 90, 1)
        $iClipart = Random(0, 3, 1)
        $iTextAlign = 1 ; Random(0, 2, 1) Left and right alignments are a bit ugly.
        ;                 they are allowed however if you need them
        ;
        ; You can use the _CowSayWin() function to create the "cowsay" message in a window
        $hCowWin = _CowSayWin($sMessage, $iWidth, $iClipart, $iTextAlign)
        ;
        ; or you can use the _String_CowSay() function to get a string of the "cowsay ascii clipart"
        ; so that you can use it however you like, probably in a Consolewrite () for example ...
        ConsoleWrite(_String_CowSay($sMessage, $iWidth, $iClipart, $iTextAlign) & @CRLF)
        While 1
            $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
            Switch $aMsg[1]
                Case $hCowWin
                    Switch $aMsg[0]
                        Case -3 ; $GUI_EVENT_CLOSE
                            ExitLoop
                    EndSwitch
            EndSwitch
        WEnd
        GUIDelete(HWnd($hCowWin))
    Next
EndFunc   ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _CowSayWin
; Description ...: Display a message in a standalone windows formatted in a balloon along with an ascii art figure
; Syntax ........: _CowSayWin($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The message to display (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The handle of the created window
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _CowSayWin($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1)
    If $iBoxLen < 21 Then $iBoxLen = 21
    Local $iSize = 12
    Local $iWeight = $FW_NORMAL
    Local $iAttrib = $GUI_FONTNORMAL
    Local $sFont = "Courier new"
    Local $sSay = _String_CowSay($sMsg, $iBoxLen, $iShape, $iAlign)
    Local $aMsgReturn = _StringSize($sSay, $iSize, $iWeight, $iAttrib, $sFont)
    Local $iXpos = (@DesktopWidth - $aMsgReturn[2]) / 2
    If $iXpos < 0 Then $iXpos = 0
    Local $iYpos = (@DesktopHeight - $aMsgReturn[3]) / 2
    If $iYpos < 0 Then $iYpos = 0
    Local $hCow = GUICreate("Cowsay", -1, -1, $iXpos, $iYpos, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ;0x94C803C5, 0x00010101) ; , $WS_EX_DLGMODALFRAME) ;0x94C803C5,  0x00010101) ; Style & ExStyle same as msgbox
    GUISetFont($iSize, $FW_NORMAL, $GUI_FONTNORMAL, $sFont)
    _WinSetClientSize($hCow, $aMsgReturn[2], $aMsgReturn[3])
    GUICtrlCreateLabel($sSay, 0, 0, $aMsgReturn[2], $aMsgReturn[3])
    GUISetState(@SW_SHOW, $hCow)
    #cs
    While 1
        Switch GUIGetMsg()
            Case -3 ; $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    #ce
    Return $hCow
EndFunc   ;==>_CowSayWin

; By kafu
; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141
Func _WinSetClientSize($hWnd, $iW, $iH)
    Local $aWinPos = WinGetPos($hWnd)
    Local $sRect = DllStructCreate("int;int;int;int;")
    DllStructSetData($sRect, 3, $iW)
    DllStructSetData($sRect, 4, $iH)
    _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE))
    WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize


; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToColumn
; Description ...: passing a (long) string and a value, it returns that same string
;                  formatted in a column as wide as the value (string is split by @CRs).
;                  Whenever possible, it tries not to break the words but to split
;                  lines in between two words
; Syntax ........: _StringToColumn($sString[, $x = 21])
; Parameters ....: $sString             - a string value. The string to format
;                  $iColumnWidth        - [optional] an integer value. Default is 21.
;                                         The wanted width of the text column
; Return values .: The string formatted as required
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToColumn($sString, $iColumnWidth = 21)
    If $iColumnWidth < 1 Then $iColumnWidth = 1
    Local $iPreviousSplit = 1
    Local $i = $iColumnWidth
    Local $iSplitPoint
    While $i <= StringLen($sString)
        $iSplitPoint = StringInStr($sString, " ", 0, -1, $i + 1)
        If $iSplitPoint = 0 Or $iSplitPoint <= $iPreviousSplit Then
            $iSplitPoint = $i
            $sString = StringLeft($sString, $iSplitPoint) & @CR & StringMid($sString, $iSplitPoint + 1)
            $i = $iSplitPoint + 1
        Else
            $sString = StringReplace($sString, $iSplitPoint, @CR)
            $i = $iSplitPoint
        EndIf
        $iPreviousSplit = $iSplitPoint
        $i += $iColumnWidth
    WEnd
    If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1)
    Return $sString
EndFunc   ;==>_StringToColumn

; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToFrame
; Description ...: places borders only to the left and to the right of the passed string block
; Syntax ........: _StringToFrame($sStr, $iFrameWidth[, $iAlign = 1[, $sV = "|"]])
; Parameters ....: $sStr                - The string to format; multiline string must be splitted by a @cr.
;                  $iFrameWidth         - wanted Width of the frame
;                                         If the desired width is less than the length of the string, the exceeding part is cut off
;                                         If the desired width is wider than the length of the string, spaces are added
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         The string is justified within the frame based on the value of the $iAlign variable, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
;                  $sV                  - [optional] a string value. Default is "|".
;                                         This is the character used to draw the two vertical edges
; Return values .: The formatted string
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToFrame($sStr, $iFrameWidth, $iAlign = 1, $sV = "|") ; $iAlign: 0=Left; 1=Center; 2=Right
    If $iFrameWidth < 1 Then $iFrameWidth = 1
    Local $a = StringSplit($sStr, @CR, 2) ; 2 =  $STR_NOCOUNT
    For $i = 0 To UBound($a) - 1
        Switch $iAlign
            Case 1 ; Center string
                $a[$i] = $sV & _StringSetLen(_StringCenter($a[$i], $iFrameWidth), $iFrameWidth) & $sV
            Case 2 ; Align to right
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth * -1) & $sV
            Case Else ; otherwise Align to left
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth) & $sV
        EndSwitch
    Next
    Return _ArrayToString($a, @CR)
EndFunc   ;==>_StringToFrame

; passing a string and a value it returns that string with a len as required
; By Gianni Addiego
Func _StringSetLen($sString, $iWantedLen = 1, $sFillChr = " ")
    If $iWantedLen = 0 Then Return ""
    Local $iLen = StringLen($sString)
    Local $iKeepLeft = $iWantedLen > 0 ; else keep the right side of the string
    $iWantedLen = Abs($iWantedLen)
    If $iLen >= $iWantedLen Then ; reduce the string length
        If $iKeepLeft Then
            Return StringLeft($sString, $iWantedLen)
        Else
            Return StringRight($sString, $iWantedLen)
        EndIf
    Else ; add chars to the string to reach the wanted len
        If $iKeepLeft Then
            Return $sString & _StringRepeat($sFillChr, $iWantedLen - $iLen)
        Else
            Return _StringRepeat($sFillChr, $iWantedLen - $iLen) & $sString
        EndIf
    EndIf
EndFunc   ;==>_StringSetLen

; place a string in the middle of a given space
; By Gianni Addiego
Func _StringCenter($sString, $iSpace)
    Local $iLen = StringLen($sString)
    Local $iHloc = Int($iSpace / 2) - Int($iLen / 2)
    If $iHloc < 0 Then
        Return StringMid($sString, Abs($iHloc) + 1, $iSpace)
    Else
        Return _StringRepeat(" ", $iHloc) & $sString
    EndIf
EndFunc   ;==>_StringCenter

; #FUNCTION# ====================================================================================================================
; Name ..........: _String_CowSay
; Description ...: Formats a string in a balloon along with an ascii art figure
; Syntax ........: _String_CowSay($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The String to format (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The passed string formatted in the required format.
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _String_CowSay($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) ; minimum $iBoxLen is 21
    If $iBoxLen / 2 = Int($iBoxLen / 2) Then $iBoxLen += 1
    Local $x
    If $iBoxLen < 22 Then
        $x = 0
    Else
        $x = Ceiling(($iBoxLen - 21) / 2)
    EndIf
    Local $sS = _StringRepeat(" ", $x), $sT = _StringRepeat("~", $x)
    Local $sHeader, $sFooter
    Switch $iShape
        Case 1
            $sHeader = _
                    $sS & "         \|||/" & @CRLF & _
                    $sS & "         (o o)" & @CRLF & _
                    "," & $sT & "oo0~~~~~~(_)~~~~~~~~~" & $sT & "," & @CRLF ; header

            $sFooter = _
                    "'" & $sT & "~~~~~~~~~~~~~~~~~~oo0" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "        |__|__|" & @CRLF & _
                    $sS & "         || ||" & @CRLF & _
                    $sS & "        oo0 0oo"
        Case 2
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \    .--." & @CRLF & _
                    "         \  |o_o |" & @CRLF & _
                    "            |:_/ |" & @CRLF & _
                    "           //   \ \" & @CRLF & _
                    "          (|     | )" & @CRLF & _
                    "         /'\_   _/`\" & @CRLF & _
                    "         \___)=(___/"
        Case 3
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'" & $sT & "oo0~~~~~~~~~~~~~~~0oo" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "  \\               //" & @CRLF & _
                    $sS & "  > \   \\|||//   / <" & @CRLF & _
                    $sS & "   > \   _   _   / <" & @CRLF & _
                    $sS & "    > \ / \ / \ / <" & @CRLF & _
                    $sS & "     > \\_o_o_// <" & @CRLF & _
                    $sS & "      > ( (_) ) <" & @CRLF & _
                    $sS & "       >|     |<" & @CRLF & _
                    $sS & "      / |\___/| \" & @CRLF & _
                    $sS & "      / (_____) \" & @CRLF & _
                    $sS & "       /   o   \" & @CRLF & _
                    $sS & "        ) ___ (" & @CRLF & _
                    $sS & "       / /   \ \" & @CRLF & _
                    $sS & "      ( /     \ )" & @CRLF & _
                    $sS & "      ><       ><" & @CRLF & _
                    $sS & "     ///\     /\\\" & @CRLF & _
                    $sS & "     '''       '''"
        Case Else
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \   ^__^" & @CRLF & _
                    "         \  (oo)\_______" & @CRLF & _
                    "            (__)\       )\/\" & @CRLF & _
                    "                ||----w |" & @CRLF & _
                    "                ||     ||"
    EndSwitch

    Return $sHeader & _StringToFrame(_StringToColumn($sMsg, $iBoxLen), $iBoxLen, $iAlign) & @CRLF & $sFooter
EndFunc   ;==>_String_CowSay

 

And I notice one small issue:
in SciTE console I get:

Quote

|  Bottled water companies  dont produce water, they |

instead:

Quote

|  Bottled water companies  don't produce water, they |

Wondering why ?
 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Share this post


Link to post
Share on other sites

Hi mLipok, thanks for the feedback,

13 hours ago, mLipok said:

And I notice one small issue:

in SciTE console I get:

|  Bottled water companies  dont produce water, they |

instead:

|  Bottled water companies  don't produce water, they |

Wondering why ?
 

I have no idea, this does not occur on my system.

13 hours ago, mLipok said:

Some minior fix:

p.s.
.... ? but what have you fixed? :think:


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
Posted (edited)
12 minutes ago, Chimp said:

but what have you fixed?

Variable declarations....
for example:

Local $sMessage, $iWidth, $iClipart, $iTextAlign

instead:

Local $sMessage, $iWidth, $iClipart, $iTextAlig

and few others.


Check your script with:

#AutoIt3Wrapper_Run_AU3Check=Y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

And you will see.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Share this post


Link to post
Share on other sites
Posted (edited)
10 minutes ago, mLipok said:

hmmm interesting, yes, now I can see,
nice, thanks :)

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

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.

  • Similar Content

    • By Chimp
      Happy holidays to all
      p.s.
      It looks best on a solid, homogeneous background.
      To move the tree click on the colored balls and drag.
      To "turn off" the tree click on it (to set the focus) and then press esc
      Have fun
      #include <GUIConstants.au3> #include <WinAPISys.au3> HotKeySet("{ESC}", "_TheEnd") Global $AlphaKey = 0x000000, $hLayer[6], $iWidth = 310, $iHeight = 290, $sBall = '♥' Global Const $aColors[6] = [0x00FF00, 0XFF0000, 0X0040FF, 0XFFFF00, 0X00FFFF, 0XFF00FF] ; 0xRRGGBB Global $a[] = ['.', '~', "'", $sBall, "'", '~', '.', '*', ' '], $tree = $a[8] & $a[7] & @CRLF, _ $hTreeGUI, $ndx, $sGotString, $sGetString, $ChristmasBalls, $sRandomBalls, $iNrOfBalls, $vDummy $hTreeGUI = GUICreate('', $iWidth, $iHeight, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetBkColor($AlphaKey, $hTreeGUI) _WinAPI_SetLayeredWindowAttributes($hTreeGUI, $AlphaKey, 0, $LWA_COLORKEY) GUISetState() For $i = 0 To 14 $tree &= StringRight($a[8], 15 - ($i + 1)) For $x = 0 To ($i + 1) * 2 $tree &= $a[Mod($ndx, 7)] $ndx += 1 Next $tree &= @CRLF If $i < 6 Then $hLayer[$i] = GUICtrlCreateLabel("", 0, 0, $iWidth, $iHeight, -1, $GUI_WS_EX_PARENTDRAG) $vDummy = GUICtrlSetFont(-1, 12, 800, 0, "Courier new") + GUICtrlSetColor(-1, $aColors[$i]) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) EndIf Next ; RegExp thanks to @seadoggie01 https://www.autoitscript.com/forum/topic/200770-how-to-clean-a-string-by-regexp/?do=findComment&comment=1440488 $ChristmasBalls = StringRegExpReplace($tree, "(*UCP)(?s)[^\Q" & $sBall & @CRLF & "\E]", " ") ; keep only balls StringReplace($ChristmasBalls, $sBall, $sBall) $iNrOfBalls = @extended GUICtrlSetData($hLayer[0], $tree) ; StringRegExpReplace($tree, "(*UCP)(?s)[\Q" & $a[7] & "\E]", " ")) While Sleep(2000) $sRandomBalls = $ChristmasBalls $RemainingBalls = $iNrOfBalls For $i = 1 To Random(5, $RemainingBalls - 5, 1) $sRandomBalls = StringReplace($sRandomBalls, StringInStr($sRandomBalls, $sBall, 0, Random(1, $RemainingBalls, 1)), " ") $RemainingBalls -= 1 Next For $i = 1 To 5 $sGetString = GUICtrlRead($hLayer[$i]) ; StringReplace(GUICtrlRead($hLayer[$i]), $a[7], " ") $sGotString = $sGetString For $ii = 1 To $RemainingBalls If StringMid($sGetString, StringInStr($sRandomBalls, $sBall, 0, $ii), 1) = $sBall Then $sGetString = StringReplace($sGetString, StringInStr($sRandomBalls, $sBall, 0, $ii), " ") EndIf Next If $sGotString <> $sGetString Then GUICtrlSetData($hLayer[$i], $sGetString) Next GUICtrlSetData($hLayer[Random(1, 5, 1)], $sRandomBalls) WEnd Func _TheEnd() If WinActive("[ACTIVE]") = $hTreeGUI Then Exit GUIDelete($hTreeGUI) EndFunc ;==>_TheEnd  
    • By Stew
      (Edited from original.  Please note that I AM NOT AN AUTOIT EXPERT.  I write code using Autoit frequently but I am no expert, especially when it comes to I/O.  So any remarks that start with "Why did you..." can be answered by referring to the first sentence.  This project was done in Autoit because of an interface I built to display the data.)
      Attached is a program and ascii input file I wrote to read stock price data, convert it to binary and then read it back into the program in binary.  The goal was to show increased performance for reading the files in binary and provide a demo on how to read/write binary for int32, int64, double and strings for anyone who might find it helpful.  The results on my PC show the following:
      Time to read ascii file only: 456.981951167202
      Ascii read & process time: 6061.83075631701
      Binary write file time: 14787.9184635239
      Time just to read binary file: 42.418867292311
      Binary read and process time: 4515.16129830537
      A couple things to note:
      1) The 32 MB ascii file took 10x longer to read than the 15 MB binary file.  Not entirely sure why.  Both were read into a buffer.
      2) The Binary write takes a long time but I made no effort to optimize this because the plan was to write this file one time only so I don't mind if it takes longer to write this file.  I care much more about how long it takes to read the file because I will be reading it many times.
      3) There was a modest gain in converting the ascii file to binary in terms of file size and reading speed.
      So big picture... not sure it's worth the effort to convert the files to binary even though most of the data is numerical data in the binary file.  That was actually surprising as I expected there would be more of a difference.  Any ideas on how to get the binary data to read at a faster rate would be great.
       
      binary.au3
      2019_02_08.zip
    • By Chimp
      A simple endless kaleidoscope made  on a RichEdit control (hit esc to exit)
      Idea is from this link: http://www.calormen.com/jsbasic/ select the "Rod's Color Pattern" demo and run it on the Apple 2 emulator on that web page to see the original Apple II version.
      ; Idea from this link: http://www.calormen.com/jsbasic/ ; get the "Rod's Color Pattern" from the "Select a sample..." combo and run it ; #include <GuiRichEdit.au3> #include <GUIConstants.au3> HotKeySet("{ESC}", "_TheEnd") ; Global $iHwidth = 40, $iVheight = 40; width and height of screen Global $sBuffer = _StringReplay(_StringReplay(" ", $iHwidth + 1) & @CRLF, $iVheight) ;to fill the RichEdit Global $sChar = " " Global Const $aApplesoft_color[16] = [ _ ; LoRes colors in Applesoft basic 0x000000, _ ; 0x0 = 00 = Black 0XFF00FF, _ ; 0x1 = 01 = Magenta 0X0000A0, _ ; 0x2 = 02 = Dark Blue 0X800080, _ ; 0x3 = 03 = Purple 0X006400, _ ; 0x4 = 04 = Dark Green 0X808080, _ ; 0x5 = 05 = Grey 0X0000CD, _ ; 0x6 = 06 = Medium Blue 0XADD8E6, _ ; 0x7 = 07 = Light Blue 0XA52A2A, _ ; 0x8 = 08 = Brown 0XFFA500, _ ; 0x9 = 09 = Orange 0XD3D3D3, _ ; 0xA = 10 = Light Grey 0XFFC0CB, _ ; 0xB = 11 = Pink 0X008000, _ ; 0xC = 12 = Green 0XFFFF00, _ ; 0xD = 13 = Yellow 0X00FFFF, _ ; 0xE = 14 = Aqua 0xFFFFFF]; ; 0xF = 15 = White Global $MyGui = GUICreate("", 335, 630, -1, -1, $WS_POPUPWINDOW, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE, $WS_EX_COMPOSITED, $WS_EX_LAYERED)) $hGlass = GUICtrlCreateLabel("", 0, 0, 335, 630, -1, $GUI_WS_EX_PARENTDRAG) ; Protect the RichEdit and allows to drag the GUI around GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; This is like a glass over the underlying RichEdit GUICtrlSetCursor(-1, 2) ; Cursor is an arrow (instead of the default I-beam) ; ; This RichEdit is used to simulate the LoRes Graphic of tha Apple 2 (40x40 pixels) Global $hGR = _GUICtrlRichEdit_Create($MyGui, $sBuffer, 0, 0, 335, 630, BitOR($ES_READONLY, $ES_MULTILINE)) _GUICtrlRichEdit_SetSel($hGR, 0, -1) _GUICtrlRichEdit_SetFont($hGR, 10, "Courier new") _GUICtrlRichEdit_SetBkColor($hGR, 0xffffff) GUISetState() ; Main loop ; --------- While 1 For $W = 3 To 50 For $x = 19 To 1 Step -1 For $y = 19 To 0 Step -1 $xy = $x + $y $iColor = Mod(Int($y * 3 / ($x + 3) + $x * $W / 12), 16) $sChar = ChrW(32 + $iColor) ; comment this if you don't want chars (only color) If $iColor > 15 Then $iColor = 15 Print($sChar, $x, $xy, $iColor) Print($sChar, $xy, $x, $iColor) Print($sChar, 40 - $x, 40 - $xy, $iColor) Print($sChar, 40 - $xy, 40 - $x, $iColor) Print($sChar, $xy, 40 - $x, $iColor) Print($sChar, 40 - $x, $xy, $iColor) Print($sChar, $x, 40 - $xy, $iColor) Print($sChar, 40 - $xy, $x, $iColor) Next Next Next WEnd ; Print a char to Htab (Horiz. pos), Vtab (Vert pos) on the RichEdit ; ------------------------------------------------------------------ Func Print($sChar = "", $iHtab = 1, $iVtab = 1, $iColor = 0xffffff) _GUICtrlRichEdit_SetSel($hGR, GetAbsPos($iHtab, $iVtab), GetAbsPos($iHtab, $iVtab) + 1, True) _GUICtrlRichEdit_SetCharBkColor($hGR, $aApplesoft_color[$iColor]) _GUICtrlRichEdit_ReplaceText($hGR, $sChar, False) EndFunc ;==>Print ; From Htab Vtab (1 based) to Absolute position within the RichEdit ; ----------------------------------------------------------------- Func GetAbsPos($iHtab = 1, $iVtab = 1, $iScreenWidth = $iHwidth) Return ($iVtab - 1) * ($iScreenWidth + 2) + $iHtab EndFunc ;==>GetAbsPos ; returns one or more chars replicated n times ; Example: ConsoleWrite(_StringReplay('*', 5) & @CRLF) Func _StringReplay($sChars = "", $iRepeats = 0) $sChars = String($sChars) $iRepeats = Int(Abs(Number($iRepeats))) Return StringReplace(StringFormat('%' & $iRepeats & 's', ""), " ", $sChars) EndFunc ;==>_StringReplay Func _TheEnd() If WinActive("[ACTIVE]") = $MyGui Then _GUICtrlRichEdit_Destroy($hGR) Exit EndIf EndFunc ;==>_TheEnd  
    • By fopetesl
      Need to read a small file which looks like
      01 01 01 00 21 21 48 4F ����!HHO (cut from hexedit) First four are binary but don't show, last four are ascii "!HHO"
      I have tried to split the file and look for the ascii string but not succeeded:
      ; Set the working directory ... or set PATH! ... FileChangeDir("C:\S3_GUI\ncat\") ; Run(@ComSpec & " /k " & "C:\S3_GUI\ncat\Home.bat", "", @SW_HIDE);;comment: not over write Local $hFileOpen = FileOpen("C:\S3_GUI\ncat\homerep", $FO_READ) ;; homerep Local $sFileRead = FileRead($hFileOpen) Local $Comp = StringInStr ($sFileRead,"!HHO",1,4) If( $Comp = 1) Then MsgBox($MB_OK, "Head is Home", "!HHO") Else MsgBox($MB_OK, "Head not Home!","!HHx") EndIf Fails every time.
      If I open it as binary then I lose the ascii?
      I've been advised to include the whole file but it's getting big. You need to see it all?
    • By TheSaint
      I had a need, and so I developed.
      Before I did that though, I did a quick search of the forum, and found a few things, but none seemed to suit what I really wanted ... though to be honest, I did not investigate them deeply or search extensively. In any case, I am not very good at modifying the code of others, nor do I enjoy doing so, so in the end I decided it was best to start from scratch ... re-inventing the wheel perhaps, but a wheel I feel a certain degree of comfort with. I also thought about Maps, but don't know enough.
      _IniString Functions (was Ini_InMem)
      Ini in memory
      Settings INI - Read/Write once to the disk
      INI File Processing Functions
      ... sure to be others.
      As with all my stuff, feel free to use (no guarantees) or modify ... just give me credit where due.
      I always go for the quick & simple approach, as those who know me here, are well aware, so without a doubt, my code could be improved - sped up, RegExp used, etc. So feel free to do that, and convert into a proper UDF, if you want, following best practices etc, as I am sure others will appreciate it.
      Recently, I have come upon a need to extract data from an approximately 50 Mb downloaded Index file, just extracting the few elements I need, and storing them in an INI file. It is quite a time consuming process, especially on my underpowered Netbook, which is where I am using the program I built. I have been considering ways to speed up things. Two good sounding methods, out of several possibles, have come to mind - 1) RAM Disk and 2) Virtual INI processing. That last being a better option, when sharing code (program) with others.
      Another method, which I am currently using, that did give me some measurable benefit, was to download the almost 50 Mb Index file in Stages (i.e. 30 x 1.4 Mb roughly), extracting data from each in turn. I have also considered extracting to 10 (or 11) separate INI files, rather than the single large INI file (4~5 Mb), as things noticeably slow up as the INI file increases in size ... obviously due to writing time.
      I can't really speed up the extraction process, but that last method may speed up the writing stage.  However, it would require significant program changes, and perhaps not gain me much benefit. To complicate things, there are too many Section names (Index ID's) for the IniReadSectionNames command, so I have had to split them off into their own (read/write) line-by-line index file, and create code to deal with duplicates. When read, Index ID's and Titles populate a Listbox control in a user GUI.
      So at this point in time, it seems best to use the Virtual INI approach to gain a significant reduction in time taken. For my own specific use, with my slow Netbook, I may also use a RAM Disk.
      Due to the aforementioned INI issues, and lack of available specific data, probably because it is always  program concentric, I have created an ASCII Checker program, which I guess you can say, is AutoIt  concentric. Because others may also find it handy, I am providing it here. NOTE - As yet, I am only aware that Escape characters exist, but have not investigated or catered for them in any way.
      ASCII Checker.zip

      The Virtual_INI_UDF is still a work in progress, though I have done most of the functions now, with the working but incomplete _Ini_Test function, still requiring changes etc from the information gleaned by the ASCII Checker program.
      Here's something to play with meanwhile.
      Updated files (24th February 2017)
      Virtual_INI_UDF.au3  NEW
      Example.au3 (23rd February 2017)
      All pretty basic, but managed to load my 4 Mb INI file (seemingly ok, but took a few seconds) ... though I have only worked with much smaller testing ones so far.
      P.S. While I have done a fair amount of testing, it has been pretty basic, and mostly limited to the examples provided. Testing has definitely not been extensive.
       
×
×
  • Create New...