Question about Dynamic Arrays..

A section for those creating 3rd party tools and add ons. Lots of techincal code creation type questions would go here.

Moderator: David Winter

Post Reply
Magnum357
Posts: 613
Joined: Thu Apr 21, 2005 11:07 pm

Question about Dynamic Arrays..

Post by Magnum357 »

I need some advice by anybody with some Database programming experience. I'm working on a schedule utility program for MaxFB and I'm running into a problem. The utility works ok and can edit a leagues schedule, but my program only displays the Team ID number in a listbox instead of the Teams actual team name.

My problem is that I can't find a way to store the team names from a League Database and then load them into Listbox so they display the Team names and not the Team ID numbers. I was thinking about using a Dyamic Array because since a league Database can have virtually an unlimited amount of Teams in the league, I would need to have an unlimited amount of Varibles to store the there names in. Unless somebody has a better solution, Dynamic Arrays are the only thing I can think of that would allow me to do this. Can anybody give a small example of how too use a Dynamic Array?
MjH
Posts: 165
Joined: Wed Feb 22, 2006 11:56 pm

RE: Question about Dynamic Arrays..

Post by MjH »

You don't say what language you're using, but I googled using "dynamic array microsoft" and got the following as the first result:

http://www.microsoft.com/technet/script ... x?mfr=true

If you're using VBScript, then that appears to be a pretty straight-forward example.
Magnum357
Posts: 613
Joined: Thu Apr 21, 2005 11:07 pm

RE: Question about Dynamic Arrays..

Post by Magnum357 »

Ah, I forgot to point that out, thanks. I'm using VB6 to build the utility, and this link you gave does offer some more detail about Dynamic Arrays then I have had before, but it doesn't seem to give much info on how to do this for Databases.
MjH
Posts: 165
Joined: Wed Feb 22, 2006 11:56 pm

RE: Question about Dynamic Arrays..

Post by MjH »

First a disclaimer: All the coding I have done in the past decade has been in Oracle PL/SQL and Java, so I have no clue about Visual Basic, therefore what I'm proposing may not be the best way to do what you want in VB.

However, I assmume that VB has way of returning a list of rows when executing a query against a database. What I would do would be something like (note, most of the following is psuedo-code, not actual VB syntax):

Code: Select all

   sqlStatement = "SELECT T.ID, T.TeamName FROM Teams T, LeagueDivisions L WHERE T.DivisionId = L.ID ORDER BY L.Name, T.TeamName";
   listOfRows = executeQuery(sqlStatement);
   
   Dim teamNameArray()
   Dim teamIDArray()
   teamSize = 0;
   
   while (listOfRows has another entry) do
     listOfRows.next
 
     ReDim Preserve teamNameArray(teamSize)
     ReDim Preserve teamIDArray(teamSize)
 
     teamNameArray(teamSize) = listOfRows.TeamName
     teamIDArray(teamSize) = listOfRows.ID
     teamSize = teamSize + 1
   end while;
 

You now have two arrays, one with the team names, and one with the team ids. Use the teamNameArray to build your list box, and when the user selects an entry in the list, you can use the index of that team in the teamNameArray to find the ID in the teamIDArray to use in other queries.

Does that help any?
Magnum357
Posts: 613
Joined: Thu Apr 21, 2005 11:07 pm

RE: Question about Dynamic Arrays..

Post by Magnum357 »

Hey, that is quite helpful code. Thanks. I will give it a try and see how it will work out in my program. Now, I just got too think of how too get the loaded TeamName Data to display in the listbox where the Team Indexes are. I think your code above hints at that, but I don't quite understand it.
Antmeister71
Posts: 31
Joined: Wed Mar 01, 2006 3:16 am

RE: Question about Dynamic Arrays..

Post by Antmeister71 »

ORIGINAL: Magnum357

I need some advice by anybody with some Database programming experience. I'm working on a schedule utility program for MaxFB and I'm running into a problem. The utility works ok and can edit a leagues schedule, but my program only displays the Team ID number in a listbox instead of the Teams actual team name.

My problem is that I can't find a way to store the team names from a League Database and then load them into Listbox so they display the Team names and not the Team ID numbers. I was thinking about using a Dyamic Array because since a league Database can have virtually an unlimited amount of Teams in the league, I would need to have an unlimited amount of Varibles to store the there names in. Unless somebody has a better solution, Dynamic Arrays are the only thing I can think of that would allow me to do this. Can anybody give a small example of how too use a Dynamic Array?

Okay, if I am understanding correctly, you want to load the data from an existing database into a listbox, but show and store the data from a specific field in the other database. VB6 should be able to do this. I wish I could remember the correct properties, but look for something along the lines of "Bound" and "Display". These two properties should give you a way to select other fields. What you will be basically doing is treating that table and as look-up table to get the team names. I had been programming in VB and Access for years, but it has been a while since I moved over to online databases such as PHP/mySQL and an open source database application such as Database in OpenOffice.

In other words, an array is not necessary for what you are trying to do.
ALMARKS.COM Master Link Directory
http://www.almarks.com/masterlinks/
Magnum357
Posts: 613
Joined: Thu Apr 21, 2005 11:07 pm

RE: Question about Dynamic Arrays..

Post by Magnum357 »

Hmm... so I really don't need an Array for this at all? I tried looking for "Bounds" in the property lists of Recordsets, but I couldn't find anything like that, maybe I'm looking in the wrong place. You don't mean "UBound" and stuff like that for Arrays right?
Antmeister71
Posts: 31
Joined: Wed Mar 01, 2006 3:16 am

RE: Question about Dynamic Arrays..

Post by Antmeister71 »

ORIGINAL: Magnum357

Hmm... so I really don't need an Array for this at all? I tried looking for "Bounds" in the property lists of Recordsets, but I couldn't find anything like that, maybe I'm looking in the wrong place. You don't mean "UBound" and stuff like that for Arrays right?

I am not sure if the verbage has changed in the past few years, but there should be a property in that list box that allows you to choose which field you want to extract info from which I believe was called "Bound" (at least it was in Access). And there was a another property called Display which allow you to display whatever field you wanted in the same record. Let me go check out info on the net to see if I am just multilating the current verbage.
ALMARKS.COM Master Link Directory
http://www.almarks.com/masterlinks/
Antmeister71
Posts: 31
Joined: Wed Mar 01, 2006 3:16 am

RE: Question about Dynamic Arrays..

Post by Antmeister71 »

Okay, here we go. Geez, I was off with the verbage because I was thinking about the listbox control in the applications I am using now. Here are two properties you can look at that should help you out.

DataField Property
ItemData Property


I provided both because I am not sure how you will create it, but if you read up on these links it does discuss those bound controls. Sorry for confusing the hell out you, but I hope this helps out.

By the way here is the info for the ListBox control here:
http://msdn.microsoft.com/library/defau ... erview.asp

You may or may not be aware of it already, but I just posted the last link just in case.
ALMARKS.COM Master Link Directory
http://www.almarks.com/masterlinks/
Post Reply

Return to “3rd Party Developers Area”