Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Reading config file


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2008, 10:16 AM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 237
Awards Showcase
Beta Tester 
Total Awards: 1
Default Reading config file

I'm creating my first (simple) application and I like to save the config..
I have been playing around with this this
Which works, but i'd like to see "name=value" in the config file..
I've already adapted the write part, but the reading part is giving me headaches
So my question to you is


The code in the tutorial is reading the ini file line by line, this also prevents comments (which I would also like :-)
I think I might be able to use the StrIndexOf and then a StrSlice, but first things first..

I was thinking something like the below to start with (bold part is changed)
Code:
Sub LoadINI
  ErrorLabel(errLoadINI)
  If Not(FileExist("Config.ini")) Then Return
  FileOpen(c2,"Config.ini",cRead)
  CheckBox1.Checked = StrSplit(FileRead(c2),"=")
  CheckBox2.Checked = StrSplit(FileRead(c2),"=")
  FileClose(c2)
  Return
  errLoadINI:
  Msgbox("Error reading INI file.","",cMsgboxOK,cMsgboxHand)
  FileClose(c2)
End Sub
the only issue with this is that there is no value assigned to the CheckBox
Because i'm not specifying which part of the split I want to use...
I couldn't find how to do this, I tried the JScript way, but that didn't work :-(

Any help is highly appreciated

Thanks!
Reply With Quote
  #2 (permalink)  
Old 03-04-2008, 11:20 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,900
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

You can ignore comments and blank lines with something like this. In this case a comment begins with a single quote

Code:
Do
  r = FileRead(c1)
Loop Until r <> "" AND StrAt(r,0) <> "'"
You could parse your lines something like this.
Code:
Sub Globals
  'Declare the global variables here.
  Dim temp(0)
End Sub

Sub App_Start
  Form1.Show
   temp() = StrSplit("Checkbox1=true","=")
  Control(temp(0)).checked = StrToLower(temp(1))
End Sub
Note that if you are using true and false like this they must be "true" and "false" not "True" and "False" or an error will occur. If the values are human entered you may need to check for leading/trailing spaces.
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 11:41 AM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 237
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
You can ignore comments and blank lines with something like this.
In this case a comment begins with a single quote
Note that if you are using true and false like this they must be "true" and "false" not "True" and "False" or an error will occur. If the values are human entered you may need to check for leading/trailing spaces.
Cool, so by replacing the "'" with "#" would accomplish the same
Maybe i should put in a function which does a StrToLower and StrReplace spaces, just to be sure

Thanks for the help
Reply With Quote
  #4 (permalink)  
Old 03-08-2008, 09:42 AM
maXim's Avatar
Senior Member
 
Join Date: May 2007
Location: Florence, Italy
Posts: 168
Send a message via MSN to maXim Send a message via Skype™ to maXim
Awards Showcase
Beta Tester 
Total Awards: 1
Post

Hi All,

look at the thread "db2000 - INI" in "Italian Forum" (db2000 - INI)...
Is it useful to Your need?
Reply With Quote
  #5 (permalink)  
Old 03-14-2008, 04:05 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 237
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Yes, it looks usable, but my italian is not really up-to-par :-)
I need to dive into it, but thatnks for the heads-up
Reply With Quote
  #6 (permalink)  
Old 03-14-2008, 08:50 PM
maXim's Avatar
Senior Member
 
Join Date: May 2007
Location: Florence, Italy
Posts: 168
Send a message via MSN to maXim Send a message via Skype™ to maXim
Awards Showcase
Beta Tester 
Total Awards: 1
Post

Hi Mr_Gee

in db2000 - INI library (DLL version) there are two operating modes whose functions are very simple:

MODE 1

' initialize mode 1
.New1([INIFileName])
' example:
INI.New1("test.ini")

' write or update a row into INI file
.write1([Section], [Key], [Value])
' example:
INI.write1("USER", "Name", "maXim")

' read a row from INI file
.read1([Section], [Key], [DefaultValue])
' example:
myVAR = INI.read1("USER", "Name", "empity")
' if row not exist or is not valid, value of myVar is equal as [DefaultValue]

' delete from INI file a specific [Section] and all his keys
.DeleteSection1([Section])
' example:
INI.DeleteSection1("USER")

MODE 2

' initialize mode 2
.New2
' example:
INI.New2

' write or update a row into INI file ([INIFileName])
.write2([INIFileName], [Section], [Key], [Value])
' example:
INI.write2("test.ini", "USER", "Name", "maXim")

' read a row from INI file ([INIFileName])
.read2([INIFileName], [Section], [Key], [DefaultValue])
' if row not exist or is not valid, value of myVar is equal as [DefaultValue]
' example:
myVAR = INI.read2("test.ini", "USER", "Name", "empity")

' delete from INI file ([INIFileName]) a specific [Section] and all his keys
.DeleteSection2([INIFileName], [Section])
' example:
INI.DeleteSection2("test.ini", "USER")

I am always available for You if has difficulty of use or if it needs more clarification.

Best Regards.

Massimo

Last edited by maXim : 03-15-2008 at 12:11 PM.
Reply With Quote
  #7 (permalink)  
Old 03-15-2008, 12:00 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 237
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Grazie Milla Massimo :-)
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
need for exe.config file? aureolevoyager Questions & Help Needed 2 03-01-2008 09:15 AM
exe.config problem agraham Bug Reports 1 01-13-2008 07:54 AM
Reading ini file values into a combox-list Softselect Questions & Help Needed 2 11-15-2007 04:41 AM
what's app.exe.config blackiice Questions & Help Needed 3 10-23-2007 01:38 PM
? Just a quick question, ****.exe.config taximania Questions & Help Needed 12 09-01-2007 08:15 PM


All times are GMT. The time now is 06:53 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0