Sign in to follow this  
Followers 0
Hylia

Automated multiple variables in use

5 posts in this topic

#1 ·  Posted (edited)

Firstly, I'm new to both AutoIT & programming in general so I don't really now what it's called what I'm trying to do, so please, bear with me.

I'm trying to declare an automaticly created multiple variable, I think it'll be easier if I just show what I've had in my script so far:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiStatusBar.au3>
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
$X = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$Y = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;pre-declare x & y

For $i = 1 To 5
Assign('x' & $i, -1);
Assign('y' & $i, -1);
Next

;pre-declare end


HotKeySet("{SPACE}", "Var")

While 1

$nSet = GUICtrlRead($N)

$pos = MouseGetPos()
GUICtrlSetData($X, $pos[0])
GUICtrlSetData($Y, $pos[1])

If $nSet = 1 then
GUICtrlSetData($MouseCoordX, $x1)
GUICtrlSetData($MouseCoordY, $y1)

ElseIf $nSet = 2 then
GUICtrlSetData($MouseCoordX, $x2)
GUICtrlSetData($MouseCoordY, $y2)

ElseIf $nSet = 3 then
GUICtrlSetData($MouseCoordX, $x3)
GUICtrlSetData($MouseCoordY, $y3)

ElseIf $nSet = 4 then
GUICtrlSetData($MouseCoordX, $x4)
GUICtrlSetData($MouseCoordY, $y4)

ElseIf $nSet = 5 then
GUICtrlSetData($MouseCoordX, $x5)
GUICtrlSetData($MouseCoordY, $y5)

EndIf


$Msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit

EndSelect

WEnd

Func Var()

If $nSet > 0 then

$x & $nSet = $pos[0]
$y & $nSet = $pos[1]
GUICtrlSetData($N, $nSet + 1)

EndIf

EndFunc

My problem is with the Func Var() I want it to automaticly create the numbers for $x1,$x2 etc.

When I use my hotkey.

How would I do this?

Edited by Hylia

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What you are doing seem to be going around the world to buy a lollipop from up the road.

Of course I could be wrong because I never used Assign, never found the need for it.

I think you should just create a 2D array

$aXY[5][2]

here you a 5 element array, each of which can store 2 values (x + y) perhaps

To visualise, run this

#include <Array.au3>

local $aXY[5][2] = [[10,20]]

_ArrayDisplay($aXY)

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I would suggest to use arrays. That's much easier. The wiki has a good tutorial regarding arrays.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok thanks, it seems to work, however now the "MouseGetPos()" doesn't seem to be updating anymore in the GUI.

Update: I've found out what the problem was in the GUI I also have $X & $Y declared, ok, problem solved can someone lock this?

Thanks again everyone for your help.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
$X = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$Y = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;pre-declare x & y

local $X[5]
local $Y[5]

;pre-declare end


HotKeySet("{SPACE}", "Var")

While 1

$nSet = GUICtrlRead($N)

$pos = MouseGetPos()
GUICtrlSetData($X, $pos[0])
    GUICtrlSetData($Y, $pos[1])

If $nSet > 0 then
GUICtrlSetData($MouseCoordX, $x[$nSet])
GUICtrlSetData($MouseCoordY, $y[$nSet])
EndIf


$Msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit

EndSelect

WEnd

Func Var()

If $nSet > 0 then
$x[$nSet] = $pos[0]
$y[$nSet] = $pos[1]
GUICtrlSetData($N, $nSet + 1)

EndIf

EndFunc

Edited by Hylia

Share this post


Link to post
Share on other sites

This line is invalid:

GUICtrlSetData($X, $pos[0])
$x is an array so you have to pass the index too
$x[$nSet]


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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