Hello all :) It's not really a coding problem I have right now, more it's a question what/how I could accomplish following task: I got Text loaded from a File (Line by Line) into a ListBox, now if the user enters a text and hits compare there should pop up a MsgBox telling if it was found or not in the ListBox. Now if the User adds a string to my ListBox should I just open simultaneously the file, search for the end of it (until *hehehe*) append it there and save the file again? All ideas are welcome. Too sad there is not an "SaveListBoxToFile"-API around when you need one. :( PS: What if one entry get's changed? Should I just be lazy and "xxxxxxxxx" out the old and write the modified at the end ? This message was edited by JimmyClif, on 3/10/2001 4:02:55 PM
JimmyClif Too sad there is not an "SaveListBoxToFile"-API around when you need one. You have to write it self. 1) Get each field from index 0 and write one by one into a file. or 2) ;=============================================================== ; Write fields into a Buffer first and you may add separator "," ;=============================================================== .while true ; == for ever invoke SendMessage,hListBox,LB_GETTEXT,index,edi ;edi point to a buffer .if eax!=0 ; if length = 0 mean emty field or last index add charlen,eax ; add length to counter add edi,eax ; adjust edi by field length mov al,"," ; add sepatator if you wish stosb ; and store inc charlen ; adjust counter .break .if charlen==index ; .endw Then write buffer to a file. You will be OK even if you insert field with "LB_INSERTSTRING" Hope this help.
Thanks forge, But I kinda decided to let the program flow into another direction... I now primarly use the ListBox as visual tool for the user. The whole program could deal without it, I just leave it inside in case the user wants to modify an entry. Every entry as soon as it is made is saved inside the textfile which gets opened simultaneously. That was the only choice I had as the Strings are 0 terminated and my Text-File Buffer was zero_initiated with GlobalAlloc. Here is what I did: (Maybe someone ever thought about dealing with this (besides Stefan Krause ;) )) I created a 65535d bytes big .cfg file which I filled up with 20h (spaces). As I have two ListBoxes I wrote at the beginning
- , in the middle at 30000d
- and at almost the end (at 60000d) .
Now I was able to read & save 0-Terminated strings one behind the other using always the Offset + SIZEOF List1 and start reading if the byte I was at is != 20 or "[", and adding to the ListBox when a 0 was found. Writing is exactly the opposite.
For modifying, I guess I simply xxxxx out the old entry and write the modified at the end... or is someone out there having a better idea?
Forge, I assume your way is much easier but erm.. well... I'm still learning.
Hi JimmyC I'm still learning as well. ------------------------------------------------------------------- For modifying, I guess I simply xxxxx out the old entry and write the modified at the end... ------------------------------------------------------------------- Instead to have a big file at the start, make it as a data base. For every entry allocate equal amount of bytes for list1 plus list2. Save them in sequence into your text file and you can index them. If then for example you want to change record no 7 simply multiply 7 by record bytes - set file pointer and write a record no. of bytes. To add new entry - set file pointer to the end of the file and write again same amount of bytes. If the entry say are 1byte than fill the rest with spaces. If you terminate the string (field) with comma instead zero and terminate the record with return then you could import or export your file into an Excel. It is just suggestion as I have 5 synchronised listboxes next to each another for user entry. Not the best, but it works. If your entry are very different in size it is probably vaste of space. Use the ListBox for user display only or use DrawText. Hope this may help a little. forge This message was edited by forge, on 3/11/2001 5:25:20 PM
Guys, Just have a look at the range of LB_#### messages that you can use to manipulate list boxes, once you get the swing of them, you can do most of the things you need with no problems at all. Regards, firstname.lastname@example.org
Hutch-- Could you elaborate a little bit about what LB_##### message you got in mind? (hehehe) Actually, I had a quick look on all of them again and I wonder what this LB_ADDFILE could be? Is it the one I need for reading the content of a file into a ListBox? And what does the The list box to which lpszFilename is added must have been filled by the DlgDirList function. mean? This is used as far as I can understand it as a method to fill a ListBox with a dir-listing... Forge, I understand your idea and it sounds good, but I believe I could fill up the textspace much more efficient writing one behind another. Anyway... I keep the index * 7 in mind as it is certainly easier to search for a specific record then. This message was edited by JimmyClif, on 3/12/2001 12:45:59 PM
Jimmy, What you are looking for in a high level file to list box message or function simply does not exist. To load the contents of a file into a list box requires that you read the file on a line by line basis and use LB_ADDSTRING to add each item. This means that you must write an algorithm to split the text file on its CRLF (ascii 13, 10) and then add each string seperately to the listbox. LB_RESETCONTENT empties the list box if you need to reload it from scratch again and you can delete or insert lines in the listbox with other messages. If you bother to read win32.hlp, there are a lot of messages for list boxes and they are very flexible to use if you bother to earn how they work. Regards, email@example.com
Hutch, erm... I knew that ;D I do read the win32.hlp file... I'd take it to bed if I could!! and I wrote already my little algo splitting my text and adding it to the ListBox... I just got a glimpse of hope when reading your reply saying "Just have a look at the range of LB_#### messages... ...you can do most of the things you need with no problems at all." Anyway... my problems are all solved... thanks for helping!