Sign in to follow this  
Followers 0
Guyana

Includes in scripts

12 posts in this topic

Hi all, how can I determine wich includes are needed in scripts. There are a lot of sample scripts that doesn't heave the right includes. Is there a possibility to see wich ones are needed? :P

Share this post


Link to post
Share on other sites



Make sure you have the newest version. Fairly sure the helpfile is updated as well so the required includes should be correct. You could also search your computer for the constants ($WS_POPUP as an example) and make sure that you search inside the files. Set the search path to the autoit include directory and you should have it.

Share this post


Link to post
Share on other sites

And that's it? Not very fine method. Thought that the sytem would say, "You need that include" as an error or xxx include missing.

As for the examples, Why doesn't the author adds the include when he posts a new script?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Because, we almost all have the lastest version of AutoIt. I recommend you should download it too. No more include errors :P

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

? I'm having the latest!!!

What does the #include <XXX.au3> mean then???

For example, to use combobox i need to add #include <ComboConstants.au3> If I don't add it the script failes???

You are saying that you won't need any include?

Cant follow, sry.

Share this post


Link to post
Share on other sites

What we're saying is that having the latest version helps because you have a better chance of seeing what includes you need. You do need the includes for your script to work but a lot of functions have been updated so the required includes changed.

Share this post


Link to post
Share on other sites

OK one last reply.

I download a sample script that only has the constants include. Everybody says, nice script, well done. I'm starting it with the latest version of autoit and it fails. Somebody else has to say to me that i have to add the comboconstants include.

A. Why doesn't the author adds it.

B. why can someone else start without any problems while he is missing the include also.

C. How does someone knows wich include had to be added (experience?).

If this is experience, is it than possible for a beginner to determine on an easy way wich includes are needed if a script fails??? I don't know what an include does.

For example, if an ocx is missing in vb, its easy to determine wich ocx by editing the project and seeing the plugin on the form.

Share this post


Link to post
Share on other sites

Robocopy example also not working. EXE works but source not. Exe very slow by the way. Going back to VB.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Guyana

A. The author adds what is supposed to be added at the moment, if not anything else is stated you should assume that he is using the current stable or beta for that time, if it's not working for you you are probably not using the same version as him. You have to remember that AutoIt is still being actively developed and things to change sometimes and as a scriptwriter you can't work on the same thing forever.

B. How do you know he is missing anything? As the previous, you have to remember that older scripts usually need a few "updates" to work with the latest versions.

C. You can start by using #AutoIt3Wrapper_Add_Constants=Y and if there is still stuff missing do as dbzfanatic said, use "Find in Files" from SciTE and search for the missing variable in the /AutoIt3/Include/ directory

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

? I'm having the latest!!!

What does the #include <XXX.au3> mean then???

For example, to use combobox i need to add #include <ComboConstants.au3> If I don't add it the script failes???

You are saying that you won't need any include?

Cant follow, sry.

What is "include"?

That is some script that contains some functions or constants that you use inside your script.

