Sign in to follow this  
Followers 0
Chobby

$value And Other Stuff

10 posts in this topic

Hey guys ..

I just started learning this AutoIt :) And well, its cool ...

So i was trying to make a little newbie script, that just opens Google.com, prompts for something to search for, and then performs the searc..

But i got problems by sending the $value ..

Here is my script:

Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE", "", @SW_MAXIMIZE)
WinWaitActive("Google - Microsoft Internet Explorer")
$value=InputBox("Search for?", "Enter the search value:")
Send("$value")
Sleep(5000)
Send("{TAB}")
Send("{ENTER}")

Note: "Homepage" is set to google.com ..

What i need help with, as a start is "Send("$value")" .. It just writes "$value" in google search engine, but not what you answered to the prompt..

Thanks,

Chobby

Share this post


Link to post
Share on other sites



Great! It works, of course..

Hmm, do you have a quick definition on how the "If ... Then" function works? Still bugging my ass with that one :)

Share this post


Link to post
Share on other sites

oooh, and 1 thing more .. If its possible..

A definition on how to get answers from MsgBoxes with for instance "Retry", "Cancel" and "Ok"-buttons ..

Like, if use hits "Ok", then X happens .. But if user hits "Cancel", then Y happens ..

A bit like "If ... Then" function i guess?

Share this post


Link to post
Share on other sites

Great! It works, of course..

Hmm, do you have a quick definition on how the "If ... Then" function works? Still bugging my ass with that one :)

The Helpfile has a section called: Conditional Statements did you read this ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Great! It works, of course..

Hmm, do you have a quick definition on how the "If ... Then" function works? Still bugging my ***with that one :)

It basically means:

If (Something [is equal/not equal/greater than/less than/etc] Something else) Then

Do some code

EndIf

So, let's say you wanted to make sure your $value was not some specific text (let's say "abcd"), you could use an If...Then statement for this.

Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE", "", @SW_MAXIMIZE)
WinWaitActive("Google - Microsoft Internet Explorer")

$value=InputBox("Search for?", "Enter the search value:")

If ($value == "abcd") Then
     MsgBox(0,"Error", "Bad value.")
     Exit
EndIf

Send($value)
Sleep(5000)
Send("{TAB}")
Send("{ENTER}")

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks guys ..

Good help :)

Edit: Is it possible to do something like this??:

If ($value == " ") Then
If ($value == "abcd") Then
If ($value == "haha?") Then
     MsgBox(0,"Error", "Bad value.")
     Exit
EndIf

Or should i write a whole new "if" for each one?

Edited by Chobby

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks guys ..

Good help :)

Edit: Is it possible to do something like this??:

If ($value == " ") Then
If ($value == "abcd") Then
If ($value == "haha?") Then
     MsgBox(0,"Error", "Bad value.")
     Exit
EndIf

Or should i write a whole new "if" for each one?

The logic of what you wrote doesn't make sense. If $value = "", then it doesn't equal those other values at the same time. If you meant to test several different variables to see that they all equal the required values, that would look like this:

; Rewrite of your code:
If $value1 == " " Then
    If $value2 == "abcd" Then
        If $value3 == "haha?" Then
            MsgBox(0,"Error", "Bad value.")
            Exit
        EndIf
    EndIf
EndIf

; Another way to do the same thing:
If $value1 == " " And $value2 == "abcd" And $value3 == "haha?" Then
    MsgBox(0,"Error", "Bad value.")
    Exit
EndIf

You would use Select/Case if you wanted different actions for different values of the same variable (this can also be done with ElseIf, but that's harder to read and follow):

Select
    Case $value == " "
        MsgBox(0, "Test", "Result is {Space}.")

    Case $value == "abcd"
        MsgBox(0, "Test", "Result is 'abcd'.")

    Case $value == "haha?"
        MsgBox(0, "Test", "Result is 'haha?'.")

    Case Else
        MsgBox(0,"Error", "Bad value: " & $value)
        Exit

EndSelect

The help file is your friend. I have it open the whole time I'm coding in AutoIT. There are basic tutorial exorcises in it too.

:mellow:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Just different ways of doing the same thing:

If $value = " " OR $value = "haha?" OR $value = "abcd" Then
Msgbox(0,'Error','Bad value: ' & $value)
EndIf

Or

Switch $value
Case " "
Msgbox(0,'Error','Bad value: ' & $value)
Case "haha?"
Msgbox(0,'Error','Bad value: ' & $value)
Case "abcd"
Msgbox(0,'Error','Bad value: ' & $value)
EndSwitch

~cdkid

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

Just different ways of doing the same thing:

If $value = " " OR $value = "haha?" OR $value = "abcd" Then
Msgbox(0,'Error','Bad value: ' & $value)
EndIf

Or

Switch $value
Case " "
Msgbox(0,'Error','Bad value: ' & $value)
Case "haha?"
Msgbox(0,'Error','Bad value: ' & $value)
Case "abcd"
Msgbox(0,'Error','Bad value: ' & $value)
EndSwitch

~cdkid

Oooh... Switch... new shiny! Never noticed that one before, cool! :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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