Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving state of selected items in listbox

Status
Not open for further replies.

TheVampire

Programmer
May 1, 2002
828
0
0
US
I can save the state of selected items in a checkbox style list like this:

Dim Total As Variant
Dim I As Integer
Total = CDec(0)
For I = 0 To List1.ListCount - 1
If List1.Selected(I) = True Then
Total = Total + (2 ^ I)
End If
Next I


Then I can save the value of total.

I can retrieve the value and set the list like this:

For I = 0 To List1.ListCount - 1
If (Total And (2 ^ I)) = (2 ^ I) Then
List1.Selected(I) = True
Else
List1.Selected(I) = False
End If
Next I


This works fine up to 94 items in the list.

Does anyone have a solution to store the state in a single variable if I have more than 94 items?

( I know, having this many items in a single listbox isn't very good design, but circumstances are forcing this on me... )

One way I thought of was to have a string of 0's and 1's, and each one would indicate the state of the corresponding list item.

I could also divide the list up into 2 or more parts and save each part like I showed above ( but that takes more code and more room in the database, etc. ). Plus I really don't know what the eventual total # of items in the list may be . ( although I'm pretty sure it won't be more than 200 or so... )

Just looking for the most efficent way to do it!

Robert
 
You're already using the biggest exact numeric type (Decimal) which uses a 12-byte (96 bit) representation and you've spotted that 92 bits are use as binary rep of number and 4 bits as a scale factor - so you're out of luck with a single variable as a numeric.

You mention storage considerations, so storing O's and 1's while use (potentially) 200ish bytes per string variable.

If you don't mind a bit of extra processing you could save storage and save a hex string, which would get you down to about 50 byte strings, but at cost of more processing than your binary string.

I guess it's the classic data storage trade-off of speed versus storage capacity required


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top