Question about Dynamic Arrays.. (Full Version)

All Forums >> [Current Games From Matrix.] >> [Sports] >> Maximum-Football 2.0 >> 3rd Party Developers Area



Message


Magnum357 -> Question about Dynamic Arrays.. (4/14/2006 3:34:37 AM)

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 -> RE: Question about Dynamic Arrays.. (4/14/2006 4:23:42 AM)

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/scriptcenter/guide/sas_vbs_hbsi.mspx?mfr=true

If you're using VBScript, then that appears to be a pretty straight-forward example.




Magnum357 -> RE: Question about Dynamic Arrays.. (4/14/2006 2:49:33 PM)

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 -> RE: Question about Dynamic Arrays.. (4/14/2006 4:04:35 PM)

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):

  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 -> RE: Question about Dynamic Arrays.. (4/15/2006 2:25:09 AM)

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 -> RE: Question about Dynamic Arrays.. (4/15/2006 5:06:59 AM)

quote:

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.




Magnum357 -> RE: Question about Dynamic Arrays.. (4/15/2006 7:54:04 AM)

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 -> RE: Question about Dynamic Arrays.. (4/15/2006 9:22:36 AM)

quote:

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.




Antmeister71 -> RE: Question about Dynamic Arrays.. (4/15/2006 10:58:16 AM)

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/default.asp?url=/library/en-us/VBRef98/html/vbmscLROverview.asp

You may or may not be aware of it already, but I just posted the last link just in case.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
2.203125