PDA

View Full Version : Visual Basic - Listboxes and the WritePrivateProfileString Property


Geodesic_D
03-27-2006, 09:23 PM
I am writing a VB program which needs to save information added to a listbox. The trouble is, the saving isn't being done properly. When I open the INI file created by my program, all I see is the name of the program in square brackets:

[Reminder Program]

'SAVE STUFF SHOULD BE HERE

What do I need to do in order to fix this?

All information is added to the textbox by the user, with the option to delete what they don't need any more.

Brandoe85
03-27-2006, 09:34 PM
VB6, VB.Net? Whats the code you're using to save the information? Are you trying to save everything thats in the list box(Like looping through the list box items and saving those to a file)?

Please expound on your question.

Geodesic_D
03-27-2006, 09:37 PM
This code is what I'm using to save:


Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long



Dim x As Integer

For x = 0 To cboReminders.ListCount
WritePrivateProfileString "Reminder Program", "Reminder", cboReminders.List(x), "list.ini"
Next x


I know that there's something wrong, that's why I need help. And it's VB6 I'm using, by the way. :thumbsup:

Brandoe85
03-27-2006, 10:02 PM
It's overwriting the file each time through, create a string with all the values and then write it after your loop:

Dim x As Integer
Dim str as String

For x = 0 To cboReminders.ListCount - 1
str = str & cboReminders.List(x)
Next x

WritePrivateProfileString "Reminder Program", "Reminder", str, "list.ini"


Good luck;

Geodesic_D
03-27-2006, 10:34 PM
OK, it saves properly. Now, how do I load the values?

Sorry, I also forgot to mention that I am on a deadline to complete this. It needs to be done by Monday April 3rd.

Geodesic_D
04-03-2006, 09:25 AM
Since I failed to turn my project in on time, I've been given another week.

Please, I need to finish this ASAP - any help is welcome.

Pyth007
04-07-2006, 06:02 PM
Try going through this tutorial, here. (http://www.vbexplorer.com/VBExplorer/focus/ini_tutorial.asp) This should help you to understand what .ini files are as well as the Win32 functions used to interact with them. Also the examples are written in VB so it shouldn't be too difficult to adapt them to your project.

Geodesic_D
04-08-2006, 11:29 AM
Try going through this tutorial, here. (http://www.vbexplorer.com/VBExplorer/focus/ini_tutorial.asp) This should help you to understand what .ini files are as well as the Win32 functions used to interact with them. Also the examples are written in VB so it shouldn't be too difficult to adapt them to your project.

I read it, but it still doesn't work. Forgive the post that was here before this - I was in a bad mood :( Sorry!

Boylinux
04-15-2006, 10:23 PM
Dim x As Integer
Dim str as String

For x = 0 To cboReminders.ListCount - 1
str = str & cboReminders.List(x) & "|"
Next x

WritePrivateProfileString "Reminder Program", "Reminder", str, "list.ini"

When reading back On Form_Load() split the ...

[Reminder Program]
Reminder=<data>|<data>|<data>

...data by "|" and cboReminderList.additem <data> later

as the listindex is not required to match then try this...

Geodesic_D
05-04-2006, 12:08 PM
Dim x As Integer
Dim str as String

For x = 0 To cboReminders.ListCount - 1
str = str & cboReminders.List(x) & "|"
Next x

WritePrivateProfileString "Reminder Program", "Reminder", str, "list.ini"

When reading back On Form_Load() split the ...

[Reminder Program]
Reminder=<data>|<data>|<data>

...data by "|" and cboReminderList.additem <data> later

as the listindex is not required to match then try this...


I didn't understand a word of that. :eek:

Geodesic_D
05-04-2006, 02:03 PM
I've attached the source code for the program. I don't usually do this, but I was hoping one of you guys would have a proper look at the code.

4488

BTW, I will kindly ask that whoever fixes my mess please EMAIL ME THE FILE. I don't want my program source code going to someone who might take all credit for it. Thank You.