Jump to content
Sign in to follow this  
Hylia

Automated multiple variables in use

Recommended Posts

Hylia

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
JohnOne

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Hylia

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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  

×