Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 8:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Finding section number in an ini file from an elements data
PostPosted: December 31st, 2008, 10:37 am 
Offline

Joined: March 8th, 2005, 9:40 pm
Posts: 63
Compliments of the season!

I wonder if anyone can help me?

I have an ini file with the following info:
Code:
[U01]
Data=1,1,1,1
Attrib=1,3
[U02]
Data=2,2,2,2,
Attrib=1,
[U03]
Data=0,3,0,3
Attrib=3,


The ini can have up to 99 sections
Not all sections may be included in the ini. i.e It may only have sections U01, U05, U99.

What I need to be able to do is
1. Find out if a specific data string is in the data element of any of the sections. Note: there will be no duplications in the Data element. i.e. "0,3,0,3" will only be found in the Data element of one section.
2. If the data string is found, establish which Section the data string is in. i.e. U03.

I can do this the long and clumsy way using the following for U01 to U99:
Code:
var U01 = GetINIFileData(SYSTEM_PUBLICATION_DIR"+Student+".ini", "U01", "Data")
var U02 = GetINIFileData(SYSTEM_PUBLICATION_DIR"+Student+".ini", "U02", "Data")
var U03 = GetINIFileData(SYSTEM_PUBLICATION_DIR"+Student+".ini", "U03", "Data") //etc to U99
var testdata=U01+"f,"+U02+"f,"+U03+"f," // etc, up to U99 ("f" is being used as a terminator)
var datatrue=String.contains(testdata,UserData)// UserData is the data that needs to be compared with the elements data i.e 0,3,0,3,
if ( String.contains(testdata,UserData)){
       ValidData=1
       DataNo =""
       if (U01 == UserData){
           DataNo = "U01"
       }
       if (U02 == UserData){
           DataNo = "U02"
       }
       if (U03 == UserData){
           DataNo = "U03"
       }// would need to do this for U01 to U99
var UserAttrib = GetINIFileData(SYSTEM_PUBLICATION_DIR"+Student+".ini", DataNo", "Attrib")
}

Else {
ValidData=0
}


How can I do this more efficiently

Regards

Neil

_________________
Opus Pro V6
Dell Inspiron 9400
Intel Centrino Duo 2GHz
2 Gig Ram
XP SP2


Top
 Profile  
 
 Post subject:
PostPosted: December 31st, 2008, 12:35 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Neil,

A FOR or WHILE loop will make light work of this. Simply replace the "Uxx" in your getINI line with a a variable that is incremented inside the loop.

The data read back and be stored in an array which also gets incremented inside the loop. As for the checking, either concatinate the array using JOIN or simply check the existance of your data as the loop executes (less code).

I'm Opus free until the weekend, but I'll if you get stuck - I'll upload a sample once the detox is over :-)

Enjoy the New Year.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Got It!
PostPosted: December 31st, 2008, 5:02 pm 
Offline

Joined: March 8th, 2005, 9:40 pm
Posts: 63
Hi Mack,

Thanks for the tip, it set me on the right track... :D
I had a feeling that I would need to use a for loop, but have always had a mental block about them.
I managed to do this :lol: , even though the loop is not a typical one 8) .

Code:
function checkdata(){
var i=1
for(;;){
    if (i<10){
       var x="U0"+i
    }
    if (i>=10){
       var x="U"+i
    }
var p1 = GetINIFileData(SYSTEM_PUBLICATION_DIR+Student+".ini", x, "Data")
    if(p1==UserData){
       Debug.trace("Found"+p1)
       Debug.trace("Found"+x)
       break
    }
    if(i==99){
       Debug.trace("not Found")
       break
    }
i++
}
}


Regards
Neil

_________________
Opus Pro V6
Dell Inspiron 9400
Intel Centrino Duo 2GHz
2 Gig Ram
XP SP2


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 48 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group