New topic: 

Saving text and loading text to a listbox

<http://forums.realsoftware.com/viewtopic.php?t=47829>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        zyrex          Post subject: Saving text and loading text to a 
listboxPosted: Thu May 09, 2013 12:18 am                         
Joined: Tue Mar 09, 2010 9:47 pm
Posts: 23                I am creating a virtual notebook for my workplace that 
keeps track of notes and number and customer complaints. We currently use an 
actual notebook which has been filled up and they write where ever they can. At 
times it's confusing and things are missed so I made one to custom fit our 
needs.

I'm a generally fair user of REALbasic which is the version I am using not 
Studio. 
There are several windows to the project which each have a listbox. Each 
listbox has 3-6 columns of text. Now awhile ago I asked how to save this text 
for another program I made. The problem I had was loading it back into the 
listbox when the program opens.

I was able to successfully export and read it in notepad but if I wanted to 
change something and it was a lot of data, it could get confusing and lose my 
place. 

Is it possible to export several listboxes on a save button/ program close 
confirmation message box(save before closing? yes/no) to a text file?? 
part 2 of that question is upon program open, can it automatically place the 
information back to the listbox in each proper column?
I don't have a clue on how to code the save and load as I was never taught that 
part. just everything else to complete the teachers projects..
If necessary I can upload the program with what I have.   
                             Top                harriew          Post subject: 
Re: Saving text and loading text to a listboxPosted: Thu May 09, 2013 5:25 pm   
                      
Joined: Fri Dec 01, 2006 3:09 pm
Posts: 649
Location: Tennessee, USA                This is a portion of code where the 
information for the program is read in. Some goes directly to a listbox, some 
goes to data classes. Here is the part reading the file and placing the info 
into the listbox

bs is a binarystream file that has been opened earlier in the code

s, numRows, i, j are all Dimmed as Int32
s is Dimmed as String

Notice the inner For loop  starts at 2 and increments by 2. This particular 
listbox has narrow columns between the columns that actually hold data for a 
nicer separation and effect in this program. So, the odd number columns are 
very narrow and empty.
s = bs.Read(6, Encodings.UTF8)  // read in version string
numRows = bs.ReadInt32  // number of categories in users budget
lblLastCheck.text = bs.ReadPString(Encodings.UTF8)  // read in last check 
number used
//  now fill the categories into the listbox
for i = 0 to numRows
  lbCatInfo.AddRow bs.ReadPString(Encodings.UTF8)  // add a new row
  for j = 2 to 8 step 2  // skipping the narrow spacer columns
  lbCatInfo.cell(i, j) = bs.ReadPString(Encodings.UTF8)  // fill in remaining 
data columns
  next j
next i

Here is the code to write the info from the listbox back out to the 
binarystream file. You should be able to determine how the variables are dimmed 
by looking at the code
num = lbCatInfo.ListCount - 1
bs.write(kVersionID)  // write out version identifier
bs.WriteInt32 num  // current number of categories
bs.WritePString lblLastCheck.text
// output category information
for i = 0 to num
  for j=0 to 8 step 2  // skip the spacer columns, their empty
  bs.WritePString lbCatInfo.cell(i, j)
  next j
next i

Hopefully this will give you a good start on saving and reloading the data.

Note, the WritePstring, ReadPstring methods for binarystreams can only be used 
if the number of characters in a single cell will not exceed 255 characters.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to