Jump to content

How to save from input box to ini /text file and use it


Recommended Posts

This code works great

CODE
#Include <GUiConstants.au3>

;Create GUI

$Main = GUICreate('Welcome to MPT Broadband', 300, 100)

Opt("GUICoordMode",1)

$username = GUICtrlCreateInput('',100,20,100)

$usernamelabel = GUICtrlCreateLabel('Username',30,23)

$password = GUICtrlCreateInput('',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)

GUISetState ()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $Button_1

GLOBAL $collectusername = GUICtrlRead($username)

WinSetState('Collect Username and Password','',@SW_HIDE)

GLOBAL $collectpassword = GUICtrlRead($password)

MsgBox(0,'Username and Password','Username: ' & $collectusername & @CRLF & 'Password: ' & $collectpassword)

ExitLoop

Case $msg = $Button_2

Exit

EndSelect

Wend

Can you please tell me ( Code would be appreciated ) how to save the username and password in an ini / text file and how to retrieve them from ini / text file

Link to comment
Share on other sites

FWIW this is copy/paste from the help file

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

$var = IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")

MsgBox(4096, "Result", $var)

IniWrite ( "filename", "section", "key", "value" )

IniWrite("C:\Temp\myfile.ini", "section2", "key", "this is a new value")

myfile.ini would look something like...

[section2]

key=this is a new value

edit: edited for mr mcgee

Edited by Leighwyn
Link to comment
Share on other sites

Can you please stop posting new topics? All 3 of your topics are related....make one topic post.

As for your request, create a checkbox, and then depending on the state of the checkbox, write to a file or not.

#Include <GUiConstants.au3>

;Create GUI
$Main = GUICreate('Welcome to MPT Broadband', 300, 100)

Opt("GUICoordMode",1)
$username = GUICtrlCreateInput('',100,20,100)
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$password = GUICtrlCreateInput('',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 ()
; Run the GUI until the dialog is closed
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("test.ini", "Data", "Username", $collectusername)
                IniWrite("test.ini", "Data", "Password", $collectpassword)
            EndIf
            WinSetState('Collect Username and Password','',@SW_HIDE)
            MsgBox(0,'Username and Password','Username: ' & $collectusername & @CRLF & 'Password: ' & $collectpassword)
            ExitLoop
        Case $msg = $Button_2
            Exit
    EndSelect
Wend

Untested.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

how to save the username and password in an ini / text file and how to retrieve them from ini / text file

Well, after you exit the loop, you will need to write the ini file, and before vreating the gui you read the ini file, but also you might want to encrypt your password...

#Include <GUiConstants.au3>
#Include <String.au3>

$IniFile = @ScriptDir & "\Test.ini"

$ReadUserName = IniRead($IniFile, "Data", "User Name", "")
$ReadUserPass = _StringEncrypt(0, IniRead($IniFile, "Data", "Password", ""), "0000", 2)

;Create GUI
$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)

GUISetState ()
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Button_1
            GLOBAL $collectusername = GUICtrlRead($username)
            WinSetState('Collect Username and Password','',@SW_HIDE)
            GLOBAL $collectpassword = GUICtrlRead($password)
            MsgBox(0,'Username and Password','Username: ' & $collectusername & @CRLF & 'Password: ' & $collectpassword)
            ExitLoop
        Case $msg = $Button_2
            Exit
    EndSelect
Wend

IniWrite($IniFile, "Data", "User Name", $collectusername)
IniWrite($IniFile, "Data", "Password", _StringEncrypt(1, $collectpassword, "0000", 2))
Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Leighwyn - FWIW... What's that supposed to mean? Please take the time to type out words if you are going to use them in your reply (or use an abbreviation that is slightly more well-known). Thanks

EDIT: Wow, my age does show throught every now and then. Lol just noticed he even added a link to the FWIW for the lazy ppl like me that can't type four letters into a google query... I PMed him an apology :whistle:. BTW (By the way), this post isn't about my laziness... it's about sumit's question.

Edited by dandymcgee

- Dan [Website]

Link to comment
Share on other sites

Can you please stop posting new topics? All 3 of your topics are related....make one topic post.

As for your request, create a checkbox, and then depending on the state of the checkbox, write to a file or not.

#Include <GUiConstants.au3>

;Create GUI
$Main = GUICreate('Welcome to MPT Broadband', 300, 100)

Opt("GUICoordMode",1)
$username = GUICtrlCreateInput('',100,20,100)
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$password = GUICtrlCreateInput('',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 ()
; Run the GUI until the dialog is closed
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("test.ini", "Data", "Username", $collectusername)
                IniWrite("test.ini", "Data", "Password", $collectpassword)
            EndIf
            WinSetState('Collect Username and Password','',@SW_HIDE)
            MsgBox(0,'Username and Password','Username: ' & $collectusername & @CRLF & 'Password: ' & $collectpassword)
            ExitLoop
        Case $msg = $Button_2
            Exit
    EndSelect
Wend

Untested.

Can someone please tell me after entering username and password how to close the inputbox ( welcome to mpt broadband ) and then open messagebox ( username and password )

Edited by sumit
Link to comment
Share on other sites

Leighwyn - FWIW... What's that supposed to mean? Please take the time to type out words if you are going to use them in your reply (or use an abbreviation that is slightly more well-known). Thanks

For What It's Worth

Next time, do a little research before displaying your ignorance.

Ralph

Link to comment
Share on other sites

  • Developers

For What It's Worth

:whistle: ** Nothing...**

Next time, do a little research before displaying your ignorance.

... since this is not needed Ralph ..... Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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