Sign in to follow this  
Followers 0
sumit

Is there any goto type command

11 posts in this topic

Please tell me if there is any goto type command.

Share this post


Link to post
Share on other sites



@sumit, do you need help making something work? Post your code and we can help you get it working (even if it has the non existent command ' goto ' ). With no goto, most people just use loops and functions.

Share this post


Link to post
Share on other sites

Thanks for replying

This is the code that i have written

g_szVersion = "My Script 1.1"
If WinExists($g_szVersion) Then
MsgBox(48, "MPT Broadband", "Program already running")
Exit
Endif
AutoItWinSetTitle($g_szVersion)
$ReadUserName = IniRead("c:\windows\mpt.ini", "Data", "Username", "")
$ReadUserPass = _StringEncrypt(0, IniRead("c:\windows\mpt.ini", "Data", "Password", ""), "0000", 2)
$Main = GUICreate('Welcome to MPT Broadband', 300, 100)
Opt("GUICoordMode",1)
$username = GUICtrlCreateInput($ReadUserName,100,20,100)
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$password = GUICtrlCreateInput($ReadUserPass,100,45,100,0,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',30,48)
$Button_1 = GUICtrlCreateButton ("OK", 190, 70, 0, 0, 0x0001)
$Button_2 = GUICtrlCreateButton ("Exit", 245, 70, 0, 0)
$checkbox = GUICtrlCreateCheckbox("Save password", 10, 70)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button_1
$check = GUICtrlRead($checkbox)
GLOBAL $collectusername = GUICtrlRead($username)
GLOBAL $collectpassword = GUICtrlRead($password)
If $check = $GUI_CHECKED Then
IniWrite("c:\windows\mpt.ini", "Data", "Username", $collectusername)
IniWrite("c:\windows\mpt.ini", "Data", "Password", _StringEncrypt(1, $collectpassword, "0000", 2))
EndIf
GUIDelete()
ExitLoop
Case $msg = $Button_2
Exit
EndSelect
Wend
GuiCreate("Connecting...... Please Wait", 212, 40,-1, -1 , BitAND($WS_POPUP, $SS_CENTER))
GUISetBkColor(0xFFF)
GUISetState ()
$oIE = _IECreate ("http://mptadsl.net.mm/WGarden/Popup.php", 0, 0, 1, 0)
_IELoadWait($oIE)
If WinExists("Cannot")  Then
_IEQuit($oIE)
$var = Ping("172.24.0.3",1000)
If $var Then
GUIDelete()
MsgBox(48, "Unable to Connect to Server", "Please Check the Proxy Settings in Internet Explorer")
Exit
Else
GUIDelete()
MsgBox(48, "Unable to Connect to Server", "Please Check your IP Address")
Endif
Exit
EndIf
$oForm = _IEFormGetObjByName ($oIE, "form1")
$oQuery = _IEFormElementGetObjByName ($oForm, "username")
_IEFormElementSetValue ($oQuery, $collectusername)
$oQuery = _IEFormElementGetObjByName ($oForm, "password")
_IEFormElementSetValue ($oQuery, $collectpassword)
_IEFormSubmit ($oForm)
_IELoadWait($oIE)
If WinExists("AutoComplete") Then Send("{ENTER}")
If WinExists("Internet Explorer") Then Send("{ENTER}")
If WinExists("Internet Access") Then
WinClose("Internet Access")
Opt("TrayMenuMode",1)
$prefsitem  = TrayCreateItem("Browse")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exititem   = TrayCreateItem("Logout")
GUIDelete()
TraySetState()
TraySetIcon("Shell32.dll",73)
TrayTip("Welcome to MPT", "You are now connected to Internet", 5,1)
While 1
$msg = TrayGetMsg()
Select
Case $msg = 0
ContinueLoop
Case $msg = $prefsitem
$oIE = _IECreate ("about:blank")
WinSetState("about","",@SW_MAXIMIZE)
Case $msg = $aboutitem
Msgbox(64, "About:", "MPT Broadband Internet Access Client")
Case $msg = $exititem
ExitLoop
EndSelect
WEnd
GuiCreate("Disconnecting...... Please Wait", 212, 40,-1, -1 , BitAND($WS_POPUP, $SS_CENTER))
GUISetBkColor(0xFFF)
GUISetState()
$oIE = _IECreate ("http://mptadsl.net.mm/WGarden/Popup.php", 0, 0, 1, 0)
_IELoadWait($oIE)
If WinExists("Cannot")  Then
_IEQuit($oIE)
$var = Ping("172.24.0.3",1000)
If $var Then
GUIDelete()
MsgBox(48, "Unable to Logout", "Please Correct the Proxy Settings in Internet Explorer and restart the client")
Exit
Else
GUIDelete()
MsgBox(48, "Unable to Logout", "Please Check your IP Address and restart the client")
Endif
Exit
EndIf
$oForm = _IEFormGetObjByName ($oIE, "form1")
$oQuery = _IEFormElementGetObjByName ($oForm, "username")
_IEFormElementSetValue ($oQuery, $collectusername)
$oQuery = _IEFormElementGetObjByName ($oForm, "password")
_IEFormElementSetValue ($oQuery, $collectpassword)
_IEFormSubmit ($oForm)
_IELoadWait($oIE)
$oLogoutBtn = _IEGetObjByName($oIE, 'Submit')
_IEAction ($oLogoutBtn, "click")
_IELoadWait($oIE)
WinClose("Internet Access")
GUIDelete()
MsgBox(4096, "MPT", "You have successfully logged out. Thank you for using MPT Broadband Internet Access")
Else
WinClose("User Authentication")
GuiDelete()
MsgBox(4096, "MPT", "Invalid Username or Password")

But i dont like the long If Else statements also I need to add some Elseif Statements in this code. So can you help me tidy up this code with functions cause its breaking up my head how to add else if etc. ( I have never used functions )

Share this post


Link to post
Share on other sites

where is the problem here. It might be messy, but (who cares) what doesn't work?

Share this post


Link to post
Share on other sites

where is the problem here. It might be messy, but (who cares) what doesn't work?

The problem is

after this part

If WinExists("Cannot")   Then
_IEQuit($oIE)
$var = Ping("172.24.0.3",1000)
If $var Then
GUIDelete()
MsgBox(48, "Unable to Logout", "Please Correct the Proxy Settings in Internet Explorer and restart the client")
Exit

I want to add

Elseif  WinExists("No page")     Then
_IEQuit($oIE)
$var = Ping("172.24.0.3",1000)
If $var Then
GUIDelete()
MsgBox(48, "Unable to Logout", "Please Correct the Proxy Settings in Internet Explorer and restart the client")
Exit

Elseif If WinExists("Error:")    Then
_IEQuit($oIE)
$var = Ping("172.24.0.3",1000)
If $var Then
GUIDelete()
MsgBox(48, "Unable to Logout", "Please Correct the Proxy Settings in Internet Explorer and restart the client")
Exit

but when i try to add them i am not able to put proper Endif ( get confused ) and it doesnt work. If i could use functions maybe it would be better.

Share this post


Link to post
Share on other sites

some syntax highlighting and indenting can make the appearence better-

$g_szVersion = "My Script 1.1"
If WinExists($g_szVersion) Then
    MsgBox(48, "MPT Broadband", "Program already running")
    Exit
Endif
Opt("GUICoordMode",1)
AutoItWinSetTitle($g_szVersion)
$ReadUserName = IniRead("c:\windows\mpt.ini", "Data", "Username", "")
$ReadUserPass = _StringEncrypt(0, IniRead("c:\windows\mpt.ini", "Data", "Password", ""), "0000", 2)
$Main = GUICreate('Welcome to MPT Broadband', 300, 100)
$username = GUICtrlCreateInput($ReadUserName,100,20,100)
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$password = GUICtrlCreateInput($ReadUserPass,100,45,100,0,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',30,48)
$Button_1 = GUICtrlCreateButton ("OK", 190, 70, 0, 0, 0x0001)
$Button_2 = GUICtrlCreateButton ("Exit", 245, 70, 0, 0)
$checkbox = GUICtrlCreateCheckbox("Save password", 10, 70)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Button_1
            $check = GUICtrlRead($checkbox)
            GLOBAL $collectusername = GUICtrlRead($username)
            GLOBAL $collectpassword = GUICtrlRead($password)
            If $check = $GUI_CHECKED Then
                IniWrite("c:\windows\mpt.ini", "Data", "Username", $collectusername)
                IniWrite("c:\windows\mpt.ini", "Data", "Password", _StringEncrypt(1, $collectpassword, "0000", 2))
            EndIf
            GUIDelete()
            ExitLoop
        Case $msg = $Button_2
            Exit
    EndSelect
Wend

GuiCreate("Connecting...... Please Wait", 212, 40,-1, -1 , BitAND($WS_POPUP, $SS_CENTER))
GUISetBkColor(0xFFF)
GUISetState ()
$oIE = _IECreate ("http://mptadsl.net.mm/WGarden/Popup.php", 0, 0, 1, 0)
_IELoadWait($oIE)
If WinExists("Cannot") Then
    _IEQuit($oIE)
    $var = Ping("172.24.0.3",1000)
    If $var Then
        GUIDelete()
        MsgBox(48, "Unable to Connect to Server", "Please Check the Proxy Settings in Internet Explorer")
        Exit
    Else
        GUIDelete()
        MsgBox(48, "Unable to Connect to Server", "Please Check your IP Address")
    Endif
    Exit
EndIf
$oForm = _IEFormGetObjByName ($oIE, "form1")
$oQuery = _IEFormElementGetObjByName ($oForm, "username")
_IEFormElementSetValue ($oQuery, $collectusername)
$oQuery = _IEFormElementGetObjByName ($oForm, "password")
_IEFormElementSetValue ($oQuery, $collectpassword)
_IEFormSubmit ($oForm)
_IELoadWait($oIE)
If WinExists("AutoComplete") Then Send("{ENTER}")
If WinExists("Internet Explorer") Then Send("{ENTER}")
If WinExists("Internet Access") Then
    WinClose("Internet Access")
    Opt("TrayMenuMode",1)
    $prefsitem  = TrayCreateItem("Browse")
    TrayCreateItem("")
    $aboutitem  = TrayCreateItem("About")
    TrayCreateItem("")
    $exititem   = TrayCreateItem("Logout")
    GUIDelete()
    TraySetState()
    TraySetIcon("Shell32.dll",73)
    TrayTip("Welcome to MPT", "You are now connected to Internet", 5,1)
    
    While 1
        $msg = TrayGetMsg()
        Select
            Case $msg = 0
                ContinueLoop
            Case $msg = $prefsitem
                $oIE = _IECreate ("about:blank")
                WinSetState("about","",@SW_MAXIMIZE)
            Case $msg = $aboutitem
                Msgbox(64, "about:", "MPT Broadband Internet Access Client")
            Case $msg = $exititem
            ExitLoop
        EndSelect
    WEnd
    
    GuiCreate("Disconnecting...... Please Wait", 212, 40,-1, -1 , BitAND($WS_POPUP, $SS_CENTER))
    GUISetBkColor(0xFFF)
    GUISetState()
    $oIE = _IECreate ("http://mptadsl.net.mm/WGarden/Popup.php", 0, 0, 1, 0)
    _IELoadWait($oIE)
    If WinExists("Cannot") Then
        _IEQuit($oIE)
        $var = Ping("172.24.0.3",1000)
        If $var Then
            GUIDelete()
            MsgBox(48, "Unable to Logout", "Please Correct the Proxy Settings in Internet Explorer and restart the client")
            Exit
        Else
            GUIDelete()
            MsgBox(48, "Unable to Logout", "Please Check your IP Address and restart the client")
        Endif
        Exit
    EndIf
    $oForm = _IEFormGetObjByName ($oIE, "form1")
    $oQuery = _IEFormElementGetObjByName ($oForm, "username")
    _IEFormElementSetValue ($oQuery, $collectusername)
    $oQuery = _IEFormElementGetObjByName ($oForm, "password")
    _IEFormElementSetValue ($oQuery, $collectpassword)
    _IEFormSubmit ($oForm)
    _IELoadWait($oIE)
    $oLogoutBtn = _IEGetObjByName($oIE, 'Submit')
    _IEAction ($oLogoutBtn, "click")
    _IELoadWait($oIE)
    WinClose("Internet Access")
    GUIDelete()
    MsgBox(4096, "MPT", "You have successfully logged out. Thank you for using MPT Broadband Internet Access")
Else
    WinClose("User Authentication")
    GuiDelete()
    MsgBox(4096, "MPT", "Invalid Username or Password")
EndIf

Share this post


Link to post
Share on other sites

Thanks Guys... Now its working.....

Share this post


Link to post
Share on other sites

If all these cases are exclusive

If WinExists("Cannot") Then

Elseif WinExists("No page") Then

Elseif If WinExists("Error:") Then

why not replace them with a Select statement:

Select
   Case WinExists("Cannot")
     ;do stuff
   Case WinExists("No page")
     ;do stuff
   Case WinExists("Error:")
     ;do stuff
   Case Else
     ;do stuff
EndSelect

Not a big improvement just making the code easier to read and avoiding long If-ElseIf statements.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Thanks ...

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