Jump to content

Case hangs when reading null from ini file


Bodman
 Share

Recommended Posts

Hi, With a bit of help from peeps in the GUI section I nearly have my script running The idea is a drop down menu is created from data in a ini file. I would like this ini file to be variable in size and the drop down auto fit to suit. The problem I have is if the ini file is not fully populated (with 10 sites) then when I run the script the GUI box cannot be closed and a webpage is opened.

(homepage)

If I populate the ini then the script works fine. im sure its something silly ive missed/added but I cannt find it for the life of me

Any help greatly appreciated.

ini file reads

[sites]

Site1=Site Number 1

URL1=http://www.url1.com

Site2=

URL2=

Site3=

URL3=

Site4=

URL4=

Site5=

URL5=

Site6=

URL6=

Site7=

URL7=

Site8=

URL8=

Site9=

URL9=

Site10=

URL10=

#include <GuiConstants.au3>
#include <String.au3>
Global $menustate



;Enters your 01 details (encrypted) into registry
If @Error then
$user = InputBox ("enter username", "please enter your 01 username","xxxxxxx01","",10,  5, 300, 20)
$pass = InputBox ("enter password", "please enter your 01 password","","*",10,  5, 300, 20)
$passenc = _StringEncrypt ( 1, $pass, "passkey" )
RegWrite("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Username", "REG_SZ", "ecdomain\" & $user)
RegWrite("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Password", "REG_SZ",  $passenc)
EndIf

ECAP()

;Sends the userid and pass info from registry
Func Pass()
$usera = RegRead ("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Username")
$passenca = RegRead ("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Password")
$passdec = _StringEncrypt ( 0, $passenca, "passkey" )   
    WinWaitActive("Connect to ecap.ecdomain.net", "" )
    ControlSend("Connect to ecap.ecdomain.net", "", "Edit2", $usera)
    ControlSend("Connect to ecap.ecdomain.net", "", "Edit3", $passdec)
    ControlClick("Connect to ecap.ecdomain.net", "", "Button1")
    $Menustate = ""
EndFunc


Func ECAP()

;Read sites and URL's from ini file
$site1 = IniRead("ecap.ini", "Sites", "Site1", "")
$URL1 = IniRead("ecap.ini", "Sites", "URL1", "")
$site2 = IniRead("ecap.ini", "Sites", "Site2", "")
$URL2 = IniRead("ecap.ini", "Sites", "URL2", "")
$site3 = IniRead("ecap.ini", "Sites", "Site3", "")
$URL3 = IniRead("ecap.ini", "Sites", "URL3", "")
$site4 = IniRead("ecap.ini", "Sites", "Site4", "")
$URL4 = IniRead("ecap.ini", "Sites", "URL4", "")
$site5 = IniRead("ecap.ini", "Sites", "Site5", "")
$URL5 = IniRead("ecap.ini", "Sites", "URL5", "")
$site6 = IniRead("ecap.ini", "Sites", "Site6", "")
$URL6 = IniRead("ecap.ini", "Sites", "URL6", "")
$site7 = IniRead("ecap.ini", "Sites", "Site7", "")
$URL7 = IniRead("ecap.ini", "Sites", "URL7", "")
$site8 = IniRead("ecap.ini", "Sites", "Site8", "")
$URL8 = IniRead("ecap.ini", "Sites", "URL8", "")
$site9 = IniRead("ecap.ini", "Sites", "Site9", "")
$URL9 = IniRead("ecap.ini", "Sites", "URL9", "")
$site10 = IniRead("ecap.ini", "Sites", "Site10", "")
$URL10 = IniRead("ecap.ini", "Sites", "URL10", "")



;Create Menu
$GUI_Handle = GuiCreate("Ecap", 199, 41,(@DesktopWidth-199)/2, (@DesktopHeight-41)/2)

$Combo_1 = GUICtrlCreateCombo("Select", 10, 10, 140, 21)

;Resizes Dropdown menu so blanks aren't shown
$sCombo = ""
For $i = 1 To 10
    $j = Eval("site" & $i)
    If $j <> "" Then $sCombo &= $j & "|"
Next
StringTrimRight($sCombo, 1)

GUICtrlSetData($Combo_1, $sCombo, "Select")

$Button_2 = GuiCtrlCreateButton("OK", 160, 10, 30, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop

    Case $msg = $Button_2
        $Menustate  = GUICtrlRead($Combo_1)

    MsgBox(4096, "Result", $Menustate)

 Case $menustate = $site1  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url1 )
    pass()
        
 Case $menustate = $site2  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url2 )
    pass()
    
 Case $menustate = $site3  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url3 )
    pass()
    
 Case $menustate = $site4  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url4 )
    pass()
    
 Case $menustate = $site5  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url5 )
    pass()
    
 Case $menustate = $site6  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url6 )
    pass()
    
 Case $menustate = $site7  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url7 )
    pass()
    
 Case $menustate = $site8  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url8 )
    pass()
    
 Case $menustate = $site9  
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url9 )
    pass()
    
 Case $menustate = $site10 
     run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $url10 )
    pass()
    
