Sign in to follow this  
Followers 0
alanpt

Tinyurl launcher for primary school students - a couple of simple problems

6 posts in this topic

Hi, I have a few problems I can't wrap my head around on a little program I made.

This is a simple website launcher for the 5 to 10 year old I work with in a couple of schools. I use tinyurl to make short and easy "passcodes" for the students to type in instead of having to go through the process of opening a browser and typing in a complex and long web address. This works really well, but I have a couple of bugs I need to fix in my script to make it easier.

1) You need to press the button instead of just pressing enter.

2) If nothing is entered the tinyurl website still loads up.

Could someone please point me in the right direction to solve this, Thanks.

#include <GUIConstantsEx.au3>

opt('MustDeclareVars', 0)

Example()

Func Example()
    Local $answer, $btn, $msg
    
    GUICreate("Tiny URL Launcher", 780, 70, @DesktopWidth / 2 - 370, @DesktopHeight / 2 - 45, -1)
    
       $font = "Verdana"
    GUISetFont(30, 400, 4, $font)  
    GUICtrlCreateLabel ( "http://www.tinyurl.com/", 10, 10 )
    $answer = GUICtrlCreateInput("", 510, 5, 200, 60)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
      GUISetFont(9, 400, 1, $font)
    $btn = GUICtrlCreateButton("GO", 710, 5, 60, 60)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ExitLoop
        EndSelect
    WEnd
$address = GUICtrlRead($answer)
ShellExecute("iexplore.exe", "http://www.tinyurl.com/" & $address, @SW_MAXIMIZE)
EndFunc

tinyurl.au3

Share this post


Link to post
Share on other sites



Whats wrong with it? Its working for me. The only thing I changed was:

ShellExecute("iexplore.exe", "http://www.tinyurl.com/" & $address, @SW_MAXIMIZE)

To

ShellExecute("http://www.tinyurl.com/" & $address)

Tell me if missed something. :)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

First, add this before any GUI code:

Opt("GUIOnEventMode", 1)

Place this right after the button's creation:

GUICtrlSetOnEvent($btn, "ButtonclickFunction")

This allows a function to be called when your button is clicked. In your case, when your button is clicked, it would run the function ButtonclickFunction.

Use HotKeySet("{Enter}", "ButtonclickFunction") to run the function when the {Enter} key is pressed.

To make sure it only works when something is entered:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 0)
Opt("GUIOnEventMode", 1)
HotKeySet("{Enter}", "ButtonclickFunction")
Global $answer, $btn

Example()

Func Example()


    GUICreate("Tiny URL Launcher", 780, 70, @DesktopWidth / 2 - 370, @DesktopHeight / 2 - 45, -1)
        $font = "Verdana"
        GUISetFont(30, 400, 4, $font)
    GUICtrlCreateLabel ( "http://www.tinyurl.com/", 10, 10 )
        $answer = GUICtrlCreateInput("", 510, 5, 200, 60)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
        GUISetFont(9, 400, 1, $font)
    $btn = GUICtrlCreateButton("GO", 710, 5, 60, 60)
        GUICtrlSetOnEvent($btn, "ButtonclickFunction")
    GUISetState()

    While 1
        Sleep(1)
    WEnd
EndFunc ;==>Example

Func ButtonclickFunction()
    $address = GUICtrlRead($answer)
    If $address <> "" Then
        ShellExecute("iexplore.exe", "http://www.tinyurl.com/" & $address, @SW_MAXIMIZE)
        Exit
    Endif
EndFunc
Edited by darkjohn20

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
opt('MustDeclareVars', 0)

Example()

Func Example()
    Local $answer, $btn, $msg

    GUICreate("Tiny URL Launcher", 780, 70, @DesktopWidth / 2 - 370, @DesktopHeight / 2 - 45, -1)

       $font = "Verdana"
    GUISetFont(30, 400, 4, $font)
    GUICtrlCreateLabel ( "http://www.tinyurl.com/", 10, 10 )
    $answer = GUICtrlCreateInput("", 510, 5, 200, 60)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
      GUISetFont(9, 400, 1, $font)
    $btn = GUICtrlCreateButton("GO", 710, 5, 60, 60,$BS_DEFPUSHBUTTON )

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ExitLoop
        EndSelect
    WEnd
$address = GUICtrlRead($answer)
If StringStripWS($address,1) <> "" Then
    ShellExecute("http://tinyurl.com/" & $address,"", @SW_MAXIMIZE)
Else
    ; empty link
EndIf
EndFunc

Jos :)

Edited by Jos

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

Thanks AlmarM, Jos and darkjohn20.

Jos's code worked best for me. Darkjohn20's forced an entry to be submitted, which would have been a hastle if the program had been accidentally opened. I chose to keep the setting that forced a new ie window, tabs can still be too confusing for the students (and teachers).

This little script has saved me countless hours of having to retype broken web addresses.

Thanks again.

For future reference:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
opt('MustDeclareVars', 0)

Example()

Func Example()
    Local $answer, $btn, $msg

    GUICreate("Tiny URL Launcher", 780, 70, @DesktopWidth / 2 - 370, @DesktopHeight / 2 - 45, -1)

       $font = "Verdana"
    GUISetFont(30, 400, 4, $font)
    GUICtrlCreateLabel ( "http://www.tinyurl.com/", 10, 10 )
    $answer = GUICtrlCreateInput("", 510, 5, 200, 60)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
      GUISetFont(9, 400, 1, $font)
    $btn = GUICtrlCreateButton("GO", 710, 5, 60, 60,$BS_DEFPUSHBUTTON )

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ExitLoop
        EndSelect
    WEnd
$address = GUICtrlRead($answer)
If StringStripWS($address,1) <> "" Then
    ShellExecute("iexplore.exe", "http://www.tinyurl.com/" & $address, @SW_MAXIMIZE)

Else
    ; empty link
EndIf
EndFunc

Share this post


Link to post
Share on other sites

I've never seen Jos' way. I'll have to remember that for future reference.

Thanks Jos.

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