Jump to content

I got a few GUI questions.


Bliz0r
 Share

Recommended Posts

Hello, I need to Enable GUI when $Newprf & $Button1 is being pressed enabled, the Func Pfcr() pops up (another GUI, where you can make the profile.)

Then I need to put the new profile on $Combo1 somehow, with the profile name itself.

#include <GUIConstants.au3>
#include <File.au3>

Global $Profile
Global $Combo1
Global $Button1
Global $Button2
Global $Profmng
Global $Save
Global $Cancel
Global $Username
Global $Password
Global $Brw1
Global $Lng1
Global $Name2

$Newprf = "Create new profile"
$Profile = GUICreate ("Profile select", 150, 70, 190, 121)
$Combo1 = GUICtrlCreateCombo ($Newprf, 8, 8, 137, 25)
$Button1 = GUICtrlCreateButton ("Ok", 8, 32, 67, 25, 0)
$Button2 = GUICtrlCreateButton ("Cancel", 80, 32, 67, 25, 0)

GUISetState (@SW_SHOW)



While 1
    $pMSG = GUIGetMsg ()
    Select
        Case $pMSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $pMSG = $Button2
            Exit
        Case $pMSG = $Button1
            GUICtrlSetOnEvent ($Newprf & $Button1, "Pfcr")
    EndSelect
WEnd

Func Pfcr()

    $Profmng = GUICreate ("Profile Creation", 276, 179, 271, 226)
    $User = GUICtrlCreateInput ("Username here", 0, 64, 121, 21)
    $Pass = GUICtrlCreateInput ("", 128, 64, 121, 21, $ES_PASSWORD)
    $Browser = GUICtrlCreateCombo ("Select", 0, 112, 121, 25)
    GUICtrlSetData (-1, "Internet Explorer|Mozilla Firefox")
    $Language = GUICtrlCreateCombo ("Select", 128, 112, 121, 25)
    GUICtrlSetData (-1, "English|Danish")
    $Save = GUICtrlCreateButton ("Save", 0, 144, 75, 25, 0)
    $Cancel = GUICtrlCreateButton ("Cancel", 80, 144, 75, 25, 0)
    $Username = GUICtrlCreateLabel ("Username", 0, 48, 52, 17)
    $Password = GUICtrlCreateLabel ("Password", 128, 48, 50, 17)
    $Brw1 = GUICtrlCreateLabel ("Browser", 0, 96, 42, 17)
    $Lng1 = GUICtrlCreateLabel ("Language", 128, 96, 52, 17)
    $Name2 = GUICtrlCreateLabel ("Name", 0, 0, 32, 17)
    $Name = GUICtrlCreateInput ("Profile name here", 0, 16, 121, 21)

    GUISetState (@SW_SHOW)


    While 1
        $Prf = GUIGetMsg ()
        Select
            Case $Prf = $GUI_EVENT_CLOSE
                Exit
            Case $Prf = $Cancel
                Exit
            Case $Prf = $Save
                $hfile = _FileCreate (GUICtrlRead ($Name) & ".ini")
                
                FileOpen (GUICtrlRead ($Name) & ".ini", 1)
                If $hfile = -1 Then
                    MsgBox (0, "Error", "Unable to open file.")
                EndIf
                
                $Us1 = GuiCtrlRead ($User)
                FileWriteLine ($hfile, $Us1)
                $Pa1 = GuiCtrlRead ($Pass)
                FileWriteLine ($hfile, $Pa1)

                FileWriteLine ($hfile, GuiCtrlRead ($Language))
                FileWriteLine ($hfile, GuiCtrlRead ($Browser))

                FileClose ($hfile)
                
                Exit
        EndSelect
    WEnd
    
EndFunc

Any help regarding how to fix this, and what commands to look for would be very much appreciated, thank you. <_<

Link to comment
Share on other sites

Try this. I'm not a big fan of guictrlsetonevent so I changed it. You were using the exit command which that exits the entire program, that doesn't just delete a GUI so you have to delete the GUI, and then exit the loop with exitloop which will return you back to the main loop of the main GUI so if someone presses Okay to creating a profile then yeah.