For example (this script is from the help file - AutoIt's virtue):

#include <Array.au3>

Local $avArray[10]

$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = "Jon"
$avArray[3] = "Larry"
$avArray[4] = "Jeremy"
$avArray[5] = "Valik"
$avArray[6] = "Cyberslug"
$avArray[7] = "Nutster"
$avArray[8] = "JdeB"
$avArray[9] = "Tylo"

_ArrayDisplay($avArray, "$avArray set manually 1D")

That script uses function _ArrayDisplay(). That function is not built-in one. It is stored inside script called Array.au3 that you can find in AutoIt's "Include" folder. You are introducing that script to AutoIt's engine using keyword #include. So, when you execute script, engine will look for definition of that function and will find it inside Array.au3.

If you don't "include" you will get "_ArrayDisplay() undefined function" error.

Like running this script:

Local $avArray[10]

$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = "Jon"
$avArray[3] = "Larry"
$avArray[4] = "Jeremy"
$avArray[5] = "Valik"
$avArray[6] = "Cyberslug"
$avArray[7] = "Nutster"
$avArray[8] = "JdeB"
$avArray[9] = "Tylo"

_ArrayDisplay($avArray, "$avArray set manually 1D")

You can avoid all includes but than you have to define all used funtions or constants:

CODE
Local $avArray[10]

$avArray[0] = "JPM"

$avArray[1] = "Holger"

$avArray[2] = "Jon"

$avArray[3] = "Larry"

$avArray[4] = "Jeremy"

$avArray[5] = "Valik"

$avArray[6] = "Cyberslug"

$avArray[7] = "Nutster"

$avArray[8] = "JdeB"

$avArray[9] = "Tylo"

_ArrayDisplay($avArray, "$avArray set manually 1D")

Func _ArrayDisplay(Const ByRef $avArray, $sTitle = "Array: ListView Display", $iItemLimit = -1, $iTranspose = 0, $sSeparator = "", $sReplace = "|")

If Not IsArray($avArray) Then Return SetError(1, 0, 0)

; Dimension checking

Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1

If $iDimension > 2 Then Return SetError(2, 0, 0)

; Separator handling

;~ If $sSeparator = "" Then $sSeparator = Chr(1)

If $sSeparator = "" Then $sSeparator = Chr(124)

; Declare variables

Local $i, $j, $vTmp, $aItem, $avArrayText, $sHeader = "Row", $iBuffer = 64

Local $iColLimit = 250, $iLVIAddUDFThreshold = 4000, $iWidth = 640, $iHeight = 480

Local $iOnEventMode = Opt("GUIOnEventMode", 0), $sDataSeparatorChar = Opt("GUIDataSeparatorChar", $sSeparator)

; Swap dimensions if transposing

If $iSubMax < 0 Then $iSubMax = 0

If $iTranspose Then

$vTmp = $iUBound

$iUBound = $iSubMax

$iSubMax = $vTmp

EndIf

; Set limits for dimensions

If $iSubMax > $iColLimit Then $iSubMax = $iColLimit

If $iItemLimit = 1 Then $iItemLimit = $iLVIAddUDFThreshold

If $iItemLimit < 1 Then $iItemLimit = $iUBound

If $iUBound > $iItemLimit Then $iUBound = $iItemLimit

If $iLVIAddUDFThreshold > $iUBound Then $iLVIAddUDFThreshold = $iUBound

; Set header up

For $i = 0 To $iSubMax

$sHeader &= $sSeparator & "Col " & $i

Next

; Convert array into text for listview

Local $avArrayText[$iUBound + 1]

For $i = 0 To $iUBound

$avArrayText[$i] = "[" & $i & "]"

For $j = 0 To $iSubMax

; Get current item

If $iDimension = 1 Then

If $iTranspose Then

$vTmp = $avArray[$j]

Else

$vTmp = $avArray[$i]

EndIf

Else

If $iTranspose Then

$vTmp = $avArray[$j][$i]

Else

$vTmp = $avArray[$i][$j]

EndIf

EndIf

; Add to text array

$vTmp = StringReplace($vTmp, $sSeparator, $sReplace, 0, 1)

$avArrayText[$i] &= $sSeparator & $vTmp

; Set max buffer size

$vTmp = StringLen($vTmp)

If $vTmp > $iBuffer Then $iBuffer = $vTmp

Next

Next

$iBuffer += 1

; GUI Constants

Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 0x66

Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 0x40

Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 0x0200

Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 0x2

Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 0x4

Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3

Local Const $_ARRAYCONSTANT_LVIF_PARAM = 0x4

Local Const $_ARRAYCONSTANT_LVIF_TEXT = 0x1

Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29)

Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4)

Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44)

Local Const $_ARRAYCONSTANT_LVM_INSERTITEMA = (0x1000 + 7)

Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54)

Local Const $_ARRAYCONSTANT_LVM_SETITEMA = (0x1000 + 6)

Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20

Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1

Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8

Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200

Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000

Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000

Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000

