Jump to content

Help with Inputbox with Button functions


 Share

Recommended Posts

Hi all. I am very inexperienced in scripting, and I have been searching the forums as well as the Help file for an answer to my question. (Which is the only reason Ive gotten this far.)

I am trying to write a script that will look at the text in a text box to determine what will happen when you click a button. For example if you type Gmail into the text box and press the button Web it will take you to the Gmail log in page and input your credentials and log you in.

So far this is what I have:

#include <GUIConstants.au3>

; GUI

$GUI1 = GuiCreate(" tasks", 400,175)

GUICtrlSetColor(-1,0xFB1409)

; InputBox

GuiCtrlCreateInput( "Enter",50, 50, 90, 20)

$Button1r1 = GUICtrlCreateButton("Web", 10, 100, 85, 30)

GUISetState(@SW_SHOW)

;R1

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Button1r1

If InputBox("gmail") Then ShellExecute("http://www.gmail.com")

Case $GUI_EVENT_CLOSE

_Exit()

EndSwitch

Wend

Func _Exit()

Exit

EndFunc

GUIDelete()

I am receiving an error when I enter gmail into the text box and press the button. Also I have no idea where to even begin with the auto log in. Any help would be greatly appreciated.

Link to comment
Share on other sites

Hi all. I am very inexperienced in scripting, and I have been searching the forums as well as the Help file for an answer to my question. (Which is the only reason Ive gotten this far.)

I am trying to write a script that will look at the text in a text box to determine what will happen when you click a button. For example if you type Gmail into the text box and press the button Web it will take you to the Gmail log in page and input your credentials and log you in.

So far this is what I have:

#include <GUIConstants.au3>

; GUI

$GUI1 = GuiCreate(" tasks", 400,175)

GUICtrlSetColor(-1,0xFB1409)

; InputBox

GuiCtrlCreateInput( "Enter",50, 50, 90, 20)

$Button1r1 = GUICtrlCreateButton("Web", 10, 100, 85, 30)

GUISetState(@SW_SHOW)

;R1

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Button1r1

If InputBox("gmail") Then ShellExecute("http://www.gmail.com")

Case $GUI_EVENT_CLOSE

_Exit()

EndSwitch

Wend

Func _Exit()

Exit

EndFunc

GUIDelete()

I am receiving an error when I enter gmail into the text box and press the button. Also I have no idea where to even begin with the auto log in. Any help would be greatly appreciated.

Welcome to AutoIt forums :D

To read an input you need to assign it to a variable the same way you did with the button. Then you read it with GuiCtrlRead.

When you post code yu can enclose it in code tags [ code ] blah blah [ /code ] but without the spaces inside the square brackets.

Also, to make things easier for you and anyone else to read, use Scite and the Tidy option with Ctrl T.

#include <GUIConstants.au3>

; GUI
$GUI1 = GUICreate(" tasks", 400, 175)
GUICtrlSetColor(-1, 0xFB1409)

; InputBox
$ipbox = GUICtrlCreateInput("Enter", 50, 50, 90, 20)

$Button1r1 = GUICtrlCreateButton("Web", 10, 100, 85, 30)

GUISetState(@SW_SHOW)

;R1
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $Button1r1, $ipbox
            $data = StringStripWS(GUICtrlRead($ipbox), 3);$data is the contents of the input, but remove leading and trailng spaces
        ;ConsoleWrite($data & @CRLF)
            Select
                Case $data = "gmail"
                    ShellExecute("http://www.gmail.com")
                Case $data = "exit"
                    _Exit()
            EndSelect

        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc  ;==>_Exit

GUIDelete()

Edit: simplified a bit

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You need to get the ControlID from the GuiCtrlCreateInput function ($hInput below). Then to read what is inside the input field use GuiCtrlRead.

#include <GUIConstants.au3>

; GUI
$GUI1 = GUICreate(" tasks", 400, 175)
GUICtrlSetColor(-1, 0xFB1409)

; InputBox
$hInput = GUICtrlCreateInput("Enter", 50, 50, 90, 20)

$Button1r1 = GUICtrlCreateButton("Web", 10, 100, 85, 30)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $Button1r1
            ShellExecute("http://www." & GuiCtrlRead($hInput) & ".com")
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc

GUIDelete()
Link to comment
Share on other sites

With the one underneth:

Case $Button1r1
If InputBox("gmail") Then ShellExecute("http://www.gmail.com")

you are not refering to your input.. you need to set the input as a variable like this:

$test = GuiCtrlCreateInput( "Enter",50, 50, 90, 20)

And then make the case when the button is pressed like this:

Case $Button1r1