#include <GUIConstants.au3>
#include <File.au3>

Global $Profile
Global $Combo1
Global $Button1
Global $Button2
Global $Profmng
Global $Save
Global $Cancel
Global $Username
Global $Password
Global $Brw1
Global $Lng1
Global $Name2

$Newprf = "Create new profile"
$Profile = GUICreate ("Profile select", 150, 70, 190, 121)
$Combo1 = GUICtrlCreateCombo ($Newprf, 8, 8, 137, 25)
$Button1 = GUICtrlCreateButton ("Ok", 8, 32, 67, 25, 0)
$Button2 = GUICtrlCreateButton ("Cancel", 80, 32, 67, 25, 0)

GUISetState (@SW_SHOW)



While 1
    $pMSG = GUIGetMsg ()
    Select
        Case $pMSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $pMSG = $Button2
            Exit
        Case $pMSG = $Button1
        If GUICtrlRead($Combo1) = $Newprf Then
    $Profmng = GUICreate ("Profile Creation", 276, 179, 271, 226)
    $User = GUICtrlCreateInput ("Username here", 0, 64, 121, 21)
    $Pass = GUICtrlCreateInput ("", 128, 64, 121, 21, $ES_PASSWORD)
    $Browser = GUICtrlCreateCombo ("Select", 0, 112, 121, 25)
    GUICtrlSetData (-1, "Internet Explorer|Mozilla Firefox")
    $Language = GUICtrlCreateCombo ("Select", 128, 112, 121, 25)
    GUICtrlSetData (-1, "English|Danish")
    $Save = GUICtrlCreateButton ("Save", 0, 144, 75, 25, 0)
    $Cancel = GUICtrlCreateButton ("Cancel", 80, 144, 75, 25, 0)
    $Username = GUICtrlCreateLabel ("Username", 0, 48, 52, 17)
    $Password = GUICtrlCreateLabel ("Password", 128, 48, 50, 17)
    $Brw1 = GUICtrlCreateLabel ("Browser", 0, 96, 42, 17)
    $Lng1 = GUICtrlCreateLabel ("Language", 128, 96, 52, 17)
    $Name2 = GUICtrlCreateLabel ("Name", 0, 0, 32, 17)
    $Name = GUICtrlCreateInput ("Profile name here", 0, 16, 121, 21)

    GUISetState (@SW_SHOW)


    While 1
        $Prf = GUIGetMsg ()
        Select
            Case $Prf = $GUI_EVENT_CLOSE
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Cancel
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Save
                $hfile = _FileCreate (GUICtrlRead ($Name) & ".ini")
                
                FileOpen (GUICtrlRead ($Name) & ".ini", 1)
                If $hfile = -1 Then
                    MsgBox (0, "Error", "Unable to open file.")
                EndIf
                
                $Us1 = GuiCtrlRead ($User)
                FileWriteLine ($hfile, $Us1)
                $Pa1 = GuiCtrlRead ($Pass)
                FileWriteLine ($hfile, $Pa1)

                FileWriteLine ($hfile, GuiCtrlRead ($Language))
                FileWriteLine ($hfile, GuiCtrlRead ($Browser))

                FileClose ($hfile)
                
                GUIDelete($Profmng)
                GUICtrlSetData($Combo1,"Some Data")
                ExitLoop
        EndSelect
    WEnd
Else
    MsgBox(0,'Profile','You selected ' & GUICtrlRead($Combo1))
EndIf

    EndSelect
WEnd

EDIT:Added a little extra something

Edited by Thatsgreat2345
Link to comment
Share on other sites

Not tested

#include <GUIConstants.au3>
#include <File.au3>

Global $Profile
Global $Combo1
Global $Button1
Global $Button2
Global $Profmng
Global $Save
Global $Cancel
Global $Username
Global $Password
Global $Brw1
Global $Lng1
Global $Name2

