473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can a reference a control Programmatically

106 New Member
Hi,

I am opening a recordset to read booking times, converting them to twips and storing them in array to display some boxes that represent a timescale.
My current method used below, will display just six boxes.

How can i adapt this to display any number of boxes and of course, reduce the coding. (of course, I could continue to use my method, but not favourable)

I am wondering if I could use some kind of control method to reference the Boxes in this manner:
Expand|Select|Wrap|Line Numbers
  1. "BOX" & A = .....
  2.  
Expand|Select|Wrap|Line Numbers
  1.     For A = 1 To NoofBookings
  2.     'MsgBox TimeSlot(A, 0) & " " & TimeSlot(A, 1) & " " & TimeSlot(A, 2) & " " & TimeSlot(A, 3)
  3.     Select Case A
  4.         Case 1
  5.             box1.Visible = True
  6.             box1.Left = ((((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9) * 2) + LeftPos)) * tw
  7.             box1.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  8.             box1.Caption = TimeReg(A)
  9.  
  10.         Case 2
  11.             Box2.Visible = True
  12.             Box2.Left = ((((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9) * 2) + LeftPos)) * tw
  13.             Box2.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  14.             Box2.Caption = TimeReg(A)
  15.  
  16.         Case 3
  17.             Box3.Visible = True
  18.             Box3.Left = ((((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9) * 2) + LeftPos)) * tw
  19.             Box3.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  20.             Box3.Caption = TimeReg(A)
  21.  
  22.         Case 4
  23.             Box4.Visible = True
  24.             Box4.Left = ((((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9) * 2) + LeftPos)) * tw
  25.             Box4.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  26.             Box4.Caption = TimeReg(A)
  27.  
  28.         Case 5
  29.             Box5.Visible = True
  30.             Box5.Left = ((((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9) * 2) + LeftPos)) * tw
  31.             Box5.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  32.             Box5.Caption = TimeReg(A)
  33.  
  34.         Case 6
  35.             Box6.Visible = True
  36.             Box6.Left = ((TimeSlot(A, 0) + (TimeSlot(A, 1) / 60) - 9 + LeftPos)) * tw
  37.             Box6.Width = ((TimeSlot(A, 2) + (TimeSlot(A, 3) / 60))) * tw * 2
  38.             Box6.Caption = TimeReg(A)
  39.  
  40.         End Select
  41.         Next A
  42.  
Aug 28 '10 #1
1 1788
ADezii
8,834 Recognized Expert Expert
Let's assume that you have 10 Text Boxes sequentially numbered Box1 thru Box10. The general Logic for accessing the Properties of these Text Boxes within a single Loop wouold be:
Expand|Select|Wrap|Line Numbers
  1. Dim TBox As TextBox
  2. Dim intBoxCtr As Integer
  3.  
  4. For intBoxCtr = 1 To 10
  5.   Set TBox = Me.Controls("Box" & CStr(intBoxCtr))
  6.     TBox.BackColor = QBColor(intBoxCtr)
  7. Next
As a side note:
  1. Converting Booking Times to Twips (1/1,440 in.) makes absolutely no sense to me.
  2. Boxes do not have a Caption Property, and attempting to assign one will generate a Runtime Error.
Aug 28 '10 #2

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

Similar topics

1
6469
by: Shravan | last post by:
Hi , I have a datetimepicker in my application. I am dropping it down (showing calendar control). When the drop down window (calendar control) is visible how can I programmatically closeup the...
0
983
by: Alex | last post by:
I'm trying to output a webcontrol in a non-standard way. What I want, is the page to output xml with the html from the webcontrol in a CDATA element of the XML document. My code looks something...
10
1609
by: fripper | last post by:
I have a VB .Net web app and I want to reposition a textbox control on the webform programmatically. I'm not sure how to do that ... can someone help please? Thanks ...
3
1939
by: Paul | last post by:
I am using Visual Studio.net 2005 (and asp.net 2.0) Let's say that in a Web Project, I have created a (Dataset?) called SomeDataset.xsd. On it I have a TableAdapter called SomeTableTableAdapter...
1
1176
by: Sharon | last post by:
Hi all, I'm trying to programmatically render a user control, but problem is, i don't have the control type and i cannot use register directive as the context is not an aspx page. Any ideas,...
2
1321
by: johnb41 | last post by:
I want to create a textbox programmatically and add the SAME textbox to to different panels. This code does not work: Dim tb As New TextBox tb.text = "xyz" Panel1.Controls.Add(tb)...
0
3465
by: Michel Couche | last post by:
Hello, I would like to programmatically set the visibility of a selectedWizardStep after clicking on a button contained in an other one. I found the following in an article from D. Esposito...
2
6956
by: R.A.F. | last post by:
Hi, 2 Days ago i wrote a post about "how to add programmatically custom control on Toolbox". I'm still blocked with this issue. Is there someone who did it under C#.NET 2005 and 2008 ? ...
3
2734
by: =?Utf-8?B?QW5nZWw=?= | last post by:
I seem to understand how the control works as long as I mated to SqlDataSource or ObjDataSource it works fine. But I do not want to flatten my design in this manner. I am interested in how I can...
13
1661
by: Just_a_fan | last post by:
I am adding a bunch of controls with the code below. Problem 1: When program flow passes to "UpperChanged" when I click it, the control name is undefined. When I enter: If udUpperLim1.Value 1...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
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
7229
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...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.