Sign in to follow this  
Followers 0
GEOSoft

Anyone Have A Good Idea For This?

5 posts in this topic

#1 ·  Posted (edited)

Probably fairly simple but I was up all last night doing Do....Until and While..Wend statements so the brain is foggy to say the least. These are the only parts of the existing script I am concerned with.

$ini = @WindowsDir & '\My.ini'
;Read INI File
$Na1 = IniRead ( $ini, 'Source', 1, "" )
$Na2 = IniRead ( $ini, 'Source', 2, "" )
$Na3 = IniRead ( $ini, 'Source', 3, "" )
$Na4 = IniRead ( $ini, 'Source', 4, "" )
$Na5 = IniRead ( $ini, 'Source', 5, "" )
$Na6 = IniRead ( $ini, 'Source', 6, "" )
$Na7 = IniRead ( $ini, 'Source', 7, "" )

DIM $a[8]
$a[0] = $Na1
$a[1] = $Na2
$a[2] = $Na3
$a[3] = $Na4
$a[4] = $Na5
$a[5] = $Na6
$a[6] = $Na7
$a[7] = <This one is handled differently so we ignore it>

As you can see I am reading an Ini file one line at a time. In order to add items to the INI I also have to modify and re-compile the script. This should be avoidable by having it read the ini file into an array and using the count of the array to replace the current IniRead lines and to set the numbers in the $a array. That way all I would have to do is add an item to the INI file and the code would take care of the rest. Any good suggestions?? :whistle:

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I would put the entire array (delimited by say "\") in a single parameter of the INI file. Then use StringSplit() to dynamically allocate the internal array :whistle:

Edited by trids

Share this post


Link to post
Share on other sites

how about something like this:

Dim $IniRecs[100]
$Rec = 0
$ini = @WindowsDir & '\My.ini'
; read ini entries till return value is ""
While 1
   $trec = IniRead ( $ini, 'Source', $Rec+1, "" )
   if $trec = "" then ExitLoop
   $Rec = $Rec + 1
   $IniRecs[$rec] = $trec
Wend
msgbox(0,"INI records returned"," INI records returned:" & $Rec )
; do your thing
For $x = 1 to $Rec
;   whatever  $IniRecs[$x]
Next

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yea, quick conversion of the original.

$ini = @WindowsDir & '\My.ini'
DIM $a[8]
for $i= 1 to 7
$a[$i]= IniRead ( $ini, 'Source', $i, "" )
next

But I normally read this directly into an array to save from dimming, and to auto set $a[0] to the amount of parts of the array.

$ini = @WindowsDir & '\My.ini'
$a=StringSplit(IniRead ( $ini, 'Source', jump, "" ),"|")

[Source]
jump=a|b|c|d|e|Froggy goes to town|g|9234234

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Quick example of InI type:

If FileExists ("configme.ini") Then
Else
$x="a|b|c|d"
IniWrite ("configme.ini","Delay","delay",$x) 
EndIf
$y = IniRead("configme.ini","Delay","delay",1000)
$array=StringSplit($y,"|")

For $i=1 To $array[0]
MsgBox(1,"",$array[$i]) 
Next
$new = InputBox("Question", "Add something?", "Planet Earth", "", -1, -1, 0, 0)
If StringLen($new)>0 Then 
    $x=""
    For $i = 1 To $array[0]
    $x=$x&$array[$i] & "|"  
    Next
$x=$x&$new
IniWrite ("configme.ini","Delay","delay",$x) 
EndIf

AutoIt3, the MACGYVER Pocket Knife for computers.

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
Sign in to follow this  
Followers 0