Jump to content
CodeName_SexBobomb

IniWrite On Next Line

Recommended Posts

CodeName_SexBobomb
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Test ()
Func Test()
$Form1 = GUICreate("Form1", 414, 212, 1449, 1197)

$Group1 = GUICtrlCreateGroup("Group1", 0, 0, 201, 161)
Global $Combo1 = GUICtrlCreateCombo("", 0, 16, 201, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Data = GUICtrlSetData($Combo1, "Combo 1|Combo 2|Combo 3")
Global $Input1 = GUICtrlCreateInput("", 0, 48, 201, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup("Group2", 210, 0, 200, 160)
    Dim $LABELS[20]
    Local $DIRECTORY    = @ScriptDir & "\Test.ini"
    Local $SECTION      = IniReadSection($DIRECTORY, "Section 1")
    Local $RESULTS      = ""
    For $r = 1 To $SECTION[0][0]
        $RESULTS &= $SECTION[$r][1] & @CRLF
    Next
    $RESULTS = StringTrimRight($RESULTS, 1)
    For $N = 0 To 10
        $LABELS[$N] = GUICtrlCreateLabel($RESULTS, 220, 15, 200, 100)
    Next
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Button1 = GUICtrlCreateButton("Save", 80, 170, 121, 33)
$Button2 = GUICtrlCreateButton("Exit", 210, 170, 121, 33)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                _WriteData ()
            Case $Button2
                Exit
        EndSwitch
    WEnd
EndFunc

_WriteData ()
Func _WriteData ()
Local $TestData = GUICtrlRead($Combo1)
Local $TestInput = GUICtrlRead($Input1)
Local $Directory    = @ScriptDir & "\Test.ini"

IniWrite ($Directory, "Section 1", "", "" & $TestData & "       " & $TestInput & @CRLF & "")
EndFunc

Hello Friends,
  Perhaps one of you can assist me. Currently I have a semi-working script. The goal of this script is to write the values of the combo box into an INI file and read said INI files. So far it does this.. but the issue is, It writes over line 1. The goal is to write on a new line each time to create a continuous log of submitted data.

Share this post


Link to post
Share on other sites
jchd

.INI file format and implied characteristic aren't suited to accumulate log data. You're better trying .log files and associated functions.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
CodeName_SexBobomb

Well this puts a serious wrench in the system. As the program would read the .ini file in order show me the information that was logged without having to actively open the log file. Would you mind providing me with a quick little snippet of how you would go about this scenario based on my example? I'm completely out of ideas here.

I was able to get a working log file. However, it doesn't do what I need it to do and it breaks the readini function.

Share this post


Link to post
Share on other sites
iamtheky

How much data?  I would think a map would serve the same purpose, and would only need to write to file in chunks (as memory warranted).  Depending on how you structure your map you can dump to .ini, dump it to an array, and then even lose your gd mind and call them back with dot notation......I have some old functions here:

 

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
CodeName_SexBobomb

Thank you once again for your input iamtheky.  I'll have to look at your script again - tomorrow, with a fresh brain. 

To answer your question, the amount of data (in my opinion) would be small. Three names, Two Dates, and a phone number per entry. Now, if the question is rather how many entries that will vary month to month but approximately 110 per month.

Share this post


Link to post
Share on other sites
iamtheky

Bouncing that data between maps and files would be easy at that size.  Just so I don't immediately create an edge case, can you provide a couple of sample entries?  While using beta functions and a notation that will be deprecated is not ideal, my solutions are nothing if not unwieldy.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
CodeName_SexBobomb
QA Agent Score Dates   IEA Agent Team Lead   Phone Number  Call Details
John Doe 11/02/2017 1:01P   Joe Agent Boss Jane   123-456-7890 10/10/10 7:32A
John Doe 11/02/2017 1:15P   Tom Agent Boss Jane   789-123-4567 1/12/15 9:02A
Jane Doe 11/02/2017 1:30P   Lisa Agent Boss Sam   456-789-1234 4/15/17 3:23P

 


Something of this nature. Ideally the data per entry would be pulled from a combination of combo and input boxes.

Share this post


Link to post
Share on other sites
kylomas

Why can't you just read the log file?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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

  • Similar Content

    • GordonFreeman
      By GordonFreeman
      Hi, i'm trying to save data in an ini key that contains @LF and @CRLF (to use in an edit control). But @LF and @CRLF cause error in ini files (because it breaks the line). Then im trying to find a workaround. Here's the script thanks in advance:
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 438, 192, 124) $hEDIT = GUICtrlCreateEdit("",11,11,600,400) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### IniWrite("JustATest.ini","TestSec","TestKey","TestValue " & @CRLF & "Testing" & @LF & "test") $sData = IniRead("JustATest.ini","TestSec","TestKey","") GUICtrlSetData($hEDIT,$sData) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • zemkor
      By zemkor
      Hello, i have question. How to save and read data from "GUICtrlCreateEdit" to ini file ?. Problem is: IniWrite write only first line of text and IniRead read only first line text.
      How to do it?
      Thanks for answer.
      $text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; write to ini file IniWrite($ini_file, "Data", "Text", GUICtrlRead($Text)) EndFunc $text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func load() ;natiahne nastavenia z .ini Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($text, IniRead($ini_file, "Data", "Text", "")) EndFunc This not working, read and write only firt line
    • MHz
      By MHz
      These functions handle ANSI and unicode inifiles similar to IniRead, IniWrite and IniDelete.
      _WinAPI_WritePrivateProfileStringW _WinAPI_GetPrivateProfileStringW So you can read from unicode inifiles created from other programs or perhaps read and write to your own inifiles.
      I was unable to figure out how the API function of WritePrivateProfileStringW can create a unicode file initially so I instead used FileOpen to create a unicode file and write the 1st entry to achieve this. Further use uses WritePrivateProfileStringW is ok to handle the unicode entries. ANSI file creation is done by WritePrivateProfileStringW by default.
      Deletion of keys and sections may need use of Null which is in AutoIt 3.3.9.0 and later. I put comments with the code so hopefully understandable to you.
      The functions use a similar parameter syntax to IniRead and IniWrite. _WinAPI_WritePrivateProfileStringW has an additional parameter to handle the flag passed to FileOpen for the initial creation of the inifile. _WinAPI_GetPrivateProfileStringW has an additional parameter in case you want the buffer that holds the return value within the UDF to be larger.
      The example has some russian text in it so you need to save it in a unicode script for correct testing.
      Example
      ; show message if script is not unicode. Unicode text in this script requires it to be UTF encoded. ; if needed in Scite, use menu bar, File -> Encoding -> UTF (any UTF type that suits you) and save the script. If Not FileGetEncoding(@ScriptFullPath) Then MsgBox(0, @ScriptName, 'Script is not unicode') ; write to ini file $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', 'Открыть', 0x21) _Notify('Write', $return) ; read from ini file $return = _WinAPI_GetPrivateProfileStringW("test.ini", 'russian', 'Open', 'Default') _Notify('Read', $return) #cs AutoIt 3.3.9.0 or later using Null keyword ; setting $sValue parameter with Null keyword will delete a key using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', Null) ; setting $sKey parameter with Null keyword will delete a section using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', Null, Null) ; setting $sSection parameter with Null keyword will flush using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", Null, Null, Null) #ce ; More info of an API that mimics these functions and explains use of Null at http://code.google.com/p/privateprofilestring/ Func _Notify($title, $return = 0, $error = @error, $extended = @extended) ; notify results from other function calls MsgBox(StringRegExpReplace($error, '-{0,1}([1-9])[0-9]*', '0x30'), $title, _ '@error = ' & $error & @CRLF & _ '@extended = ' & $extended & @CRLF & _ '$return = ' & $return _ ) EndFunc User defined functions
      ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_WritePrivateProfileStringW ; Description ...: Write to ANSI and unicode encoded ini files ; Syntax.........: _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue[, $iMode = 1]) ; Parameters ....: $sFileName - The filename of the .ini file ; $sSection - The section name in the .ini file ; $sKey - The key name in the in the .ini file ; $sValue - The value to write/change ; $iMode - Refer to FileOpen mode parameter ; Return values .: Success - Not 0 ; Failure - 0 ; @error 1 to 5 - Refer to DllCall ; @error 6 - FileOpen failed to open a handle to create the file ; Author ........: MHz ; Modified.......: ; Remarks .......: Similar to IniWrite but uses unicode API calls. If $sValue is Null then $sKey is deleted. If $sKey is Null, ; then $sSection is deleted. If $sSection, $sKey and $sValue are all Null, then $sFileName is ; flushed. *** Null is a keyword that only exists in AutoIt3 versions 3.3.9.x and later *** ; Related .......: DllCall, FileOpen, IniWrite ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms725501%28v=vs.85%29.aspx ; http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue, $iMode = 1) Local $handle_write, $ret ; check if path is relative and make it absolute if it is relative $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName ; create a unicode encoded file if needed and write the entry If Not FileExists($sFileName) And $iMode > 0x20 Then $handle_write = FileOpen($sFileName, $iMode) If $handle_write = -1 Then Return SetError(6, 0, 0) FileWrite($handle_write, '[' & $sSection & ']' & @CRLF & $sKey & '=' & $sValue & @CRLF) FileClose($handle_write) Return 1 EndIf ; write to the ini file. $ret[0] will contain nonzero if successful $ret = DllCall('Kernel32.dll', 'bool', 'WritePrivateProfileStringW', _ 'wstr', $sSection, _ 'wstr', $sKey, _ 'wstr', $sValue, _ 'wstr', $sFileName _ ); lpAppName, lpKeyName, lpString, lpFileName If @error Then Return SetError(@error, @extended, 0) Return SetExtended(0, $ret[0]) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_GetPrivateProfileStringW ; Description ...: Read from ANSI and unicode encoded ini files ; Syntax.........: _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey[, $sDefault = ''[, $iBufferSize = 65536]]) ; Parameters ....: $sFileName - The filename of the .ini file ; $sSection - The section name in the .ini file ; $sKey - The key name in the in the .ini file ; $sDefault - The default value to return if the requested key is not found ; $iBufferSize - Adjustable buffer size which contains the chars from the API call ; Return values .: Success - Returns the requested key value ; Failure - Returns the default string if requested key not found ; @error 1 to 5 - Refer to DllCall ; Author ........: MHz ; Modified.......: ; Remarks .......: Similar to IniRead but uses unicode API calls ; Related .......: IniRead ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724353%28v=vs.85%29.aspx ; http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey, $sDefault = '', $iBufferSize = 65536) Local $buffer, $ret ; check if path is relative and make it absolute if it is relative $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName ; create a buffer to hold the returned string $buffer = DllStructCreate('wchar[' & $iBufferSize & ']') ; read from the ini file. $ret[0] will contain number of chars returned $ret = DllCall('Kernel32.dll', 'dword', 'GetPrivateProfileStringW', _ 'wstr', $sSection, _ 'wstr', $sKey, _ 'wstr', $sDefault, _ 'ptr', DllStructGetPtr($buffer), _ 'dword', DllStructGetSize($buffer), _ 'wstr', $sFileName _ ); lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName If @error Then SetError(@error, @extended, $sDefault) Return SetExtended($ret[0], DllStructGetData($buffer, 1)) EndFunc Thanks to AZJIO for some russian text for use in the example.
      Edit:
      Updated with summary correction by guiness in post #2
    • tes5884
      By tes5884
      Hi guys,
      I'm trying to add a startup script using autoit.

      One of the steps is writing to the "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini" file.

      Problem is even though I run the code it doesn't change the actual file, and it returns "1" meaning it was successful.


      $ini = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini" $val1 = IniWrite($ini, "Shutdown","0CmdLine", "C:\Scripts\USBReminder.exe") $val2 = IniWrite($ini, "Shutdown","0Parameters", "") MsgBox(0, "", $val1 & @CRLF & $val2)
      Thanks!!
    • hackersarchangel
      By hackersarchangel
      Ok so here's my "evil plan" lol: I am working on making a test to help me study for the A+. The idea is that I want to make it modular so I can specify a battery of tests.

      My bright idea was to make an ini file generator, since that has built functions and a method for sorting. The generator is mostly done, it's a basic one to make multiple choice questions. Here's the tricky bit: I want to be able to mark each answer with 1, 2, 3, and 4 so I can then have the test program grab the answers at random, but still relevant to each question, and not show the numbers so it's harder to tell which ones are which.

      Example:

      Q. Who founded Apple Computer, Inc?
      1) Steve Ballmer
      2)Steve Jobs and Steve Wozniak
      3) Bill Gates and Steve Jobs
      4) Tom Petty and the Heartbreakers

      but have that be in a different order everytime I take the test, so I can't cheat even though I'm writing the test lol. I have that figured out as far as how it's organized with the questions, just need to figure out how to grab the questions and answers, but do it in a way that it's not seen in the test, so I can randomize them. So far I'm sure I can randomize the question order, but still not sure on how to keep it from repeating a question.

      Here's my code so far for the ini generator, the Test portion I'll be working on as soon as I can think of a way to have it pick a question at random. Partially why I'm here


      #include <GUIConstantsEx.au3> ;Constants for GUI Events #include <WindowsConstants.au3> Global $Answer, $Answer_input[4], $counter = 0, $Build_bttn, $Question, $Question_input _Create_GUI() Func _Create_GUI() ;To implement a reset function, make everything in the GUI first, THEN put all the case stuff inside ;_Main(). HotKeySet("{F3}","_Main") ;A program reset switch, in case a function gets funky and doesn't process right. GUICreate("Question and Answer Generator Version 0.1",640,480) ;The code for adding questions and answers to the .ini file. $Question_input = GUICtrlCreateEdit("Question goes here",45,45, 250, 75) $Answer_input[0] = GUICtrlCreateInput("1)", 45, 150, 300, 20) $Answer_input[1] = GUICtrlCreateInput("2)", 45, 175, 300, 20) $Answer_input[2] = GUICtrlCreateInput("3)", 45, 200, 300, 20) $Answer_input[3] = GUICtrlCreateInput("4)", 45, 225, 300, 20) $Build_bttn = GUICtrlCreateButton("Add to File", 525,440) _Main() EndFunc Func _Main() GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $Gui_Event_Close Exit Case $Build_bttn $Question = GUICtrlRead($Question_input) $Answer = GUICtrlRead($Answer_input[0]) & @LF & GUICtrlRead($Answer_input[1]) & @LF & GUICtrlRead($Answer_input[2]) & @LF & GUICtrlRead($Answer_input[3]) If ($counter) < 10 Then $counter = $counter+1 IniWrite("AlphaTest.ini","Questions","Question_" & $counter, $Question) IniWriteSection("AlphaTest.ini","Answer_" & $counter,$Answer) EndIf EndSwitch WEnd EndFunc
      I understand this is a complicated project, one I'm willing to share back with the community of course since the idea is to make it a simple generator and then just point the Test exe to the q&a file
×