If GUICtrlRead($test) = "Gmail" Then
    ShellExecute("http://www.gmail.com")
EndIf

Hope it helps.

EDIT: Since they others was before me :D I will try do something else. I don't know how far you will take it, but if you are trying to make a toolbar or something where you just type in some commands and then the program will do something for you. then you could try looking on this little example:

#include <GUIConstants.au3>

$GUI = GuiCreate(" tasks", 200,100)
$data = GuiCtrlCreateInput( "Enter",20,20,100,20)
$Button1 = GUICtrlCreateButton("Web", 20,50,85,30)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $Button1
        _command()
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
Wend

Func _command()
$choice = GUICtrlRead($data)
    Select
        Case $choice = "Gmail"
            ShellExecute("http://www.gmail.com")
        Case $choice = "Notebook"
            Run("Calc")
        Case $choice = "Google"
            ShellExecute("http://www.google.com")
    EndSelect
EndFunc ;_command()
Edited by newbiescripter
Link to comment
Share on other sites

#include <GUIConstants.au3>

$GUI = GuiCreate(" tasks", 200,100)
$data = GuiCtrlCreateInput( "Enter",20,20,100,20)
$Button1 = GUICtrlCreateButton("Web", 20,50,85,30)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $Button1
        _command()
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
Wend

Func _command()
$choice = GUICtrlRead($data)
    Select
        Case $choice = "Gmail"
            ShellExecute("http://www.gmail.com")
        Case $choice = "Notebook"
            Run("Calc")
        Case $choice = "Google"
            ShellExecute("http://www.google.com")
    EndSelect
EndFunc ;_command()
Thanks everyone for all the help...I now understand the relationships above . So I thought that continuing with a second button would be fairly simple. But oh I was wrong... I believe where I am going wrong is in the "While" section. I thought it would be as simple as adding a knew button, then repeating the While function and renaming it to While 2 instead of While 1. This is what I have done.:

#include <GUIConstants.au3>

$GUI = GUICreate(" tasks", 200, 100)
$data = GUICtrlCreateInput("Enter", 20, 20, 100, 20)
$Button1 = GUICtrlCreateButton("Web", 20, 50, 85, 30)
$Button2 = GUICtrlCreateButton("Web", 20, 100, 85, 30)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            _command()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _command()
    $choice = GUICtrlRead($data)
    Select
        Case $choice = "Gmail"
            ShellExecute("http://www.gmail.com")
        Case $choice = "Notepad"
            Run("notepad")
        Case $choice = "Google"
            ShellExecute("http://www.google.com")
        Case $choice = "slorl_ors"
            ShellExecute("http://slorl.alsco.com:8080/")
            
    EndSelect

    While 2
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Button2
                _command()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd

    Func _command()
        $choice = GUICtrlRead($data)
        Select
            Case $choice = "Gmail"
                ShellExecute("http://www.gmail.com")
            Case $choice = "Notepad"
                Run("notepad")
            Case $choice = "Google"
                ShellExecute("http://www.google.com")
            Case $choice = "slorl_ors"
                ShellExecute("http://slorl.alsco.com:8080/")
                
        EndSelect
    EndFunc

Can someone look at what I'm doing wrong and help me? Thanks in advance.

Edited by wtd73
Link to comment
Share on other sites

Well you can do what you describes in the PM like the following:

#include <GUIConstants.au3>

$GUI = GuiCreate(" tasks", 200,100)
$data = GuiCtrlCreateInput( "Enter",20,20,100,20)
$Button1 = GUICtrlCreateButton("Web", 20,50,85,30)
$Button2 = GUICtrlCreateButton("Launch", 105,50,85,30)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $Button1
        _command()
    Case $Button2
        _launch()
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
Wend

Func _command()
$choice = GUICtrlRead($data)
    Select
        Case $choice = "Gmail"
            ShellExecute("http://www.gmail.com")
        Case $choice = "Notebook"
            Run("Calc")
        Case $choice = "Google"
            ShellExecute("http://www.google.com")
    EndSelect
EndFunc;_command()

Func _launch()
$string = GUICtrlRead($data)
ShellExecute("www." & $string & ".something.com")
EndFunc; _launch()

It is almost the same as I did before, just added an extra button calling the function launch like you wanted. and then you can see how the rest works by you self. it is pretty simpel..

Regards

Link to comment
Share on other sites

I did figure it out. I sent the PM to you yesterday afternoon, so when I didn't here anything from you earlier today, I hit the help file... (Which was probably better for me since it forced me to read and re-read.) While I was reading the help file it just hit me and I said to myself "I understand now."

I've got everything working fine except one function. But I want to keep trying to get it to work..

Thanks for the help

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