$Newprf = "Create new profile"
$Profile = GUICreate ("Profile select", 150, 70, 190, 121)
$Combo1 = GUICtrlCreateCombo ($Newprf, 8, 8, 137, 25)
$Button1 = GUICtrlCreateButton ("Ok", 8, 32, 67, 25, 0)
$Button2 = GUICtrlCreateButton ("Cancel", 80, 32, 67, 25, 0)

GUISetState (@SW_SHOW)



While 1
    $pMSG = GUIGetMsg ()
    Select
        Case $pMSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $pMSG = $Button2
            Exit
        Case $pMSG = $Button1
            Pfcr()
    EndSelect
WEnd

Func Pfcr()

    $Profmng = GUICreate ("Profile Creation", 276, 179, 271, 226)
    $User = GUICtrlCreateInput ("Username here", 0, 64, 121, 21)
    $Pass = GUICtrlCreateInput ("", 128, 64, 121, 21, $ES_PASSWORD)
    $Browser = GUICtrlCreateCombo ("Select", 0, 112, 121, 25)
    GUICtrlSetData (-1, "Internet Explorer|Mozilla Firefox")
    $Language = GUICtrlCreateCombo ("Select", 128, 112, 121, 25)
    GUICtrlSetData (-1, "English|Danish")
    $Save = GUICtrlCreateButton ("Save", 0, 144, 75, 25, 0)
    $Cancel = GUICtrlCreateButton ("Cancel", 80, 144, 75, 25, 0)
    $Username = GUICtrlCreateLabel ("Username", 0, 48, 52, 17)
    $Password = GUICtrlCreateLabel ("Password", 128, 48, 50, 17)
    $Brw1 = GUICtrlCreateLabel ("Browser", 0, 96, 42, 17)
    $Lng1 = GUICtrlCreateLabel ("Language", 128, 96, 52, 17)
    $Name2 = GUICtrlCreateLabel ("Name", 0, 0, 32, 17)
    $Name = GUICtrlCreateInput ("Profile name here", 0, 16, 121, 21)

    GUISetState (@SW_SHOW)


    While 1
        $Prf = GUIGetMsg ()
        Select
            Case $Prf = $GUI_EVENT_CLOSE
                ExitLoop
            Case $Prf = $Cancel
                ExitLoop
            Case $Prf = $Save
                $hfile = _FileCreate (GUICtrlRead ($Name) & ".ini")
                
                FileOpen (GUICtrlRead ($Name) & ".ini", 1)
                If $hfile = -1 Then
                    MsgBox (0, "Error", "Unable to open file.")
                EndIf
                
                $Us1 = GuiCtrlRead ($User)
                FileWriteLine ($hfile, $Us1)
                $Pa1 = GuiCtrlRead ($Pass)
                FileWriteLine ($hfile, $Pa1)

                FileWriteLine ($hfile, GuiCtrlRead ($Language))
                FileWriteLine ($hfile, GuiCtrlRead ($Browser))

                FileClose ($hfile)
                
                ExitLoop
        EndSelect
    WEnd
    
EndFunc

8)

Thats Great, got beat by 2,3,4,5 seconds...lol

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Well, I only teach in stages, that way they can learn more

lol... I forgot!

8)

I'd recommend this great tool to help you remember its called Autoit 1-2-3.... Oh wait <_<

But blitz it all depends on if you want to use the on event mode, or not bother with a bunch of different functions and just use one loop. I prefer one loop as sometimes with using functions transferring variables around can be a hassle

Link to comment
Share on other sites

So far, so good. But I'm having a bit of trouble getting the profile named the same as the name variable.

GUICtrlSetData($Combo1, (GUICtrlRead($Name)))

Beside that, is there any possible way that it'll keep on remembering the profile, so the profile wont have to be remade every time the script is being runned? <_<

Link to comment
Share on other sites

Perhaps...

#include <GUIConstants.au3>
#include <File.au3>

Global $Profile
Global $Combo1
Global $Button1
Global $Button2
Global $Profmng
Global $Save
Global $Cancel
Global $Username
Global $Password
Global $Brw1
Global $Lng1
Global $Name2

