I used, in the past, ways to save some service data associated to text (all in a text file). That worked and I was happy with it. This is related to ListBox (or must I wrote Listbox ?)
Yesterday, I had the stupid idea to do the same in a current project and I fall into these traps:
- The Colors.
I saved to disk nto a text file, two color definitions: cmy(0.1,0,0) and cmy(0,0,0.1). They are stored in a set of Properties used in ListBox1.CellBackgroundPaint to display alternatively the ListBox background Rows.
WHAT A STUPID IDEA. The correct way to store a color on disk is:
The Columns Widths.
Why dont also retrieve a proposed (default) list of columns widths ?
So, I added to the file a set of integer values, coma separated (the correct number of integers), and this does not works as intended: only the first column was set properly and the other columns share the rest of the space.
Side effect: no horizontal scroll bar.
The Header strings.
I also saved to disk the ListBox header for the text data that follows. For some reason I discovered after many hours, this was not the right way to do things.
BUT, the text data was correctly displayed in the columns. Go figure.
Side effect: no horizontal scroll bar.
Now here are the solutions to problems 2 and 3 and these resolve the horizontal scroll bar bad behavior (side effect).
In my code, I added the lines:
a. Get the number of \Tab in the Header string (the string I pass later to the ListBoc header),
b. Use that value to set the ListBox number of Columns (ColumnCount).
[after I finished to type this text, I found a different way to do that: set the headers after populating the ListBox. No need to compute the number of tabs in the heading line.]
- The final code:
The two lines that makes the code working fine are at entry d, below.
I found an alternate way to achieve the same goal:
do not use entry d and move entry g at the end of the code (after populating the ListBox.
even if this can make some sense (no, the only logical way to do is vertically ), I do not think at that until I was writing this text (so, after I found a solution.
I just noticed that the original code have entry d (read below). The problem then was the background color ‘bug’. I re-wrote the whole method in Window1.Open (to speed up the process) and forgot about that. Weird.
Used code (I skipped the Dim lines to be shorter):
[code] // a. Get a reference to this file
OpenFI = GetFolderItem(“Default Data.txt”)
// b. Get a Referente to read the file
OpenTIS = TextInputStream.Open(OpenFI)
// c. Load the ListBox background colors
ColHeaders = OpenTIS.ReadLine // Get the Header String
ColWidths = OpenTIS.ReadLine // Get the Column Widths String
RowColors = OpenTIS.ReadLine // Get the Colors String
// d. Get and set the Column Count
ColCnt = CountFields(ColHeaders,Chr(9))
LB.ColumnCount = ColCnt
// e. Get the colors
ColorOne = NthField(RowColors,Chr(9),1)
ColorTwo = NthField(RowColors,Chr(9),2)
// f. Store the colors
gBkgnd_Blue = ColorOne
gBkgnd_Yellow = ColorTwo
// g. Set the header & the Column widths
LB.ColumnWidths = ColWidths
LB.Heading(-1) = ColHeaders
// Not displayed: the Do
Loop Until OpenTIS.EOL (read lines / AddRows) and OpenTIS.Close lines.
Of course, “Default Data.txt” have to have three service lines in the correct order before the real text data.
Line 1: Reprint Date Title Start End Length Print Start Print End
Line 2: 90,250,90,90,100,100,100
Line 3: &h00E5FFFF &h00FFFFE5
All other lines holds the data to add in the ListBox Rows / Columns.
Compiled on Windows XP (VirtualBox), the project shows an IOException and do not works too.
Same project compiled for Windows (on OS X) runs fine on Windows XP [I do not take time to investigate more)
The tested environment:
a. Xojo 2013r3.3
b. Mountain Lion
d. Windows XP
e. MacBook Pro 2011-11
I made cold boots between the tests on Mountain Lion / Mavericks.
When I falled on the troubles, I quit every applications, then run Xojo and get the same troubles.
Then, I made cold boot, runs only Xojo but this was not enough.
I trashed the current Xojo folder and re-install it from the dmg: no change.
cold boot: Power Off the computer, wait some minutes (seconds are enough, but Dear Prudence).
The used code and the results were tested and retested. All three values were checked and found as correct in the debugger. This and a check on the way I saved the colors in a different (and older) project leads me to find how to save a color in a text file (use &h followed by a 32 bits Hex code for the color). The reading part was correct and do not needed to be changed.
- How can I know I have to use &h to describe a color ?
&h in the documentation description is:
Used to represent a hexadecimal literal.
&h does not appears in the documentation at the Color Module description.
even Variant.ColorValue does not talk about &h.
PS: there is a potential bug: if the header string does not holds the correct number of entries (enough entries for the number of columns), there will be a miss in the ListBox header. BUT, this is the text file creator responsibility to do its job correctly.
So, remove the two lines related to count the number of \abs in the Header string and place the Heading attribution after filling the ListBox (after the Do Loop code).