Fires of Heaven Guild Message Board  

Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
Or, use your gamerDNA username: (more...)
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-05-2007, 08:53 AM   #1 (permalink)
Grooverider
hildog
 
Grooverider's Avatar
 
Join Date: Aug 2002
Posts: 860
+0 Internets
VB6 help.. again ;)

Having a little problem.

Reading settings in the following format from an INI file:

[general]
totalrecords=3[list]
infoname1=Blahblah
infoemail1=blah@blah.com
infoname2=Mr.White
infoemail2=White@sad.com
infoname3=Mr. Black
infoemail3=black@mr.com

When i'm deleting a record; say record 2, it reduces totalrecords to 2. However, i'm stuck with info1 and info3 as the two records.

I'm populating the .name into a listbox in the following way:

Read Total Accounts from INI

For i = 1 To TotalAccounts

AccountList.AddItem (ReadIniValue(App.Path & "\config.ini", "list", "infoname" & i))
AccountList.ItemData(AccountList.NewIndex) = i

Next i


Obviously.. there's a large problem with this. Any suggestions?
Grooverider is offline   Reply With Quote
Old 12-05-2007, 11:02 AM   #2 (permalink)
Zippygoose
Math Enthusiast/Badass MC
 
Zippygoose's Avatar
 
Join Date: Jun 2002
Location: Seattle
Posts: 650
+0 Internets
Send a message via AIM to Zippygoose
I'm not exactly sure what you are trying to do here.

Could you post the business requirement/homework assignment that needs to be accomplished along with your code?
Zippygoose is online now   Reply With Quote
Old 12-05-2007, 12:39 PM   #3 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
More details would help. Is this a structure you created or one you have to work with? The way you have it, you have to re-write the entire list to update the numbers you are using.

If you are coming up with this structure my suggestion is use XML.
Hachima is offline   Reply With Quote
Old 12-05-2007, 04:04 PM   #4 (permalink)
Niceshot23
Registered User
 
Join Date: Oct 2004
Posts: 112
+0 Internets
going by what you wrote, id open the ini file and put it all into 1 string and manipulate it instead of actually using the readini function.... here's what i suggest

dim strText as string
dim intStart as long
dim intEnd as long
dim intRecords as int
dim intRecord as long
dim strname as string
dim stremail as string

'strtext should equal to the
strText = "[general]
totalrecords=3[list]
infoname1=Blahblah
infoemail1=blah@blah.com
infoname2=Mr.White
infoemail2=White@sad.com
infoname3=Mr. Black
infoemail3=black@mr.com"

intstart = instr(strtext, 1, "[general]")
intstart = instr(strtext, intstart, chr$(13))

'if it equals 0 then it means that this entry wasnt in the ini file
if intStart = 0 then exit sub

'now you should be at totalrecords= line
intstart = instr(strtext, intstart, "=")
intstart = intstart + 1

intend = instr(strtext, intstart, "[list]")

intrecords = mid(strtext, intstart, intend - intstart)

'now make a loop looking for "infoname1="
intrecord = 1
do until intstart = 0
'name
intstart = instr(strtext, intstart, "infoname")
intstart = instr(strtext, intstart, "=")
intstart = intstart + 1
intend = instr(strtext, intstart, chr$(13)
strname = mid(strtext, intstart, intend - intstart)

'email
intstart = instr(strtext, intstart, "infoemail")
intstart = instr(strtext, intstart, "=")
intstart = intstart + 1
intend = instr(strtext, intstart, chr$(13)
stremail = mid(strtext, intstart, intend - intstart)

'intrecord is the number of times it goes through this loop, meaning that there are that many "infoname"'s regardless of the number next to it
intrecord = intrecord + 1
loop

once you're complete, using all the numbers and strings you've grabbed, you should be able to create a new string and use that to overwrite the ini file ....


i havent ran this i just typed this out in the comments ... dont have vb at work but i've worked 6 years in vb so i know what im doing ... besides, im only going on what you've written ....
Niceshot23 is offline   Reply With Quote
Old 12-05-2007, 05:22 PM   #5 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
that seems like a lot of messy hard coding just to grab INI data when there are already working methods to grab the key value pairs. I'd rather just make an INI file class to deal with it. Here is what I'd use in C#. You can probably do a VB equivalent.


Quote:
public class IniFile
{
public string path;

[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);


public IniFile(string INIPath)
{
path = INIPath;
}

public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}


public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp,
255, this.path);
return temp.ToString();

}
}

Last edited by Hachima : 12-05-2007 at 05:25 PM.
Hachima is offline   Reply With Quote
Old 12-05-2007, 06:35 PM   #6 (permalink)
Shots
Registered User
 
Shots's Avatar
 
Join Date: Nov 2006
Posts: 466
The only way to do it is to rewrite the section, as you've found out. Either calling WritePrivateProfileString in a loop (to null the old and then write then new) or calling WritePrivateProfileSection after you've manually rebuilt the Section in a string.
Shots is offline   Reply With Quote
Old 12-06-2007, 02:18 AM   #7 (permalink)
Grooverider
hildog
 
Grooverider's Avatar
 
Join Date: Aug 2002
Posts: 860
+0 Internets
Yeah, shots you've called it.

I've decided to make it so that the final entry in the ini is moved to plug the deleted hole..
Grooverider is offline   Reply With Quote
Old 12-06-2007, 11:30 AM   #8 (permalink)
Niceshot23
Registered User
 
Join Date: Oct 2004
Posts: 112
+0 Internets
its also pretty easy to just write to the registry....
Niceshot23 is offline   Reply With Quote
Old 12-07-2007, 05:27 AM   #9 (permalink)
Grooverider
hildog
 
Grooverider's Avatar
 
Join Date: Aug 2002
Posts: 860
+0 Internets
Nah, I want the data to be transferrable. Registry isn't great for it imo
Grooverider is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On
uberguilds network



All times are GMT -7. The time now is 01:20 AM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6