473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Duplicating objects on a form?

21
Hello,

I am working with a large game database, which has coordinates for where each NPC is located in the game. I am using Access 2003 to query the database for reference purposes, and am trying to create a visual representation of where each NPC is located on a map image.

I have the code set up to position a single "pin" image on the map at the coordinates it should be. However, I would like to know how I could go about creating a function to either insert a new image into the form (another pin) or clone the existing pin object?

Thanks for the help!
Apr 18 '07 #1
9 1697
Rabbit
12,516 Expert Mod 8TB
You can't do that unless you put the form back into design view. Best you can do is have the controls created but invisble till you need it.
Apr 18 '07 #2
Himmel
21
You can't do that unless you put the form back into design view. Best you can do is have the controls created but invisble till you need it.
Well, the idea is to dynamically place pins after a query. So for example, I search for everyone in "room 1", and there are 5 people. So I want 5 pins to be placed. When I hit "search" a new form is opened to display the image of the room. So having code that modifies the form at a design level should not cause any problems. Or if there is a method to create a dynamic form, that would work too.

I hope I'm making some sort of sense. If the only way is to already have 1000 pin images hidden and just make the ones I need visible, I'm going to cry. :)
Apr 18 '07 #3
ADezii
8,834 Expert 8TB
Well, the idea is to dynamically place pins after a query. So for example, I search for everyone in "room 1", and there are 5 people. So I want 5 pins to be placed. When I hit "search" a new form is opened to display the image of the room. So having code that modifies the form at a design level should not cause any problems. Or if there is a method to create a dynamic form, that would work too.

I hope I'm making some sort of sense. If the only way is to already have 1000 pin images hidden and just make the ones I need visible, I'm going to cry. :)
You can use the CreateForm() Method to create a Form based on an existing Form Template or the Default Form Template. You can also use the CreateControl() Method to dynamically create Controls on an existing Form. Both Methods are covered in the Access Help Files.
Apr 18 '07 #4
Himmel
21
That's the info I was looking for. :)


A new problem though... Is there a way to make Access create more than 878 controls on a form? This is a monster of a game and each area I want to display has at least 1000 NPC's in it.
Apr 19 '07 #5
Himmel
21
Come to think of it, perhaps you could bring your considerable expertise to review this code and let me know if it's optimal. :) This uses some integers that are based specifically on the gaming environment, so some of the static declarations (range, imagemap, worldmap, etc) are set that way for a reason.

Expand|Select|Wrap|Line Numbers
  1. Public Function TemplateForm() As String
  2.  
  3. Dim rst As ADODB.Recordset
  4. Dim ctl As Control
  5. Dim frm As Form
  6. Dim pingx As Long
  7. Dim pingy As Long
  8. Dim stLinkCriteria As String
  9.  
  10. Set frm = CreateForm
  11. Set rst = New ADODB.Recordset
  12.  
  13. frm.InsideWidth = 400
  14. frm.InsideHeight = 400
  15.  
  16.  
  17. frm.NavigationButtons = False
  18. frm.DividingLines = False
  19. frm.ControlBox = False
  20. frm.ScrollBars = 2
  21. frm.RecordSelectors = False
  22. frm.Section(0).BackColor = -2147483633
  23.  
  24. With rst
  25.     .ActiveConnection = CurrentProject.Connection
  26.     .CursorType = adOpenKeyset
  27.     .LockType = adLockOptimistic
  28.     .Open "Select * From QRY_NPC_In_Chunk"
  29.  
  30.     Do Until .EOF
  31. 'Our constants:
  32. 'Range from map 0,0 to top-left corner is...
  33. range = 102395
  34.  
  35. 'The map image is 400px/400px.  A world map is 204790 units.
  36. imagemap = 400.0032
  37. worldmap = 204790
  38.  
  39. 'Worldmap / imagemap = quantifier
  40. q = worldmap / imagemap
  41.  
  42. 'The map ping will be placed at (pingX, pingY), in quips.
  43. ' with 96 pixels to 1 inch, and 1440 quips to 1 inch.
  44. ' Since we have the original pixels and want it in quips,
  45. ' the math is: quips=(inches=(pixels=(range+coord)/96)*1440)
  46. pingx = (((range + !x) / q) / 96) * 1440
  47. pingy = (((range + !y) / q) / 96) * 1440
  48.  
  49.             Set ctl = CreateControl(frm.Name, acImage, , "", "", pingx, pingy, 165, 165)
  50.  
  51.             ctl.SizeMode = 0
  52.             ctl.PictureType = 0
  53.             ctl.BorderStyle = 0
  54.             ctl.Picture = "map-ping.png"
  55.             Set ctl = CreateControl(frm.Name, acLabel, , "", "", pingx, pingy, 165, 165)
  56.             ctl.TextAlign = 2
  57.             ctl.FontWeight = 800
  58.         .MoveNext
  59.     Loop
  60.     .Close
  61. End With
  62.  
  63. Set rst = Nothing
  64. TemplateForm = frm.Name
  65. DoCmd.Close acForm, frm.Name, acSaveYes
  66.  
  67. DoCmd.OpenForm TemplateForm, , , stLinkCriteria
  68.  
  69.  
  70. End Function
  71.  