EndSelect

WEnd
EndFunc
Edited by Bodman
Link to comment
Share on other sites

IniRead ( "filename", "section", "key", "default" )

If you don't want it to be NULL then make..

$site1 = IniRead("ecap.ini", "Sites", "Site1", "")
$URL1 = IniRead("ecap.ini", "Sites", "URL1", "")
$site2 = IniRead("ecap.ini", "Sites", "Site2", "")
$URL2 = IniRead("ecap.ini", "Sites", "URL2", "")
$site3 = IniRead("ecap.ini", "Sites", "Site3", "")
$URL3 = IniRead("ecap.ini", "Sites", "URL3", "")
$site4 = IniRead("ecap.ini", "Sites", "Site4", "")
$URL4 = IniRead("ecap.ini", "Sites", "URL4", "")
$site5 = IniRead("ecap.ini", "Sites", "Site5", "")
$URL5 = IniRead("ecap.ini", "Sites", "URL5", "")
$site6 = IniRead("ecap.ini", "Sites", "Site6", "")
$URL6 = IniRead("ecap.ini", "Sites", "URL6", "")
$site7 = IniRead("ecap.ini", "Sites", "Site7", "")
$URL7 = IniRead("ecap.ini", "Sites", "URL7", "")
$site8 = IniRead("ecap.ini", "Sites", "Site8", "")
$URL8 = IniRead("ecap.ini", "Sites", "URL8", "")
$site9 = IniRead("ecap.ini", "Sites", "Site9", "")
$URL9 = IniRead("ecap.ini", "Sites", "URL9", "")
$site10 = IniRead("ecap.ini", "Sites", "Site10", "")
$URL10 = IniRead("ecap.ini", "Sites", "URL10", "")

This..

$site1 = IniRead("ecap.ini", "Sites", "Site1", "-1")
$URL1 = IniRead("ecap.ini", "Sites", "URL1", "-1")
$site2 = IniRead("ecap.ini", "Sites", "Site2", "-1")
$URL2 = IniRead("ecap.ini", "Sites", "URL2", "-1")
$site3 = IniRead("ecap.ini", "Sites", "Site3", "-1")
$URL3 = IniRead("ecap.ini", "Sites", "URL3", "-1")
$site4 = IniRead("ecap.ini", "Sites", "Site4", "-1")
$URL4 = IniRead("ecap.ini", "Sites", "URL4", "-1")
$site5 = IniRead("ecap.ini", "Sites", "Site5", "-1")
$URL5 = IniRead("ecap.ini", "Sites", "URL5", "-1")
$site6 = IniRead("ecap.ini", "Sites", "Site6", "-1")
$URL6 = IniRead("ecap.ini", "Sites", "URL6", "-1")
$site7 = IniRead("ecap.ini", "Sites", "Site7", "-1")
$URL7 = IniRead("ecap.ini", "Sites", "URL7", "-1")
$site8 = IniRead("ecap.ini", "Sites", "Site8", "-1")
$URL8 = IniRead("ecap.ini", "Sites", "URL8", "-1")
$site9 = IniRead("ecap.ini", "Sites", "Site9", "-1")
$URL9 = IniRead("ecap.ini", "Sites", "URL9", "-1")
$site10 = IniRead("ecap.ini", "Sites", "Site10", "-1")
$URL10 = IniRead("ecap.ini", "Sites", "URL10", "-1")

