A question about subclassed controls


Firstly a small idea of what my program is doing. It is for a national association which has shows. At these shows, they have Championship Classes, that is, the winners of those classes are New Zealand Champions, not just champions in their show. There are 363 different Classes up for grabs. They don’t all have to be allocated. My program takes in a list of clubs interested in each championship, then using the Random function, chooses one. There are two rounds to this selection process. In Round 1 the clubs can only get a total of 6 championships. In the second round they can continue to get as many as they can. So to my question:

I have a subclassed TextField which I have called “Round1Warning” (I know the name doesn’t matter to my question) whose job it is to check when each club has reached six classes. In setting up the TextField to show how many classes each club has, I have used the Round1Warning subclass and created a “club Set” where the members are called “club(0)” “club(1)”, etc to “club(14)”.

Currently the only record of how many classes each club has is in the TextField. Could I store that information in the Round1Warning Class, and if so, could I also store any other information I like, such as the club name, and the actual number of the classes they have “won”? I guess what I am asking, also, is does each club in the clubSet have a different version of the Round1Warning Class? If it does, then I think I just have to add properties to store each of the things I want to store, like the Club Number, Club Name,and which classes they have won. If I store which classes they have won in an array, I could get the number of classes won using ubound?

Am I thinking in an oop manner, or am I completely on the wrong track?


almost sounds like a dog show app :stuck_out_tongue:

Sometimes you would think it is, but in fact it is a Poultry, Pigeons and Caged Birds show.

Still very similar in terms of champions etc
Honestly a database would make organizing & storing this data a TON easier
And simpler to find rather than looping through controls etc

OK, that’s really sounds good. I am already using a database to store the categories (Poultry, Pigeons, etc) and then the breeds within each category and the Class Number and Class Description. As I have already opened that database, I think I will just add more tables to it, and go from there. I open the database in the App Open event.

[code] Dim dbFile As FolderItem
Dim cr As String
Dim startClass As String
Dim numClasses As String
startClass = “”
cr = EndOfLine
dbFile = SpecialFolder.ApplicationData.Child(“Poultry”).Child(“Poultry_db.sdb”)

If dbFile.Exists Then
Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile
If db.Connect Then
// Use the database
Dim sql As String
sql = “SELECT classStart, subcat FROM subcat”
Dim data As RecordSet
data = db.SQLSelect(sql)
If data <> Nil Then
While Not data.EOF
startClass = startClass + data.Field(“classStart”).StringValue
startClass = startClass + ", "
End If
sql = “SELECT * FROM classes”
data = db.SQLSelect(sql)
if data <> Nil Then
numClasses = Str(data.RecordCount)
end If
End If
MsgBox(“Can’t load database”)
End if

Is it open for the life of the program, unless of course I close it?

Nope. db will go out of context at the last End If statement. If you want to keep the database connection then either create a property of App called db, or add a module and add a property to that called db. Then in your code change

Dim db As New SQLiteDatabase


db = SQLiteDatabase .

Ah I see
db goes out of scope - missed that initially

I’d be happy to peek at your db design if you wanted

There are some really great techniques for doing categories / subcategories and then there are the usual normalization techniques
See http://en.wikipedia.org/wiki/Nested_set_model

Thanks Wayne

I will give that a go.

Hi Norman

Thanks for the offer. How would I get the .sdb file to you? Email?

Can’t edit my post but you should change the code to

db = New SQLiteDatabase

You still need the New keyword.

Hi Wayne

OK got that. I do have a question though. I have followed Paul Lefebvre’s Webinar on the Eddies Electronics application. So the way you are suggesting that I do it, is that what Paul called “keeping the database in memory” or words to that effect? Secondly, if you are are familiar with this Webinar, I have created a file called “PoultryDatabase” whose Super is an SQLite Database.
Then inside “App” I created a property called “poultry_db” which is a PoultryDatabase.

Is that the same as you are telling me to do?

When all the disclosure triangles are closed, the Database folder is on the same level as App.

I haven’t followed the Webinar, but do know that the web app version uses an in memory copy of the database to ensure the data is usable for demos. This is not what I’m suggesting. You should add a property to App “poultry_db” Super SqlliteDatabase and in app.open create the instance with poultry_db = New sqllitedatabase. This will then be available to the app while it runs.

If you intend to add threads to your app then create a new connection for each thread, and set up for WAL.

Seeing as you in NZ why don’t you join the Xojo users group in Auckland at http://www.meetup.com/Auckland-Xojo-Users-Group/events/167042712/. I’m hoping to get the next session running through a web conferencing site - Auckland doesn’t have enough users.

Hi Wayne

I have been looking at your Users Group, and did see that some people belong who aren’t in Auckland. I did just think that as I am in the South Island, and retired, it would not be very often that I could attend. But if you are looking at web conferencing, that would be really good. I would probably be a wallflower for a while until I get to grips with Xojo again, but it could be fun.

I will join shortly.