Jump to content

How do I assign a variable to an array element?


gte
 Share

Recommended Posts

I feel like this should be easy, but I've had a hell of a time trying to figure out how to assign a variable to the output of wingetpos. I searched for about an hour and couldn't find anything conclusive.

This code isn't correct, but I'd like to have it setup to something like the following

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch")

$winposhorizontal = $winpos[0]

Thanks for reading.

Link to comment
Share on other sites

I feel like this should be easy, but I've had a hell of a time trying to figure out how to assign a variable to the output of wingetpos. I searched for about an hour and couldn't find anything conclusive.

This code isn't correct, but I'd like to have it setup to something like the following

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch")

$winposhorizontal = $winpos[0]

Thanks for reading.

That's perfect, but just get rid of the second quotes in WinGetPos.

Try this:

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "")

$winposhorizontal = $winpos[0]
$winposvertical = $winpos[1]

MsgBox(0, "", $winposhorizontal & ":" & $winposvertical)

It's working!

Link to comment
Share on other sites

  • Moderators

gte,

There is nothing wrong with your syntax. ;)

What error do you get? Are you sure the 2 quotes are correct? Check with the Au3Info tool. If they are not correct then WinGetPos will fail and you do not have an array to access. Try something like this to check on that:

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch")
If Not IsArray($winpos) Then MsgBox(0, "Error", "No position found")
$winposhorizontal = $winpos[0]

Looking forward to the next instalment. :evil:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks Melba/Kiti

Here is the error message I'm getting

C:\Documents and Settings\668692\My Documents\Work Stuff\AutoIt\testing\caprs2testing.au3 (394) : ==> Subscript used with non-Array variable.:

$winposhorizontal = $winpos[0]

$winposhorizontal = $winpos^ ERROR

And the function

Func _verifywinposition()

Global $SM_VIRTUALWIDTH = 78

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)

$VirtualDesktopWidth = $VirtualDesktopWidth[0]

If WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Then

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch")

$winposhorizontal = $winpos[0]

If $winposhorizontal >= ($VirtualDesktopWidth - 250) Then

WinMove("HP OpenView ServiceCenter - Incident Queue:", "", $caprswindowlocation[0], $caprswindowlocation[1])

ConsoleWrite("Had to reset window position location to 500 less than " & $VirtualDesktopWidth & @CRLF)

EndIf

EndIf

EndFunc

That's perfect, but just get rid of the second quotes in WinGetPos.

Try this:

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "")

$winposhorizontal = $winpos[0]
$winposvertical = $winpos[1]

MsgBox(0, "", $winposhorizontal & ":" & $winposvertical)

It's working!

gte,

There is nothing wrong with your syntax. ;)

What error do you get? Are you sure the 2 quotes are correct? Check with the Au3Info tool. If they are not correct then WinGetPos will fail and you do not have an array to access. Try something like this to check on that:

$winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch")
If Not IsArray($winpos) Then MsgBox(0, "Error", "No position found")
$winposhorizontal = $winpos[0]

Looking forward to the next instalment. :evil:

M23

Edited by gte
Link to comment
Share on other sites

  • Moderators

gte,

That error is telling you that $winpos is not an array, as I suspected. So we can safely say that WinGetPos is not finding your window.

Have you checked the 2 quotes you use to identify the window with the Au3Info tool yet? If you get those wrong, it will never work! ;)

M23

Edit: OK, I see from your edit that you have solved it by checking if the window exists. Good idea! :evil:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Yes, you were right as usual Melba :evil:

Thanks again for the guidance, I think this script is finally ready to go!

gte,

That error is telling you that $winpos is not an array, as I suspected. So we can safely say that WinGetPos is not finding your window.

Have you checked the 2 quotes you use to identify the window with the Au3Info tool yet? If you get those wrong, it will never work! ;)

M23

Edit: OK, I see from your edit that you have solved it by checking if the window exists. Good idea! :evil:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...