Jump to content
Sign in to follow this  
russell

Variable in a Variable

Recommended Posts

russell

I made this to open notepads.exe and the below code works i just reliazed while playing around that i have a serious problem i cant find a solution to. I wanted to reffrence the "$handle" of the created notepads. I tried "$handle($r)" and serveral other combinations only to fail. The problem lies here: "$handle = WinGetHandle ("Untitled - Notepad" & $r)" becuase its recreating this over and over i cant define a new $handle uniqe to each widows that i can later reffence. If i were to use lets say 3 in the input box. How would i at the end have 3 notepad windows defined like $handle1,$handle2,$handle3? I am either way over thinking this or am truly stumped. If you run something like 14 windows you begin to see the problem

#include <Array.au3>
#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Input Length=2, Width=20, Height=20
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Notepad","Enter desiered notepad windows",""," 2","20","20","-1","-1")
Select
Case @Error = 0 ;OK - The string returned is valid
Case @Error = 1 ;The Cancel button was pushed
Case @Error = 3 ;The InputBox failed to open
EndSelect
#EndRegion --- CodeWizard generated code End ---
Dim $handle
local $arr[$sInputBoxAnswer]

$r=0
Do
Notepad ()
$r = $r+1
Until $r = UBound($arr)
$r =0
Do
WinActivate ("Window " & $r)
Send ("I am window number " & $r)
Sleep (1000)
$r = $r+1
Until $r = UBound($arr)

Func Notepad ()
ShellExecute("Notepad.exe")
Sleep(1000)
WinActive ("Untitled - Notepad")
$handle = WinGetHandle ("Untitled - Notepad" & $r)
WinMove ($handle,"" ,0,0)
WinSetTitle ($handle,"","Window " & $r)
Sleep (1000)
EndFunc
Edited by russell

muppet hands are so soft :)

Share this post


Link to post
Share on other sites
skysel

This post will answer your question, learn to use search wisely :-)

Edited by skysel

Share this post


Link to post
Share on other sites
czardas

The code could be better organized. You are not yet finished so I only changed what I considered necessary to get you further.

#include <Array.au3>
#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Input Length=2, Width=20, Height=20
;If Not IsDeclared("sInputBoxAnswer") Then Local $iInputBoxAnswer
Local $iInputBoxAnswer = InputBox("Notepad","Enter desiered notepad windows",""," 2","20","20","-1","-1")
Switch @error
    Case 0 ;OK - The string returned is valid
    Case 1 ;The Cancel button was pushed
    Case 3 ;The InputBox failed to open
EndSwitch
#EndRegion --- CodeWizard generated code End ---
Local $aHandle[$iInputBoxAnswer]
Local $arr[$iInputBoxAnswer]

Local $r=0
Do
    Notepad ($r)
    $r = $r+1
Until $r = UBound($arr)
$r =0
Do
    WinActivate ("Window " & $r)
    Send ("My win handle is " & $aHandle[$r])
    Sleep (1000)
    $r = $r+1
Until $r = UBound($arr)

_ArrayDisplay($aHandle, "Win Handles") ; Check it's working

Func Notepad ($r)
    ShellExecute("Notepad.exe")
    Sleep(1000)
    ;WinActive ("Untitled - Notepad")
    $aHandle[$r] = WinGetHandle ("Untitled - Notepad")
    WinMove ($aHandle[$r],"" ,10,10) ; Changed position.
    WinSetTitle ($aHandle[$r],"","Window " & $r)
    Sleep (1000)
EndFunc
Edited by czardas

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  

×