Jump to content
Sign in to follow this  
SmOke_N

Function Header

Recommended Posts

SmOke_N

I was getting annoyed with another language and creating a function header template, so I decided to make a quick and easy GUI to create a function header with just the data I wanted.

Any edit left blank will not be included in the function header output. I made it just for personal use, but someone else may find it useful.

;Create header function output

Global $sTopBottom = ";===============================================" & _
                    "===================================================="
Global $sFunction =              "; Function Name:    "
Global $sDescription =           "; Description:      "
Global $sParameters =            "; Parameter(s):     "
Global $sRequirement =           "; Requirement(s):   "
Global $sReturnValue =           "; Return Value(s):" & @CRLF
Global $sReturnValueOnSuccess =  ";                 On Success:" & @CRLF
Global $sReturnValueOnFailure =  ";                 On Failure:" & @CRLF
Global $sReturnValueonerror =    ";                 @Error:" & @CRLF
Global $sReturnValueOnExtended = ";                 @Extended:" & @CRLF
Global $sRemarks               = "; Remark(s):      "
Global $sAuthor                = "; Author(s):      "
Global $sPassString = ""

$hMain = GUICreate("Au3 Function Header Creator", 518, 585)

GUICtrlCreateLabel("Function Name:   ", 16, 20, 128, 17)
$hFunctionName = GUICtrlCreateInput("", 148, 17, 345, 21)

GUICtrlCreateLabel("Description:", 16, 50, 128, 17)
$hDescription = GUICtrlCreateEdit("", 148, 44, 345, 49)

GUICtrlCreateLabel("Parameter(s):", 16, 100, 128, 17)
$hParameters = GUICtrlCreateEdit("", 149, 100, 345, 49)

GUICtrlCreateLabel("Return Value(s) Success:", 16, 155, 128, 17)
$hReturnValSuccess = GUICtrlCreateEdit("", 149, 155, 345, 49)

GUICtrlCreateLabel("Return Value(s) Failure:", 16, 210, 128, 17)
$hReturnValFailure = GUICtrlCreateEdit("", 149, 210, 345, 49)

GUICtrlCreateLabel("Return Value(s) Error:", 16, 270, 128, 17)
$hReturnValError = GUICtrlCreateEdit("", 149, 265, 345, 49)

GUICtrlCreateLabel("Return Value(s) Extended:", 16, 320, 128, 17)
$hReturnValExtended = GUICtrlCreateEdit("", 149, 320, 345, 49)

GUICtrlCreateLabel("Requirement(s):", 16, 375, 128, 17)
$hRequirments = GUICtrlCreateEdit("", 149, 375, 345, 49)

GUICtrlCreateLabel("Remark(s):", 16, 434, 128, 17)
$hRemarks = GUICtrlCreateEdit("", 148, 430, 345, 49)

GUICtrlCreateLabel("Author(s):", 16, 493, 128, 17)
$hAuthor = GUICtrlCreateEdit("", 148, 489, 345, 49)

