|
-
Jul 19th, 2007, 09:45 PM
#1
Thread Starter
New Member
[2005] listview read and save CFG
Hi,
I need to read a file .cfg (it's like an .ini) and change, read some information.
here is and exemple of the CFG file:
Code:
[rubrique]
item.0=10.0, 15, 1
item.1=12.0, 11, 5
item.2=17.0, 15, 3
etc...
First, I need to read all lines in [rubrique] and keep only the first number after = (So in the example, I want to add in my listview 10, 12 and 17
So I have a listview.
To read the CFG I use:
Code:
Declare Auto Function GetPrivateProfileString Lib "kernel32.dll" (ByVal section As String, _
ByVal key As String, ByVal defvalue As String, ByVal retval As System.Text.StringBuilder, _
ByVal bufsize As Integer, ByVal path As String) As Integer
Public Shared Function ReadCfgValue(ByVal path As String, ByVal section As String, _
ByVal key As String, Optional ByVal defvalue As String = "") As String
Dim sb As New System.Text.StringBuilder(1024)
GetPrivateProfileString(section, key, defvalue, sb, 1024, path)
Return sb.ToString()
End Function
Dim rubrique As String = ReadCfgValue("Path_of_the_CFG", "rubrique", "item.0")
Dim MyArray() As String
Dim MyString As String
MyString = (rubrique)
MyArray = Split$(MyString, ".")
ListView1.Items.Add(MyArray(0))
BUT with this code, I can add only the first number of the first item. IT's normal because I read the key item.0 but...
First question:
How can I read all items. (Important, I don't know how many item is in the CFG of the user)
If the first question is resolved, I want to be able to click on an item in my listview and change/save the number if I need (via and other Form with a textbox where the user can change the number)
Second question:
So, how can change a number in the listview and save in the .CFG
Thanks for your help...
Last edited by livai; Jul 20th, 2007 at 06:10 AM.
-
Jul 19th, 2007, 11:16 PM
#2
Re: [2005] listview read and save
Can you open this file in a text editor. If yes then why not use StrimReader to read and separate the info.
-
Jul 20th, 2007, 12:17 AM
#3
Thread Starter
New Member
Re: [2005] listview read and save
Ok, I find a solution to load the number and to change it in my listview.
The last difficulty is :
How can I save (replace) the new entry in my CFG file ???
Please, help it's my last difficulty for this prog
thanks
Last edited by livai; Jul 20th, 2007 at 06:09 AM.
-
Jul 20th, 2007, 07:06 AM
#4
Thread Starter
New Member
Re: [2005] listview read and save CFG
I found this solution
Code:
EntireString = EntireString.Replace("old_number", ListView1.Items(0).SubItems(1).Text)
but the result is
Old version:
[rubrique]
item.0=10.0, 15, 1
item.1=12.0, 11, 5
item.2=17.0, 15, 3
etc...
New version:
[rubrique]
item.0=100
item.1=200
item.2=300
etc...
How to don't change these numbers after "," ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|