$Newprf = "Create new profile"
$Profile = GUICreate ("Profile select", 150, 70, 190, 121)
$Combo1 = GUICtrlCreateCombo ($Newprf, 8, 8, 137, 25)
$Button1 = GUICtrlCreateButton ("Ok", 8, 32, 67, 25, 0)
$Button2 = GUICtrlCreateButton ("Cancel", 80, 32, 67, 25, 0)

GUISetState (@SW_SHOW)



While 1
    $pMSG = GUIGetMsg ()
    Select
        Case $pMSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $pMSG = $Button2
            Exit
        Case $pMSG = $Button1
        If GUICtrlRead($Combo1) = $Newprf Then
    $Profmng = GUICreate ("Profile Creation", 276, 179, 271, 226)
    $User = GUICtrlCreateInput ("Username here", 0, 64, 121, 21)
    $Pass = GUICtrlCreateInput ("", 128, 64, 121, 21, $ES_PASSWORD)
    $Browser = GUICtrlCreateCombo ("Select", 0, 112, 121, 25)
    GUICtrlSetData (-1, "Internet Explorer|Mozilla Firefox")
    $Language = GUICtrlCreateCombo ("Select", 128, 112, 121, 25)
    GUICtrlSetData (-1, "English|Danish")
    $Save = GUICtrlCreateButton ("Save", 0, 144, 75, 25, 0)
    $Cancel = GUICtrlCreateButton ("Cancel", 80, 144, 75, 25, 0)
    $Username = GUICtrlCreateLabel ("Username", 0, 48, 52, 17)
    $Password = GUICtrlCreateLabel ("Password", 128, 48, 50, 17)
    $Brw1 = GUICtrlCreateLabel ("Browser", 0, 96, 42, 17)
    $Lng1 = GUICtrlCreateLabel ("Language", 128, 96, 52, 17)
    $Name2 = GUICtrlCreateLabel ("Name", 0, 0, 32, 17)
    $Name = GUICtrlCreateInput ("Profile name here", 0, 16, 121, 21)

    GUISetState (@SW_SHOW)


    While 1
        $Prf = GUIGetMsg ()
        Select
            Case $Prf = $GUI_EVENT_CLOSE
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Cancel
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Save
                $hfile = _FileCreate (GUICtrlRead ($Name) & ".ini")
                $iName = GUICtrlRead ($Name)
                FileOpen ( $iName & ".ini", 1)
                If $hfile = -1 Then
                    MsgBox (0, "Error", "Unable to open file.")
                    ExitLoop
                EndIf
               
                $Us1 = GuiCtrlRead ($User)
                FileWriteLine ($hfile, $Us1)
                $Pa1 = GuiCtrlRead ($Pass)
                FileWriteLine ($hfile, $Pa1)

                FileWriteLine ($hfile, GuiCtrlRead ($Language))
                FileWriteLine ($hfile, GuiCtrlRead ($Browser))

                FileClose ($hfile)
               
                GUIDelete($Profmng)
                GUICtrlSetData($Combo1,$iName, 1)
                ExitLoop
        EndSelect
    WEnd
Else
    MsgBox(0,'Profile','You selected ' & GUICtrlRead($Combo1))
EndIf

    EndSelect
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

This is how I would approach it...

#include <GUIConstants.au3>
#include <File.au3>

Global $Profile
Global $Combo1
Global $Button1
Global $Button2
Global $Profmng
Global $Save
Global $Cancel
Global $Username, $User
Global $Password, $Pass
Global $Brw1, $Browser
Global $Lng1, $Language
Global $Name2, $Name
Global $Folder = @ScriptDir & "\Profiles"

DirCreate($Folder)
$Newprf = Get_Profiles()

