Sign in to follow this  
Followers 0
Old_Man_Winter

How To Set A Variable In Winactivate?

10 posts in this topic

Hi,

I'm new here, just discovered Autoit and it rocks!

I also have my first problem:

I want to activate a large number of successive windows: title = Figure 1, Figure 2, Figure 3 .... Figure N

in a do/untill or for/next loop.

eg:

$n = 0

Do

    $n = $n + 1

    WinActivate("Figure $n")

Until $n = 200

Only this doesn't work of course. How do I put a variable in the WinActivate title ?

Thanks alot

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This should work (without testing):

$n = 0
Do
   $n = $n + 1
   WinActivate("Figure " & $n, "")
Until $n = 200

Forgot the , "" on the WinActivate Function.

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

Nope, doesn't seem to work.

The full title is "Figure No.1" etc. So I tried:

$n = 0
Do
  $n = $n + 1
  WinActivate("Figure No." & $n, "")
  sleep(1000)
Until $n = 200

But nothing opens

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wait for the window, then use WinActivate.

A For loop has a counter to suit use

For $n = 1 To 200
    WinWait("Figure No." & $n)
    WinActivate("Figure No." & $n)
    Sleep(1000)
Next
Edited by MHz

Share this post


Link to post
Share on other sites

Sorry :)

Tried it and it isn't working either

Share this post


Link to post
Share on other sites

Sorry :)

Tried it and it isn't working either

yeah, the reason your first attempt wasn't working was because you have to concatenate the variable in as in the samples given. I bet, just based on the number of windows with successive titles like that, you're probably trying to activate child windows. try this...

Opt("WinSearchChildren",1)
$n = 1
While WinExists("Figure No." & $n)
WinActivate("Figure No." & $n)
$n = $n + 1
WEnd

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This should work (without testing):

WinActivate("Figure " & $n, "")
I'm having trouble activating a window using only a variable.

Is there any reason that this shouldn't work?

WinActivate($var)

Thanks,

mike

Edited by blueschism

Share this post


Link to post
Share on other sites

I'm having trouble activating a window using only a variable.

Is there any reason that this shouldn't work?

WinActivate($var)

Thanks,

mike

It will work, if feed the correct string that the variable holds.

Sorry, but the info that you supply is at best, guessing to solve.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It will work, if feed the correct string that the variable holds.

Sorry, but the info that you supply is at best, guessing to solve.

I'm pulling parts quantities out of an AS400 system and updating one of 2 user selected excel spreadsheets. The AS400 window and both excel spreadsheets are open in the background when attempting this. It's not correctly grabbing the spreadsheet. Here are the sections that apply.

Opt("WinTitleMatchMode", 2) 

; which excel doc?
$aLoop = 1
While $aLoop = 1
    $xlsin = InputBox("Get stock amounts", "Enter:" & @CRLF & @CRLF & "1 for TOP 100" & @CRLF & "2 for Manual", "", "")
    If @error = 1 Then
        Exit
    Else
        If $xlsin = 1 Then
            $spreadsheet = "Top"
            ExitLoop
        ElseIf $xlsin = 2 Then
            $spreadsheet = "manual"
            ExitLoop
        Else
            MsgBox(4096, "Error", "You typed in the wrong thing - try again!")
        EndIf
    EndIf
WEnd

; which line?
$bLoop = 1
While $bLoop = 1
    $ROW = InputBox("XLS Line to start on", "Enter Row number to start on", "2")
    If @error = 1 Then
        Exit
    ElseIf $ROW >= 2 Then
        $ROW = Int($ROW)
        ExitLoop
    EndIf  
WEnd

; start at excel field
WinActivate($spreadsheet)
Send("^{HOME}")
Send("{DOWN " & $ROW & "}")
Send("{UP}")

The 2 excel docs are called:

Top 100 Parts.xls

manual spreadsheet.xls

Any suggestions appreciated,

mike

Edited by blueschism

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