Jump to content

populate array with text file


Recommended Posts

hello,

I work on an application with a .ini like this:

1001=a
1002=b
1003=c
1004=d
1005=e
1006=f
1007=g
1008=h
1009=i
2001=l
....
9001=z

not many lines (81) but can't use it as normal ini.

My user can manipulate text file values but only to optimize script usability.

So I want to start script, and :

- read '.ini', and insert its value in an array

- when user do something var is valorized (eg: 1001)

- script take this value, read array, search for 1001 and return letter 'a' to user.

Hope to have explained my need ^_^

thank you all,

m.

Link to comment
Share on other sites

Maybe...

#include <file.au3>

Dim $aRecords, $File = @ScriptDir & "Text.ini"

If Not _FileReadToArray($File, $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

; create your user GUI
$Find = InputBox("Ini Reader", "Please input a line #")

; for testing
; $aRecords = StringSplit("1001=a,1002=b,1003=c", ",")

For $x = 1 To $aRecords[0]
    If StringInStr($aRecords[$x], $Find) Then
        MsgBox(-1, 'Record:' & $x, StringRight($aRecords[$x], 1))
        ExitLoop
    EndIf
Next

8)

NEWHeader1.png

Link to comment
Share on other sites

For a user changed ini

#include <file.au3>

Dim $aRecords, $File = @ScriptDir & "Text.ini"

If Not _FileReadToArray($File, $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

; create your user GUI
$Find = InputBox("Ini Reader", "Please input a line #")

; for testing
; $aRecords = StringSplit("1001=a,1002=b,1003=c", ",")

For $x = 1 To $aRecords[0]
    If StringInStr($aRecords[$x], $Find) Then
        $split = StringSplit($aRecords[$x], "=")
        MsgBox(-1, 'Record:' & $x, $split[2])
        ExitLoop
    EndIf
Next

8)

NEWHeader1.png

Link to comment
Share on other sites

Problem with that second one valuter seems 4 returns the same value as 1004.

There should never be a "4". As I understand it is from 1001 to 9009 ( or similar). The second script is for the text after the equal sign to be changed.

8)

EDIT:

I only created the manipulation as the OP asked, not the GUI or the filtering. My "InputBox" was for example only... thx 8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

ooOOooo @ Val

I know I know for giggles I added a length measure LOL.

EDIT: Wow im bored

#include <file.au3>

Dim $aRecords, $File = @ScriptDir & "Text.ini"

If Not _FileReadToArray($File, $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exitloop
EndIf

; create your user GUI
$Find = InputBox("Ini Reader", "Please input a line #")

; for testing
; $aRecords = StringSplit("1001=a,1002=b,1003=c", ",")
$Len = StringLen($Find)
if $Len < 4 Then
    Exit
Else
    For $x = 1 To $aRecords[0]
        If StringInStr($aRecords[$x], $Find) Then
            $split = StringSplit($aRecords[$x], "=")
            MsgBox(-1, 'Record:' & $x, $split[2])
        ExitLoop
    EndIf
EndIf
Next
Edited by lordicast
[Cheeky]Comment[/Cheeky]
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...