Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Clumping entries in an ini file 2

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
I have an ini file of just one section's eg [Filter] entries.

I am going to display them in an Edit box on a form.

I would like the 'True' and 'False' to be separately together and listed before the string values for easier reading by the user.

thus far I have this code

<code>

myfile = 'filtertemp.txt'
lcINI = Filetostr(myfile)

create cursor myIni (myLine c(254))
append from filtertemp.txt type sdf

create cursor myNewIni (myLine c(254))

append from myIni FOR 'True'$myLine
append from myIni FOR 'False'$myLine
append from myIni FOR !'False'$myLine OR !'True'$myLine
browse
</code>

These appends don't work.
Can anyone point me to the correct syntax please.

Thanks.

Coldan
 
I have modified the above code and the only 'not working' part is the extraction of the entries not containing = False or =True.

This is my SQL

Select * From myIni Where !'=False'$myIni.myLine OR !'=True'$myIni.myLine Order By myLine Into Cursor mycursor3

I have tried a bracket for the where clause

What do I do please?

Coldan
 
Coldan,

I think you need to change the OR to AND.

As it stands, you are getting to get all entries. That's because you're asking for entries that don't contain false or that don't contain true. Well, all entries don't contain one or other (unless an entry can contain both, but I assume that won't happen).

If you change the OR to AND, you're going to get all entries that contain something other than true or false, which I think is what you want.

I know it doesn't sound intuitive, but try it and see.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Coldan,
Did you check your expression? Logically it means select all. Do you mean that you want only those lines that either have a True or False in them? (Or all except those lines? You can apply this either by moving the ! outer or using AND instead of OR)

Code:
* Lines that have either True or False
Select * From  myIni ;
  Where  ('=False'$myIni.myLine OR '=True'$myIni.myLine) ; Order By myLine ;
Into Cursor mycursor3

* Lines that doesn't have neither True nor False
Select * From  myIni ;
  Where  !('=False'$myIni.myLine OR '=True'$myIni.myLine) ; Order By myLine ;
Into Cursor mycursor3


IMHO instead of $ operator (which is no way of supporting case insensitivity without the help of another function) use atc() function:

Code:
* Lines that have either True or False
Select * From  myIni ;
  Where  ( ;
   atc('=False',myIni.myLine) > 0 OR 
   atc('=True', myIni.myLine) > 0 ;
 ) Order By myLine ;
Into Cursor mycursor3

* Lines that have neither True nor False
Select * From  myIni ;
  Where  ( ;
   atc('=False',myIni.myLine) = 0 AND 
   atc('=True', myIni.myLine) = 0 ;
 ) Order By myLine ;
Into Cursor mycursor3

And your append:
Code:
myfile = 'filtertemp.txt'

Create Cursor myNewIni (myLine c(254))

* Get True first, False second, others last
Append From (m.myfile) Type Sdf For Atc('=True', myLine) > 0
Append From (m.myfile) Type Sdf For Atc('=False', myLine) > 0
Append From (m.myfile) Type Sdf  For ;
  atc('=True', myLine) = 0 And Atc('=False', myLine) = 0

Browse
Or you could have the same effect with an index:
Code:
myfile = 'filtertemp.txt'

Create Cursor myNewIni (myLine c(254))
Append From (m.myfile) Type Sdf

Index On Icase( ;
  Atc('=True', myLine) > 0, 1, ;
  Atc('=False', myLine) > 0, 2, ;
  3) Tag showOrder
Browse

Or maybe you would opt to use a select to get them in the order you want:
Code:
myfile = 'filtertemp.txt'

Create Cursor myIni (myLine c(254))
Append From (m.myfile) Type Sdf

Select * From myIni Where Atc('=True', myLine) > 0 ;
  UNION All ;
  SELECT * From myIni Where Atc('=False', myLine) > 0 ;
  UNION All ;
  SELECT * From myIni Where Atc('=True', myLine) = 0 And Atc('=False', myLine) = 0 ;
  INTO Cursor myNewIni
Browse

There are at least 3 ways in VFP as they say:)

Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top