|
You last visited: Today at 05:43
Advertisement
INI write, read, display data
Discussion on INI write, read, display data within the AutoIt forum part of the Coders Den category.
04/28/2016, 15:46
|
#1
|
elite*gold: 0
Join Date: Jan 2014
Posts: 43
Received Thanks: 1
|
INI write, read, display data
Hi
Im testing ini function and i have some problems with it. When i add item to ini file it owerite my first entry, and it dont show me items from ini on listview.
And i need instead of id to be username, password, nickname
Here is my code so far i tested
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
Global $ini_path = 'test.ini'
; check if ini file exists if not create it
If $ini_path = '' Then _FileCreate("test.ini")
; read items from ini in listview
$dd = IniRead($ini_path, "Account", "id", "No data")
GUICreate("Form1", 388, 596, 762, 289)
GUICtrlCreateGroup(" Add account", 8, 8, 369, 81)
GUICtrlCreateLabel("Username", 24, 32, 52, 15)
GUICtrlCreateLabel("Password", 153, 32, 50, 15)
$username = GUICtrlCreateInput("", 24, 50, 121, 21)
$password = GUICtrlCreateInput("", 152, 50, 121, 21)
$addAcc = GUICtrlCreateButton("Add", 288, 48, 75, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup(" Accounts ", 8, 104, 369, 449)
$idListview = GUICtrlCreateListView("", 24, 136, 337, 396)
_GUICtrlListView_AddColumn($idListview, "Username", 150)
_GUICtrlListView_AddColumn($idListview, "Password", 183)
_GUICtrlListView_AddItem($idListview, $dd, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$startBtn = GUICtrlCreateButton("Start game", 8, 560, 369, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $addAcc
__addChar()
Case $idListview
;~ _GUICtrlListView_BeginUpdate($idListview)
;~ For $i = 1 To $dd[0][0]
;~ Local $dd = IniRead($ini_path, "Account", "test", "")
;~ _GUICtrlListView_AddItem($idListview, $dd, 1)
;~ Next
;~ _GUICtrlListView_EndUpdate($idListview)
EndSwitch
WEnd
; __runGame() runs game from list when u click double on item or select item start button
Func __runGame()
EndFunc ;=> __runGame()
; __addChar()
Func __addChar()
Local $user = GUICtrlRead($username)
Local $pass = GUICtrlRead($password)
If $user <> '' And $pass <> '' Then
IniWrite($ini_path, "Account", "id", $user &','& $pass)
Else
MsgBox(64, "", "All fields must be filled.")
EndIf
EndFunc ;=> __addChar()
And items in ini file
[Account]
id=1234,1234
id=bah
id=afk
id=rwet
id=gtwddda
|
|
|
04/28/2016, 17:10
|
#2
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
Just use a number for the Ini-Loop. Something like
Code:
[Account]
1=user1,pass1
2=user2,pass2
|
|
|
04/28/2016, 17:39
|
#3
|
elite*gold: 0
Join Date: Jan 2014
Posts: 43
Received Thanks: 1
|
But how to write to ini file when i must enter section and key, and 1,2 is keys.
|
|
|
04/28/2016, 17:47
|
#4
|
elite*gold: 0
Join Date: Mar 2016
Posts: 104
Received Thanks: 34
|
i found an old script thats not like yours but i think u can use some things from it
Code:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
$sText = "Line 1" & @CRLF & "Line 2" & @CRLF & "Line 3"
$sIniPath = @ScriptDir & "\test.ini"
$hGUI = GUICreate("Test", 500, 500)
$cEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200)
$cSave = GUICtrlCreateButton("Save", 10, 300, 80, 30)
GUICtrlSetState($cSave, $GUI_FOCUS)
$cRead = GUICtrlCreateButton("Read", 100, 300, 80, 30)
$cCheck = GUICtrlCreateButton("Check", 400, 300, 80, 30)
GUICtrlSetState($cCheck, $GUI_DISABLE)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $cSave
; Read multiple lines
$sOriginal = GUICtrlRead($cEdit)
; Clear edit
GUICtrlSetData($cEdit, "")
; Convert EOLs into dummy strings
$sConverted = StringReplace($sOriginal, @CRLF, "{ENTER}")
; This is the result
MsgBox($MB_SYSTEMMODAL, "Converted before write", $sConverted)
; Which is written tot he ini
IniWrite($sIniPath, "Multiline", "Text", $sConverted)
; Allow us to peek inside the ini
GUICtrlSetState($cCheck, $GUI_ENABLE)
Case $cRead
; Read the strign from the ini
$sOriginal = IniRead($sIniPath, "Multiline", "Text", "Houston, we have a problem")
; Convert the dummies back into EOLs
$sConverted = StringReplace($sOriginal, "{ENTER}", @CRLF)
; And we get this
MsgBox($MB_SYSTEMMODAL, "Converted after read", $sConverted)
; Which we replace in the edit
GUICtrlSetData($cEdit, $sConverted)
Case $cCheck
; Read the ini content directly
$sContent = FileRead($sIniPath)
; See it is all one string with dummies replacing the EOLs
MsgBox($MB_SYSTEMMODAL, "Read from ini", $sContent)
EndSwitch
WEnd
|
|
|
04/28/2016, 18:17
|
#5
|
elite*gold: 0
Join Date: Jan 2014
Posts: 43
Received Thanks: 1
|
I have 3 columns
Code:
_GUICtrlListView_AddColumn($List1, "Username", 150)
_GUICtrlListView_AddColumn($List1, "Password", 145)
_GUICtrlListView_AddColumn($List1, "Nickname", 150)
and i try to populate it like this
Code:
Func __readIni()
If FileExists($ini) Then
$fOpen = FileOpen($ini)
$fRead = FileRead($fOpen)
$nItem = StringReplace($fRead, "[Accounts]", "")
_GUICtrlListView_AddItem($List1,$nItem&@CRLF)
EndIf
EndFunc
But i get only 1 line in 1st column
|
|
|
04/28/2016, 18:27
|
#6
|
elite*gold: 400
Join Date: Jun 2011
Posts: 513
Received Thanks: 101
|
Try this:
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
Global $ini_path = 'test.ini', $AccNumber
; check if ini file exists if not create it
;If $ini_path = '' Then _FileCreate("test.ini")
If Not FileExists($ini_path) Then
IniWriteSection("test.ini", "Account", "")
IniWriteSection("test.ini", "Password", "")
EndIf
$IniReadUser = IniReadSection($ini_path, "Account")
If @error <> 0 Then
$AccNumber = 0
Else
$AccNumber = $IniReadUser[0][0]
EndIf
; read items from ini in listview
GUICreate("Form1", 388, 596, 762, 289)
GUICtrlCreateGroup(" Add account", 8, 8, 369, 81)
GUICtrlCreateLabel("Username", 24, 32, 52, 15)
GUICtrlCreateLabel("Password", 153, 32, 50, 15)
$username = GUICtrlCreateInput("", 24, 50, 121, 21)
$password = GUICtrlCreateInput("", 152, 50, 121, 21)
$addAcc = GUICtrlCreateButton("Add", 288, 48, 75, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup(" Accounts ", 8, 104, 369, 449)
$idListview = GUICtrlCreateListView("", 24, 136, 337, 396)
_GUICtrlListView_AddColumn($idListview, "Username", 150)
_GUICtrlListView_AddColumn($idListview, "Password", 183)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$startBtn = GUICtrlCreateButton("Start game", 8, 560, 369, 25)
_refreshListView()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $addAcc
__addChar()
Case $idListview
;~ _GUICtrlListView_BeginUpdate($idListview)
;~ For $i = 1 To $dd[0][0]
;~ Local $dd = IniRead($ini_path, "Account", "test", "")
;~ _GUICtrlListView_AddItem($idListview, $dd, 1)
;~ Next
;~ _GUICtrlListView_EndUpdate($idListview)
EndSwitch
WEnd
; __runGame() runs game from list when u click double on item or select item start button
Func __runGame()
EndFunc ;=> __runGame()
; __addChar()
Func __addChar()
Local $user = GUICtrlRead($username)
Local $pass = GUICtrlRead($password)
If $user <> '' And $pass <> '' Then
$AccNumber += 1
IniWrite($ini_path, "Account", "User" & $AccNumber, $user)
IniWrite($ini_path, "Password", "Pass" & $AccNumber, $pass)
_refreshListView()
Else
MsgBox(64, "", "All fields must be filled.")
EndIf
EndFunc ;=> __addChar()
Func _refreshListView()
_GUICtrlListView_DeleteAllItems($idListview)
If $AccNumber = 0 Then
GUICtrlCreateListViewItem( "no data", $idListview)
Else
For $i = 1 To $AccNumber
GUICtrlCreateListViewItem(IniRead($ini_path, "Account", "User" & $i, "") & '|' & IniRead($ini_path, "Password", "Pass" & $i, ""), $idListview)
Next
EndIf
EndFunc
|
|
|
04/28/2016, 18:37
|
#7
|
elite*gold: 0
Join Date: Jan 2014
Posts: 43
Received Thanks: 1
|
Quote:
Originally Posted by °Incinerate
Try this:
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
Global $ini_path = 'test.ini', $AccNumber
; check if ini file exists if not create it
;If $ini_path = '' Then _FileCreate("test.ini")
If Not FileExists($ini_path) Then
IniWriteSection("test.ini", "Account", "")
IniWriteSection("test.ini", "Password", "")
EndIf
$IniReadUser = IniReadSection($ini_path, "Account")
If @error <> 0 Then
$AccNumber = 0
Else
$AccNumber = $IniReadUser[0][0]
EndIf
; read items from ini in listview
GUICreate("Form1", 388, 596, 762, 289)
GUICtrlCreateGroup(" Add account", 8, 8, 369, 81)
GUICtrlCreateLabel("Username", 24, 32, 52, 15)
GUICtrlCreateLabel("Password", 153, 32, 50, 15)
$username = GUICtrlCreateInput("", 24, 50, 121, 21)
$password = GUICtrlCreateInput("", 152, 50, 121, 21)
$addAcc = GUICtrlCreateButton("Add", 288, 48, 75, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup(" Accounts ", 8, 104, 369, 449)
$idListview = GUICtrlCreateListView("", 24, 136, 337, 396)
_GUICtrlListView_AddColumn($idListview, "Username", 150)
_GUICtrlListView_AddColumn($idListview, "Password", 183)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$startBtn = GUICtrlCreateButton("Start game", 8, 560, 369, 25)
_refreshListView()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $addAcc
__addChar()
Case $idListview
;~ _GUICtrlListView_BeginUpdate($idListview)
;~ For $i = 1 To $dd[0][0]
;~ Local $dd = IniRead($ini_path, "Account", "test", "")
;~ _GUICtrlListView_AddItem($idListview, $dd, 1)
;~ Next
;~ _GUICtrlListView_EndUpdate($idListview)
EndSwitch
WEnd
; __runGame() runs game from list when u click double on item or select item start button
Func __runGame()
EndFunc ;=> __runGame()
; __addChar()
Func __addChar()
Local $user = GUICtrlRead($username)
Local $pass = GUICtrlRead($password)
If $user <> '' And $pass <> '' Then
$AccNumber += 1
IniWrite($ini_path, "Account", "User" & $AccNumber, $user)
IniWrite($ini_path, "Password", "Pass" & $AccNumber, $pass)
_refreshListView()
Else
MsgBox(64, "", "All fields must be filled.")
EndIf
EndFunc ;=> __addChar()
Func _refreshListView()
_GUICtrlListView_DeleteAllItems($idListview)
If $AccNumber = 0 Then
GUICtrlCreateListViewItem( "no data", $idListview)
Else
For $i = 1 To $AccNumber
GUICtrlCreateListViewItem(IniRead($ini_path, "Account", "User" & $i, "") & '|' & IniRead($ini_path, "Password", "Pass" & $i, ""), $idListview)
Next
EndIf
EndFunc

|
This works fine, thank u.
|
|
|
 |
Similar Threads
|
Inet(-Read/-Write)
12/27/2011 - AutoIt - 0 Replies
#Helped :awesome:
|
LUA file write/read
08/21/2011 - Metin2 Private Server - 4 Replies
Hallo =)
Ich würde gerne wissen ob es möglich ist mit den LUA Befehlen von Mt Textdateien zu schreiben und ob das irgend ein Server verwendet, ggf Erfahrungen mit so einem System gesammelt hat.
Danke im vorraus!
grüßle LordMampf2
|
ce write/read frage
12/21/2009 - General Coding - 5 Replies
ich habe da eine frage bezüglich der funktionen von dem programm cheatengine. hierzu weitere infos :
ich habe einen teleporter für flyff gecodet. ich schreibe die werte mithilfe von WriteProcessMemory oder lese sie mit ReadProcessMemory aus. flyff crasht bei zu weiter entfernung vom a punkt . fals ich dasselbe in ce versuche funktioniert es einwandfrei.
nun meine frage : wie schreibt und liest ce die werte aus ? auf jedenfall nicht mit read/write processmem
|
Please read, and write =P
04/09/2009 - Runescape - 0 Replies
What do you want on this forum?
I want frequent visitors to list every good idea.
Maybe a guide they need.
What do people need and want?
|
All times are GMT +1. The time now is 05:46.
|
|