Solved

VB 4.0 - Creating Objects on the Fly

Posted on 1997-08-05
3
156 Views
Last Modified: 2012-05-04
I have a situation where I want to create a releated object for each database record I read in. Basically I want to create probably a picture box or image for each record read in. Each record may have an associated BMP.

In reading the records from the table I want to create an object for each an load this onto the form. The will have to be moveable as I want to be able to drag & Drop these into a certain position.

I will give you an example.  I have a sports Database where there are teams entered.  For each round in the competition I want the user to be able to associate the teams playing each other. I want to create an object for each team on the right part of the form then associated Home & Away playing team in the left part of the form.

Thanks in Advance
0
Comment
Question by:trevorm
3 Comments
 
LVL 3

Expert Comment

by:dansari
ID: 1429762
trevorm:

Why don't you store the X and Y coordinates (Left and Top properties) of each picture box control in the database?  In the Form_Unload event (or using a Save button, or something), you can save the values.

If the number of players and teams is fixed, then you can create the picture box controls at design time; otherwise, you can use control arrays.

Hope this helps.
0
 

Accepted Solution

by:
hfanan earned 200 total points
ID: 1429763
I faced this problem before with Edit Box but the solution is the same for picture boxes.
Define a control array of picture boxes. Let its name be "P"
To create a new control dynamically use the Load command.
For example Load P(i) where i is the index of the array.
To remove the control from memry, use the UnLoad command
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1429764
Here's another trick.  Make your data structures do the work.  Put the file name of the bmp, or the icon name if using an image list, in your records.  That way when you read the record, it defines its own image.  Then if you want to change images, just refile another .bmp under the same file name on your drive.


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 85
VBA filters 2 67
Help me. 3 60
Export Data to Different .csv Files 26 115
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question