Jump to content

Create file with inputted variables?


Bliz0r
 Share

Recommended Posts

Hello, I am trying to make a program here that saves the inputted variables "Username" and "Password" to a file, so it's readable, and ready to use later on.

#include <GUIConstants.au3>

$Form1 = GUICreate("Create profile", 254, 136, 288, 213)
$User = GUICtrlCreateInput("", 0, 16, 121, 21)
$Pass = GUICtrlCreateInput("", 128, 16, 121, 21, $ES_PASSWORD)
$Firefox = GUICtrlCreateCombo("Select", 0, 56, 121, 25)
            GUICtrlSetData(-1,"Internet Explorer|Mozilla Firefox")
$English = GUICtrlCreateCombo("Select", 128, 56, 121, 25)
$Save = GUICtrlCreateButton("Save", 0, 88, 75, 25, 0)
            GUICtrlSetData(-1,"English|Danish")
$Button1 = GUICtrlCreateButton("Cancel", 80, 88, 75, 25, 0)
$Username = GUICtrlCreateLabel("Username", 0, 0, 52, 17)
$Password = GUICtrlCreateLabel("Password", 128, 0, 50, 17)
$Browser = GUICtrlCreateLabel("Browser", 0, 40, 42, 17)
$Language = GUICtrlCreateLabel("Language", 128, 40, 52, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Also, saving the Combo data, which browser that have been selected, or language.

Anyone who can help me? :)

Link to comment
Share on other sites

Your GuiCtrlCreateButton() is in the way of setting the combo data for $English (move it down one line).

Add a Case to your message loop for $Button1, and inside that do FileOpen(), GuiCtrlRead(), FileWriteLine() and FileClose().

All there in the help file!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Your GuiCtrlCreateButton() is in the way of setting the combo data for $English (move it down one line).

Add a Case to your message loop for $Button1, and inside that do FileOpen(), GuiCtrlRead(), FileWriteLine() and FileClose().

All there in the help file!

:)

Thanks alot, just what I needed. ;)

Link to comment
Share on other sites

Hello again, Now I made it all work - Even though it won't save the variables.

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

Global $Profmng
Global $Save
Global $Cancel
Global $Username
Global $Password
Global $Brw1
Global $Lng1
Global $Name2

$Profmng = GUICreate("Profile Creation", 276, 179, 271, 226)
$User = GUICtrlCreateInput ("", 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 ("", 0, 16, 121, 21)

GUISetState (@SW_SHOW)


While 1
    $pMsg = GUIGetMsg ()
    Select
            Case $pMsg = $GUI_EVENT_CLOSE
                Exit
            Case $pMsg = $Cancel
                Exit
            Case $pMsg = $Save
                If Not _FileCreate ("Name.ini") Then
                    MsgBox (4096, "Error", " Error creating profile   error:" & @error)
                EndIf
            
                FileOpen("Name.ini", 1)
                If "Name.ini" = -1 Then
                    MsgBox (0, "Error", "Unable to open file.")
                EndIf
            
                $Us1 = GuiCtrlRead ($User, 1)
                $Pa1 = GuiCtrlRead ($Pass, 1)
                $La1 = GuiCtrlRead ($Language, 1)
                $Br1 = GuiCtrlRead ($Browser, 1)
            
                FileClose ("Name.ini") 
                
                Exit
    EndSelect
WEnd

And I have no clue what's wrong. Besides, how to I make it create a file with the name, of the variable $Name ?

Link to comment
Share on other sites

You seem to be missing the FileWrite() or FileWriteLine() functions after those GuiCtrlRead()'s...

:)

Drat... beat out by Super Fly!

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, I'm so stupid I forgot that. :)

Anyway, any tips on how I make the $Name work? I need to create a file for a profile list. All with different passwords / usernames, that's why I need the $Name variable working.

Edited by Bliz0r
Link to comment
Share on other sites

Thanks, I'm so stupid I forgot that. :)

Anyway, any tips on how I make the $Name work? I need to create a file for a profile list. All with different passwords / usernames, that's why I need the $Name variable working.

Just assemble the file name using that variable with '&' operator.

You don't need advanced info option to read the controls (inputs don't have advanced info to read).

Notice what I did on the third and fourth writes: The returned data from one function can be the direct input to the parameter of another function. In other words, AutoIt allows "nested functions":

$hFile = FileOpen($Name & ".ini", 1) ; Use the file handle
                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)

;)

Luke, come to the Dark Side... 'cause we have cookies!

Posted Image

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...