$hGenerate = GUICtrlCreateButton("Generate Ouptut", 10, 550, 497, 25, 0)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $hGenerate
            If GUICtrlRead($hFunctionName) = "" Then
                MsgBox(16, "Error", "You must at least have a function name.")
                ContinueLoop
            EndIf
            $sPassString = $sTopBottom & @CRLF & ";" & @CRLF
            $sPassString &= $sFunction & GUICtrlRead($hFunctionName) & @CRLF & ";" & @CRLF
            If GUICtrlRead($hDescription) <> "" Then
                $sPassString &= _ParseWordsToString(GUICtrlRead($hDescription), $sDescription)
            EndIf
            If GUICtrlRead($hParameters) <> "" Then
                $sPassString &= _ParseWordsToString(GUICtrlRead($hParameters), $sParameters)
            EndIf
            If GUICtrlRead($hReturnValSuccess) <> "" Or GUICtrlRead($hReturnValFailure) <> "" Or _
                GUICtrlRead($hReturnValError) <> "" Or GUICtrlRead($hReturnValExtended) <> "" Then
                $sPassString &= $sReturnValue
                
                If GUICtrlRead($hReturnValSuccess) <> "" Then _
                    $sPassString &= $sReturnValueOnSuccess & _ParseWordsToString(GUICtrlRead($hReturnValSuccess))
                If GUICtrlRead($hReturnValFailure) <> "" Then _
                    $sPassString &= $sReturnValueOnFailure & _ParseWordsToString(GUICtrlRead($hReturnValFailure))
                If GUICtrlRead($hReturnValError) <> "" Then _
                    $sPassString &= $sReturnValueonerror & _ParseWordsToString(GUICtrlRead($hReturnValError))
                If GUICtrlRead($hReturnValExtended) <> "" Then _
                    $sPassString &= $sReturnValueOnExtended & _ParseWordsToString(GUICtrlRead($hReturnValExtended))
            EndIf
            If GUICtrlRead($hRequirments) <> "" Then
                $sPassString &= _ParseWordsToString(GUICtrlRead($hRequirments), $sRequirement)
            EndIf
            If GUICtrlRead($hRemarks) <> "" Then
                $sPassString &= _ParseWordsToString(GUICtrlRead($hRemarks), $sRemarks)
            EndIf
            If GUICtrlRead($hAuthor) <> "" Then
                $sPassString &= _ParseWordsToString(GUICtrlRead($hAuthor), $sAuthor)
            EndIf
            _GUI_HeaderOutput($sPassString & $sTopBottom & @CRLF, $hMain)
    EndSwitch
WEnd

;===================================================================================================
;
; Function Name:    _GUI_HeaderOutput()
;
; Description:      GUI to show the header output 
;
; Parameter(s):     $sString: String to display 
;                   $hParent: Parent GUI
;
; Return Value(s):
;                 On Success:
;                   None 
;
; Remark(s):      Use the copy button to attach the output to the clipboard for ease of use 
;
; Author(s):      SmOke_N 
;
;===================================================================================================
Func _GUI_HeaderOutput($sString, $hParent)
    $hOutput = GUICreate("Au3 Output", 650, 400, Default, Default, -1, -1, $hParent)
    $hEditOutput = GUICtrlCreateEdit($sString, 10, 10, 630, 340)
    $hCopy = GUICtrlCreateButton("Copy to clipboard", 10, 360, 630, 25)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case -3
                GUIDelete($hOutput)
                Return
            Case $hCopy
                ClipPut($sString)
        EndSwitch
    WEnd
    Return
EndFunc


;===================================================================================================
;
; Function Name:    _ParseWordsToString()
;
; Description:      Separates the words by a space to fix the length, if the lenghth is too long,   
;                   then it will separate the string to the next line making sure it does not cut   
;                   off a word. 
;
; Parameter(s):     $sString: String from the edit boxes to separate 
;                   $sPrefix: Some of the prefix strings being passed need to have the length string  
;                   included on it 
;                   $nCount: [Optional] Max string length allowed 
;
; Return Value(s):
;                 On Success:
;                   Fixed length string 
;
; Author(s):      SmOke_N 
;
;===================================================================================================
Func _ParseWordsToString($sString, $sPrefix = "", $nCount = 100)
    Local $aArray, $nLen, $sRet
    Local $aSplit = StringSplit(StringStripCR($sString), @LF)
    For $xCC = 1 To $aSplit[0]
        $aSplit[$xCC] = StringStripWS($aSplit[$xCC], 7)
        $aArray = StringSplit($aSplit[$xCC], " ")
        $nLen = 0
        If $xCC > 1 Then $sPrefix = ""
        If $sPrefix = "" Then $sPrefix = ";                   "
        $sHold = $sPrefix
        For $iCC = 1 To UBound($aArray) - 1
            $nLen = StringLen($aArray[$iCC])
            If $nLen + StringLen($sHold) > $nCount Then
                Do
                    $sHold &= " "
                Until StringLen($sHold) >= $nCount
                $sRet &= $sHold & @CRLF
                $sHold = ";                   " & $aArray[$iCC] & " "
            Else
                $sHold &= $aArray[$iCC] & " "
            EndIf
        Next ;$iCC
        If $sHold Then $sRet &= $sHold & @CRLF
    Next ;$xCC
    $sRet &= ";" & @CRLF
    Return $sRet    
EndFunc

Edit:

Just noticed that there was word wrap with it, fixed the length to hopefully fix that.

Edited by SmOke_N

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

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
Sign in to follow this  

×