Local Const $_ARRAYCONSTANT_tagLVITEM = "int Mask;int Item;int SubItem;int State;int StateMask;ptr Text;int TextMax;int Image;int Param;int Indent;int GroupID;int Columns;ptr pColumns"

Local $iAddMask = BitOR($_ARRAYCONSTANT_LVIF_TEXT, $_ARRAYCONSTANT_LVIF_PARAM)

Local $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]"), $pBuffer = DllStructGetPtr($tBuffer)

Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM), $pItem = DllStructGetPtr($tItem)

DllStructSetData($tItem, "Param", 0)

DllStructSetData($tItem, "Text", $pBuffer)

DllStructSetData($tItem, "TextMax", $iBuffer)

; Set interface up

Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, Default, Default, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX))

Local $aiGUISize = WinGetClientSize($hGUI)

Local $hListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 26, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS)

Local $hCopy = GUICtrlCreateButton("Copy Selected", 3, $aiGUISize[1] - 23, $aiGUISize[0] - 6, 20)

GUICtrlSetResizing($hListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS)

GUICtrlSetResizing($hCopy, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)

GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES)

GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT)

GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE)

; Fill listview

For $i = 0 To $iLVIAddUDFThreshold

GUICtrlCreateListViewItem($avArrayText[$i], $hListView)

Next

For $i = ($iLVIAddUDFThreshold + 1) To $iUBound

$aItem = StringSplit($avArrayText[$i], $sSeparator)

DllStructSetData($tBuffer, "Text", $aItem[1])

; Add listview item

DllStructSetData($tItem, "Item", $i)

DllStructSetData($tItem, "SubItem", 0)

DllStructSetData($tItem, "Mask", $iAddMask)

GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_INSERTITEMA, 0, $pItem)

; Set listview subitem text

DllStructSetData($tItem, "Mask", $_ARRAYCONSTANT_LVIF_TEXT)

For $j = 2 To $aItem[0]

DllStructSetData($tBuffer, "Text", $aItem[$j])

DllStructSetData($tItem, "SubItem", $j - 1)

GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETITEMA, 0, $pItem)

Next

Next

; ajust window width

$iWidth = 0

For $i = 0 To $iSubMax + 1

$iWidth += GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0)

Next

If $iWidth < 250 Then $iWidth = 230

WinMove($hGUI, "", Default, Default, $iWidth + 20)

; Show dialog

GUISetState(@SW_SHOW, $hGUI)

While 1

Switch GUIGetMsg()

Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE

ExitLoop

Case $hCopy

Local $sClip = ""

; Get selected indices [ _GUICtrlListView_GetSelectedIndices($hListView, True) ]

Local $aiCurItems[1] = [0]

For $i = 0 To GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0)

If GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, 0x2) Then

$aiCurItems[0] += 1

ReDim $aiCurItems[$aiCurItems[0] + 1]

$aiCurItems[$aiCurItems[0]] = $i

EndIf

Next

; Generate clipboard text

If Not $aiCurItems[0] Then

For $sItem In $avArrayText

$sClip &= $sItem & @CRLF

Next

Else

For $i = 1 To UBound($aiCurItems) - 1

$sClip &= $avArrayText[$aiCurItems[$i]] & @CRLF

Next

EndIf

ClipPut($sClip)

EndSwitch

WEnd

GUIDelete($hGUI)

Opt("GUIOnEventMode", $iOnEventMode)

Opt("GUIDataSeparatorChar", $sDataSeparatorChar)

Return 1

EndFunc

That is what compiler do when compiling. You are "including" to reduce the size of the main script and to make it more human-readable, simpler, etc.

Also, there could be the problem with constants with newer version of AutoIt because AutoiIt's developers are obviously trying to find the best way to "include" them considering many things (e.g. the size of the eventually compiled script).

btw, I simply love Internal Server Error when previewing post. Love!


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

OK that migrate script is perfect, thx.

:P

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