$Profile = GUICreate("Profile select", 150, 70, 190, 121)
$Combo1 = GUICtrlCreateCombo("", 8, 8, 137, 25)
GUICtrlSetData(-1, $Newprf, "Create new profile")
$Button1 = GUICtrlCreateButton("Ok", 8, 32, 67, 25, 0)
$Button2 = GUICtrlCreateButton("Cancel", 80, 32, 67, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $pMSG = GUIGetMsg()
    Select
        Case $pMSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $pMSG = $Button2
            Exit
        Case $pMSG = $Button1
            Create_Profile(GUICtrlRead($Combo1))
    EndSelect
WEnd

; ------------------- Functions --------------------------

Func Get_Profiles()
    Local $ret = "Create new profile|"
    Local $FileList = _FileListToArray($Folder, "*.dat", 1)
    If @error = 1 Then
        MsgBox(0, "Sorry!", "No Profiles Found.   ", 2)
        Return $ret
    EndIf
    If IsArray($FileList) Then
        For $x = 1 To UBound($FileList) - 1
            $ret = $ret & StringTrimRight($FileList[$x], 4) & "|"
        Next
    EndIf
    Return StringTrimRight($ret, 1)
EndFunc   ;==>Get_Profiles

Func Make_Profile($iName)
    Local $hFolder = $Folder & "\" & $iName & ".dat"
    FileClose(FileOpen($hFolder, 1))
    _FileWriteToLine($hFolder, 1, GUICtrlRead($User), 1)
    _FileWriteToLine($hFolder, 2, GUICtrlRead($Pass), 1)
    _FileWriteToLine($hFolder, 3, GUICtrlRead($Browser), 1)
    _FileWriteToLine($hFolder, 4, GUICtrlRead($Language), 1)
EndFunc   ;==>Make_Profile

Func Read_Profile($iName)
    Local $hfile = FileOpen($Folder & "\" & $iName & ".dat", 0)
    If $hfile = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Return
    EndIf
    GUICtrlSetData($Name, $iName)
    GUICtrlSetData($User, FileReadLine($hfile, 1))
    GUICtrlSetData($Pass, FileReadLine($hfile, 2))
    GUICtrlSetData($Browser, FileReadLine($hfile, 3))
    GUICtrlSetData($Language, FileReadLine($hfile, 4))
    FileClose($hfile)
EndFunc   ;==>Read_Profile

Func Create_Profile($fName)
    $Profmng = GUICreate("Profile Creation", 276, 179, 271, 226)
    $User = GUICtrlCreateInput("Username here", 0, 64, 121, 21)
    $Pass = GUICtrlCreateInput("", 128, 64, 121, 21, $ES_PASSWORD)
    $Browser = GUICtrlCreateCombo("Select", 0, 112, 121, 25)
    GUICtrlSetData(-1, "Internet Explorer|Mozilla Firefox")
    $Language = GUICtrlCreateCombo("Select", 128, 112, 121, 25)
    GUICtrlSetData(-1, "English|Danish")
    $Save = GUICtrlCreateButton("Save", 0, 144, 75, 25, 0)
    $Cancel = GUICtrlCreateButton("Cancel", 80, 144, 75, 25, 0)
    $Username = GUICtrlCreateLabel("Username", 0, 48, 52, 17)
    $Password = GUICtrlCreateLabel("Password", 128, 48, 50, 17)
    $Brw1 = GUICtrlCreateLabel("Browser", 0, 96, 42, 17)
    $Lng1 = GUICtrlCreateLabel("Language", 128, 96, 52, 17)
    $Name2 = GUICtrlCreateLabel("Name", 0, 0, 32, 17)
    $Name = GUICtrlCreateInput("Profile name here", 0, 16, 121, 21)
    GUISetState(@SW_SHOW)
    If FileExists($Folder & "\" & $fName & ".dat") Then Read_Profile($fName)
    While 1
        $Prf = GUIGetMsg()
        Select
            Case $Prf = $GUI_EVENT_CLOSE
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Cancel
                GUIDelete($Profmng)
                ExitLoop
            Case $Prf = $Save
                $rName = GUICtrlRead($Name)
                If $rName = "" Then ContinueLoop
                Make_Profile($rName)
                
                GUIDelete($Profmng)
                GUICtrlSetData($Combo1, $rName, 1)
                ExitLoop
        EndSelect
    WEnd
    
EndFunc   ;==>Create_Profile

8)

NEWHeader1.png

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