Sign in to follow this  
Followers 0
Xibalba

Prefix in variable naming - complete list?

4 posts in this topic

Hello,

I've noticed that all the included examples uses a variable practice like so:

  • $sWow64 (string)
  • $hImage (handle)
  • For $iY = 0 To $iH - 1 (integers)

 

and so on...

Which seems to be a nice practice in general.

I'm wondering if there's any list of all the data types, and how they are/can/should be used when it comes to naming variables? Or quality discussions on this specific area regarding coding standards.

For example, I'm not yet sure what data type $tSomething means (an example from the help file states: "a variable for use with DllStruct calls" which isn't that clear to me)

Share this post


Link to post
Share on other sites



Xibalba,

That type of variable naming is called Hungarian notation - or at least a subset of it. Here is an old link which offers an idea of the range of variables you are likely to come across in AutoIt - I add $c for ControlIDs in my own scripts. :)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Xibalba,

That type of variable naming is called Hungarian notation - or at least a subset of it. Here is an old link which offers an idea of the range of variables you are likely to come across in AutoIt - I add $c for ControlIDs in my own scripts. :)

M23

 

Thanks.

Could you give an example of a ControlID usage?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Xibalba,

A ControlID is the integer variable returned when you create a control using the native functions (GUICtrlCreate###). It is actually an index to an internal AutoIt array which holds all the details of the control and which allows you to affect the control by using the native functions such as GUICtrlSetData, GuiCtrlSetState, etc. :)

The return from the creation of a GUI or a control created using the UDF functions (_GUICtrl###_Create) is a Windows handle - a special hex value which uniquely identifies items in the Windows environment. These controls are not listed in the internal AutoIt array and so the coder needs to do a lot more work to get them to play nicely. A good example of this different behaviour is shown in the Tabs tutorial in the Wiki. ;)

M23

P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. ;)

Edited by Melba23

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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0

  • Similar Content

    • user4157124
      By user4157124
      As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?
      Some suggestions :
      For...To...Step...Next -loop variable-naming like $iN ($i1, $i2, etc.) : conforms to recommended naming convention, identifies level (albeit inverted to ExitLoop and ContinueLoop's convention) and enables SciTE selection-highlighting (requires minimum of 3 characters). Minimize logic in global scope, separate data & settings from logic, use of vertical space, project organization (folder structure, resource- and include file management). Example (loop variable-naming, minimizing logic in global scope and separation of settings from logic) :
      #include <Array.au3> Global Enum $RANDOM_RETURNFLOAT, _ $RANDOM_RETURNINTEGER Global Enum $EXITCODE_NONE Global Const $g_sChar0 = '-' Global Const $g_sChar1 = '+' Global Const $g_iAmountX = 10 Global Const $g_iAmountY = $g_iAmountX Main() Func Main() Local $aArray[$g_iAmountY][$g_iAmountX] For $i1 = 0 To $g_iAmountY - 1 For $i2 = 0 To $g_iAmountX - 1 $aArray[$i1][$i2] = Random(0, 1, $RANDOM_RETURNINTEGER) ? $g_sChar1 : $g_sChar0 Next Next _ArrayDisplay($aArray) Exit $EXITCODE_NONE EndFunc Example (project organization) :
      + project_folder + bak [backup files] + bin [distributed binaries and dependencies] + inc [non-standard include files] + res [resource files (icons, file+install files, etc.)] + usr [configuration files, databases, etc.] - script.au3 - script.exe Example (use of vertical space) :
      Func _DigitalRoot($iNum) Local $sNum = '' Local $aNum While $iNum > 9 $sNum = String($iNum) $aNum = StringSplit($sNum, '') $iNum = 0 For $i1 = 1 To $aNum[0] $iNum += Int($aNum[$i1]) Next WEnd Return $iNum EndFunc
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I was looking for a method with rename an Excel Sheet, but I didn't find a lot...
      So, I decided to make it in another way...
      Since I have to create a new Workbook, I thought that, creating a new Workbook, deleting the existing sheet, and adding a new one, would be almost the same...
      But I'm encountering a lot of issues, both when I delete the sheet and when I add the new sheet...
      This is what I do:
       
      ; Create the Excel Object... Local $oExcel_PRV_HW = _Excel_Open(False) If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione dell'oggetto Excel." & @CRLF & "Errore: " & @error & @CRLF & "Esteso: " & @extended) Else ; Create the Workbook with 1 worksheet... Local $oWorkbook_New = _Excel_BookNew($oExcel_PRV_HW, 1) ; Save the Workbook in order to open it and work with it... _Excel_BookSaveAs($oWorkbook_New, $sFilePreventivo, $xlOpenXMLWorkbook, True) If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante il salvataggio della cartella di lavoro." & @CRLF & "Errore: " & @error) EndIf ; Open the Workbook to work with... Local $oWorkbook_PRV_HW = _Excel_BookOpen($oExcel_PRV_HW, $sFilePreventivo) If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file '" & $sFilePreventivo & "'." & @CRLF & "Errore: " & @error) Else ; Here I would add the _Excel_SheetDelete() and _Excel_SheetAdd() as I did, but they return errors... EndIf EndIf Can someone help me out, please? Thanks
    • guinness
      By guinness
      I haven't posted anything in the examples section for about 6-7 weeks, so felt it was that time again. This shows how to use the string functions of AutoIt and regular exp<b></b>ressi&#111;ns. The header pretty much explains what the function(s) do.
       

      #include <MsgBoxConstants.au3> #include <StringConstants.au3> MsgBox($MB_SYSTEMMODAL, '', _FilePrefix(@ScriptFullPath)) ; Append _ thus creating C:\Example\Test_.exe MsgBox($MB_SYSTEMMODAL, '', _FilePrefixSRE(@ScriptFullPath & '.text')) ; Append _ thus creating C:\Example\Test_.exe ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FilePrefixSRE ; Description ...: Append a prefix before the file extension. ; Syntax ........: _FilePrefixSRE($sFilePath[, $sPrefix = Default]) ; Parameters ....: $sFilePath - Filepath or name to append a prefix before the file extension. ; $sPrefix - [optional] A string value. Default is '_'. ; Return values .: Success - Filepath with the intended prefix. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _FilePrefixSRE($sFilePath, $sPrefix = Default) If $sPrefix = Default Or StringStripWS($sPrefix, $STR_STRIPALL) == '' Then $sPrefix = '_' Return StringRegExpReplace($sFilePath, '^(.+?)(\.\w+)?$', '${1}' & $sPrefix & '${2}') EndFunc ;==>_FilePrefixSRE ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FilePrefix ; Description ...: Append a prefix before the file extension. ; Syntax ........: _FilePrefix($sFilePath[, $sPrefix = Default]) ; Parameters ....: $sFilePath - Filepath or name to append a prefix before the file extension. ; $sPrefix - [optional] A string value. Default is '_'. ; Return values .: Success - Filepath with the intended prefix. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _FilePrefix($sFilePath, $sPrefix = Default) If $sPrefix = Default Or StringStripWS($sPrefix, $STR_STRIPALL) == '' Then $sPrefix = '_' Local $iDot = StringInStr($sFilePath, '.', Default, -1) - 1 If $iDot <= 0 Then $iDot = StringLen($sFilePath) Return StringLeft($sFilePath, $iDot) & $sPrefix & StringTrimLeft($sFilePath, $iDot) EndFunc ;==>_FilePrefix