Jump to content

how to loop for exact amount times?


neltisen
 Share

Recommended Posts

Hello,

I was using AutoIt (I think it was AutoIt, but I'm not sure) around half year ago. For few months I forgot about its (even name, I had full disc format, so I'm not sure if it was this app :P). Through this time I have completly forgotten my scripts, but I remember something like this:

$id = 1

loop 1000

send ( "add skill" $id)

sleep 200

$id += 1

(this macro was usable to learn all abilities in HoMM V ;) )

I know that I can use For...until in exchange, but what when I don't need var in my script?

example:

loop 20

send ( "wtb g40 stuff" )

sleep 1000

how to use loop here only for (as example) 20 times?

Link to comment
Share on other sites

I perfer the method weaponx listed. -It just seems cleaner/ easier. When I am in question, I just adapt these from VBA

CODE
Sub Main()

DoLoop

WhileWend

ForNext

ForEach

SpecialCells

EndDown

End Sub

Private Sub DoLoop()

Dim r As Range

Set r = Range("a1")

Do Until IsEmpty® Or r.Row = Rows.Count

Set r = r.Offset(1)

Loop

End Sub

Private Sub WhileWend()

Dim r As Range

Set r = Range("a1")

While Not IsEmpty® And r.Row <> Rows.Count

Set r = r.Offset(1)

Wend

End Sub

Private Sub ForNext()

For i = 1 To Application.WorksheetFunction.CountA(Range("A:A"))

If IsEmpty(Cells(i, 1)) Then Exit For

Next i

End Sub

Private Sub ForEach()

Dim r As Range

For Each r In Range("A:A").Cells

If IsEmpty® Then Exit For

Next r

End Sub

Private Sub SpecialCells()

Set r = Range("A:A").SpecialCells(xlCellTypeBlanks)

End Sub

Private Sub EndDown()

Dim r As Range

Set r = Range("a1")

Select Case True

Case IsEmpty®

' do nothing

Case IsEmpty(r.Offset(1))

Set r = r.Offset(1)

Case Else

Set r = r.End(xlDown).Offset(1)

End Select

End Sub

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...