That way if there is no value in the INI file it will be -1.. next time please use the help file ;].

Hope this helps.

- John :D

Edited by John2006

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Thanks for the reply John, I have tried changeing what you said to -1 but unfortunatley the script still hangs. It appears that once the case command hits no info it crashes

//Bod

Edited by Bodman
Link to comment
Share on other sites

No reason to have redundant code:

#include <GuiConstants.au3>
#include <String.au3>
Global $menustate

;Enters your 01 details (encrypted) into registry
If @error Then
    $user = InputBox("enter username", "please enter your 01 username", "xxxxxxx01", "", 10, 5, 300, 20)
    $pass = InputBox("enter password", "please enter your 01 password", "", "*", 10, 5, 300, 20)
    $passenc = _StringEncrypt(1, $pass, "passkey")
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Username", "REG_SZ", "ecdomain\" & $user)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Password", "REG_SZ", $passenc)
EndIf

ECAP()

;Sends the userid and pass info from registry
Func Pass()
    $usera = RegRead("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Username")
    $passenca = RegRead("HKEY_CURRENT_USER\SOFTWARE\Ecap", "Password")
    $passdec = _StringEncrypt(0, $passenca, "passkey")
    WinWaitActive("Connect to ecap.ecdomain.net", "")
    ControlSend("Connect to ecap.ecdomain.net", "", "Edit2", $usera)
    ControlSend("Connect to ecap.ecdomain.net", "", "Edit3", $passdec)
    ControlClick("Connect to ecap.ecdomain.net", "", "Button1")
    $menustate = ""
EndFunc   ;==>Pass


Func ECAP()
    Local $array[10][2]
    
    ;Read sites and URL's from ini file
    For $X = 1 to 10
        $array[$X-1][0] = IniRead("ecap.ini", "Sites", "Site" & $X, "")
        $array[$X-1][1] = IniRead("ecap.ini", "Sites", "URL" & $X, "")        
    Next

    ;Create Menu
    $GUI_Handle = GUICreate("Ecap", 199, 41, (@DesktopWidth - 199) / 2, (@DesktopHeight - 41) / 2)

    $Combo_1 = GUICtrlCreateCombo("Select", 10, 10, 140, 21)

    ;Resizes Dropdown menu so blanks aren't shown
    $sCombo = ""
    For $i = 1 To 10
        $j = Eval("site" & $i)
        If $j <> "" Then $sCombo &= $j & "|"
    Next
    StringTrimRight($sCombo, 1)

    GUICtrlSetData($Combo_1, $sCombo, "Select")

    $Button_2 = GUICtrlCreateButton("OK", 160, 10, 30, 20)

    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $Button_2
                $menustate = GUICtrlRead($Combo_1)

                MsgBox(4096, "Result", $menustate)

            Case $menustate = $site1
                Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $URL1)
                Pass()

        EndSelect
    
    ;Check for matching menu state
    For $X = 1 to 10
        If $menustate = $array[$X-1][0] Then
            Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new " & $array[$X-1][1])
            Pass()
        EndIf
    Next

    WEnd
EndFunc   ;==>ECAP
Edited by weaponx
Link to comment
Share on other sites

Thanks for that Weaponx it has made my code a lot smaller but unfortuntley I dont get anything at all in the drop down box now.

My code also seems to be stuck in the While - Wend loop but I cant see my mistake :D

Thanks again

Bod

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