Apr 19 '07 #6
ADezii
8,834 Expert 8TB
That's the info I was looking for. :)


A new problem though... Is there a way to make Access create more than 878 controls on a form? This is a monster of a game and each area I want to display has at least 1000 NPC's in it.
The maximum number of Controls and Sections you can add over the lifetime of a Form is: 754
Apr 19 '07 #7
ADezii
8,834 Expert 8TB
Come to think of it, perhaps you could bring your considerable expertise to review this code and let me know if it's optimal. :) This uses some integers that are based specifically on the gaming environment, so some of the static declarations (range, imagemap, worldmap, etc) are set that way for a reason.

Expand|Select|Wrap|Line Numbers
  1. Public Function TemplateForm() As String
  2.  
  3. Dim rst As ADODB.Recordset
  4. Dim ctl As Control
  5. Dim frm As Form
  6. Dim pingx As Long
  7. Dim pingy As Long
  8. Dim stLinkCriteria As String
  9.  
  10. Set frm = CreateForm
  11. Set rst = New ADODB.Recordset
  12.  
  13. frm.InsideWidth = 400
  14. frm.InsideHeight = 400
  15.  
  16.  
  17. frm.NavigationButtons = False
  18. frm.DividingLines = False
  19. frm.ControlBox = False
  20. frm.ScrollBars = 2
  21. frm.RecordSelectors = False
  22. frm.Section(0).BackColor = -2147483633
  23.  
  24. With rst
  25.     .ActiveConnection = CurrentProject.Connection
  26.     .CursorType = adOpenKeyset
  27.     .LockType = adLockOptimistic
  28.     .Open "Select * From QRY_NPC_In_Chunk"
  29.  
  30.     Do Until .EOF
  31. 'Our constants:
  32. 'Range from map 0,0 to top-left corner is...
  33. range = 102395
  34.  
  35. 'The map image is 400px/400px.  A world map is 204790 units.
  36. imagemap = 400.0032
  37. worldmap = 204790
  38.  
  39. 'Worldmap / imagemap = quantifier
  40. q = worldmap / imagemap
  41.  
  42. 'The map ping will be placed at (pingX, pingY), in quips.
  43. ' with 96 pixels to 1 inch, and 1440 quips to 1 inch.
  44. ' Since we have the original pixels and want it in quips,
  45. ' the math is: quips=(inches=(pixels=(range+coord)/96)*1440)
  46. pingx = (((range + !x) / q) / 96) * 1440
  47. pingy = (((range + !y) / q) / 96) * 1440
  48.  
  49.             Set ctl = CreateControl(frm.Name, acImage, , "", "", pingx, pingy, 165, 165)
  50.  
  51.             ctl.SizeMode = 0
  52.             ctl.PictureType = 0
  53.             ctl.BorderStyle = 0
  54.             ctl.Picture = "map-ping.png"
  55.             Set ctl = CreateControl(frm.Name, acLabel, , "", "", pingx, pingy, 165, 165)
  56.             ctl.TextAlign = 2
  57.             ctl.FontWeight = 800
  58.         .MoveNext
  59.     Loop
  60.     .Close
  61. End With
  62.  
  63. Set rst = Nothing
  64. TemplateForm = frm.Name
  65. DoCmd.Close acForm, frm.Name, acSaveYes
  66.  
  67. DoCmd.OpenForm TemplateForm, , , stLinkCriteria
  68.  
  69.  
  70. End Function
  71.  
I'll review the code at my earliest convenience.
Apr 19 '07 #8
Himmel
21
The maximum number of Controls and Sections you can add over the lifetime of a Form is: 754
Thanks. I will put a limiter in so it won't keep breaking.
Apr 19 '07 #9
ADezii
8,834 Expert 8TB
Thanks. I will put a limiter in so it won't keep breaking.
I'm hazy on a couple of areas, but the code itself seems solid. It may be a good idea to explicitly declare several Variables such as q, worldmap, and imagemap. Undeclared Variables without Variable declaration turned on can pose a very annoying problem. You refer to quips several times in your Comments, are you referring to Twips (1440/inch)? It seems you biggest problem may be the restriction on the maximum nember of Controls allowed over the lifetime of a Form: 754.
Apr 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
11
by: EdB | last post by:
I'm still having trouble grasping what's going on here and how to resolve it. In VB6 I have a form that has several combo boxes with lots of items in each; it takes a long time to load the form...
15
by: Christopher Benson-Manica | last post by:
Is there a general mechanism to duplicate, or provide for the duplication of, objects? As an example, suppose I need to duplicate an array. I can accomplish this with array.slice( 0 ), but that's...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.