Jump to content

Are these still Valid Commands?


GEOSoft
 Share

Recommended Posts

Are the following still valid in Ver 3? If not what are the new commands?

IfMsgBox

GoTo

GoSub

Return

IfInString

IfNotInString

I used "Select" to replace a few IfInString but that was doing it the hard way because the entire string from the registry had to be checked instead of just 3 0r 4 numbers.

It looks like the Help file still needs a lot of work. Reading through the posts here I am finding things that are not yet documented.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

AutoIt version 3 has a bunch of functions and a real IF statement:

If $x = 1 ;equality test

If $x >= 1 AND $x <= 10 ;number between 1 and 10 inclusive

If ($x = 1) OR ($x = 2) OR ($x = 3) ;a bunch of cases

If NOT (x = 5) ;inequality

If x <> 5 ;logically equivalent to the previous one

And so on

GoTo is not supported; there is a forum topic about this

GoSub/Return has been replaced with function declarations:

Func functioname([byRef] $param1, [byRef] $param2)

EndFunc

; As for IfInStr, you can use the following

If StringInStr( "string", "substring", [casesense] ) Then

; code goes here

EndIf

HOWEVER, this is *possibly* a bad coding style. StringInStr returns the index of the string (or returns zero if not found). AutoIt treats a nonzero value as TRUE and zero as FALSE, I believe. So it might be better to say:

$myVariable = StringInStr( "string", "substring", [casesense] ) Then

If $myVariable > 0

MsgBox(0,"","Substring was found...")

Else

MsgBox(0,"","String not found")

EndIf

If Not StringInStr( "string", "substring", [casesense] ) Then

; code goes here

EndIf

MsgBox is a bit tricky

$x = MsgBox(0,"Title","Text goes here")

If $x = 0 Then

; user clicked OK button

EndIf

See the help file--under the respective sections--for details.

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Thanks CyberSlug.

I have the whole script working now but it sure seems bulky. Having GoSub/Return was much, much better. That way if someone made an error in an input box I could return them to the beginning of that Sub so they could try again.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Administrators

Thanks CyberSlug.

I have the whole script working now but it sure seems bulky.  Having GoSub/Return was much, much better.  That way if someone made an error in an input box I could return them to the beginning of that Sub so they could try again.

Trust me, once you have got the hang of While/Do/For/ExitLoop/ContinueLoop there are very few v3 scripts that will anything like as large/complicated as a v2 script. Especially when you look back on code that had Gotos everywhere.

As for your input box, if you want to make sure a input matches your requirements and loop until it does so, something like this may help:

$loop = 1
Do
    $input = InputBox("Input", "Enter your name")
    If $input <> "Jon" Then
        MsgBox(0, "", "Sorry, must enter 'Jon' to continue")
    Else
        $loop = 0  ; Will make the loop stop below
    EndIf
Until $loop <> 1

Or:

Do
    $input = InputBox("Input", "Enter your name")
    If $input <> "Jon" Then
        MsgBox(0, "", "Sorry, must  'Jon' to continue")
    EndIf
Until $input = "Jon"

And something to remember is that it's very hard to convert complex scripts from v2 to v3 because you need to think in a different way. Writing new scripts is a doddle once you are in the "zone" though :whistle: (I won't be converting my old big scripts i'll continue to use 2.64 for those B) )

Link to comment
Share on other sites

Thanks again CS and Jon. It looks like I can work with those loops OK. The reasons I want this script converted are;

A) I can have a default field in the input boxes. In the old script I had to disable one of them because it was downright disasterous if that reg key was left empty.

:whistle: The ability to Cancel from an input box.

There are a lot of nice features in ver 3 but it's going to take some getting used to. I also have an idea of running it with Larry's GUI at some point, but that will wait untill I am more familiar with this version, or it may never get done.

BTW another (simple) script calls for getting the free disk space as a percentage of the total drive space. I have that working but it returns with about 4 decimal places. Is there an easy way to round that up to one or two? and is there a simple loop to run that would return the available space on each drive without hardcoding the drive path? I never know how many partitions the user may have so it would have to start with C: and increment until it ran out of fixed disks and at the same time report the space for each fixed disk. The idea is that it starts up a defrag application that should never be run on a drive with less than 15% free space. If one drive is less than that, the drive has to be skipped. This one is not urgent since I still have a lot more to do on the app anyway.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

; Yeah, this code could be better written--but is final revision, I hope

$drive = 67;ASCII value of 'C'
Do
   $freeSpace = PrettyPrint(DriveSpaceFree(Chr($drive) & ":\"), 2, 1)
   MsgBox(0,"Free space on " & Chr($drive) & ":\ is", $freeSpace & " Megabytes")
   $drive = $drive + 1
Until $freeSpace == 0


; Parameters:  number, digitsAfterDecmialPoint, whetherToPutCommas
;  This truncates instead of rounding, but that's close enough :-)
Func PrettyPrint($var, $precision, $commas)
   $dot = StringInStr($var, ".")
   $tmp = StringLeft($var, $dot + $precision)
   If $commas Then
      For $i = $dot-4 to 1 step -3
         $tmp = StringLeft($tmp,$i) & "," & StringTrimLeft($tmp,$i)
      Next
   EndIf
   Return $tmp
EndFunc

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Well it looks like a good starting point anyway. It also checks the CD drives when it should only be checking hard drives but I will work at it. Thanks a lot.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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