Hi there.
Sorry if this is long winded. I am relatively new to programming and have managed so far with google and a lot of patience! I am having a problem naming timer contols at runtime. This is what I am trying to achieve.
1. I connect to my dataset and to my first record
2. I create a loop for the recordset
3. I create various objects on a form and name them using the info in the dataset
I also need to create timers and name them using the first field of my dataset. It needs to be dynamic as its database driven. There could be as many as 100 timers at any one point.
I can use the Button.name = "myname" fine for most controls
but doing a Timer.name does not work
This is some of my code (some variable values not shown):
'Counter to move through the database Dataset
Dim RecordsCount As Integer
RecordsCount = ManagerDataSet. Robots.Count
'Declare name incremented with record number to make it unique
Dim btnSSName(Recor dsCount) As Button
For myLoop = 0 To (RecordsCount - 1)
'Create a button
btnSSName(myLoo p) = New Button()
btnSSName(myLoo p).Location = New Drawing.Point(b tnSSPosVer, lblposHoz) 'lblposVer, ProgBarPosHoz)
btnSSName(myLoo p).Name = "btnSS" + currentRobot
btnSSName(myLoo p).Text = currentRobot
btnSSName(myLoo p).Width = 70
btnSSName(myLoo p).Height = 23
btnSSName(myLoo p).BackColor = Color.Red
btnSSName(myLoo p).ForeColor = Color.White
TabControl1.Tab Pages(0).Contro ls.Add(btnSSNam e(myLoop))
next myLoop
That all works great for populating objects on the form.
When I create a timer in a similar way:
Dim tmr(RecordsCoun t) As Timer
tmr(myLoop) = New Timer
tmr(myLoop).Int erval = whatevermydatas etrecordis
tmr(myLoop).Nam e = "myuniquena me"
AddHandler tmr(myLoop).Tic k, AddressOf hndlifespan
*****The Problem ******
Using . .
tmr(myLoop).Nam e = "myuniquena me"
I get a error of 'Name' is not a member of 'System.Windows .Forms.Timer'
When one of my dynamicly created buttons is pressed it goes to the dynamically created button click handler. This in turn knows which button was pressed by asking its name. At this point I want to launch a specific timer based on the button name.
So if the button "Alpha" was pressed I want to enable the "Alpha" timer (that was created dynamically from the dataset with its associated interval).
I have created a timer at design time which does this:
Friend WithEvents billy As System.Windows. Forms.Timer
Me.billy = New System.Windows. Forms.Timer(Me. components)
If I do the same
Dim billy As Timer
billy = New Timer
The timer is stuck with the name "billy" still and I am unable to change it.
I wish to name the timer with a name that is held in a string. At the moment I acn see that
Dim myString As Timer
can not work as It is an assigned string
so
Dim tmr(CInt(myStri ng)) As Timer
tmr(CInt(myStri ngt)) = New Timer
AddHandler tmr(CInt(myStri ng)).Tick, AddressOf hndlifespan
does not flag errors in intellisense but I have no idea why it asked me to convert my string into an Integer and if it will work.
I am burned out and lost !!!!!!!!
Many thanks and sorry if I made your head hurt!
Paul
Sorry if this is long winded. I am relatively new to programming and have managed so far with google and a lot of patience! I am having a problem naming timer contols at runtime. This is what I am trying to achieve.
1. I connect to my dataset and to my first record
2. I create a loop for the recordset
3. I create various objects on a form and name them using the info in the dataset
I also need to create timers and name them using the first field of my dataset. It needs to be dynamic as its database driven. There could be as many as 100 timers at any one point.
I can use the Button.name = "myname" fine for most controls
but doing a Timer.name does not work
This is some of my code (some variable values not shown):
'Counter to move through the database Dataset
Dim RecordsCount As Integer
RecordsCount = ManagerDataSet. Robots.Count
'Declare name incremented with record number to make it unique
Dim btnSSName(Recor dsCount) As Button
For myLoop = 0 To (RecordsCount - 1)
'Create a button
btnSSName(myLoo p) = New Button()
btnSSName(myLoo p).Location = New Drawing.Point(b tnSSPosVer, lblposHoz) 'lblposVer, ProgBarPosHoz)
btnSSName(myLoo p).Name = "btnSS" + currentRobot
btnSSName(myLoo p).Text = currentRobot
btnSSName(myLoo p).Width = 70
btnSSName(myLoo p).Height = 23
btnSSName(myLoo p).BackColor = Color.Red
btnSSName(myLoo p).ForeColor = Color.White
TabControl1.Tab Pages(0).Contro ls.Add(btnSSNam e(myLoop))
next myLoop
That all works great for populating objects on the form.
When I create a timer in a similar way:
Dim tmr(RecordsCoun t) As Timer
tmr(myLoop) = New Timer
tmr(myLoop).Int erval = whatevermydatas etrecordis
tmr(myLoop).Nam e = "myuniquena me"
AddHandler tmr(myLoop).Tic k, AddressOf hndlifespan
*****The Problem ******
Using . .
tmr(myLoop).Nam e = "myuniquena me"
I get a error of 'Name' is not a member of 'System.Windows .Forms.Timer'
When one of my dynamicly created buttons is pressed it goes to the dynamically created button click handler. This in turn knows which button was pressed by asking its name. At this point I want to launch a specific timer based on the button name.
So if the button "Alpha" was pressed I want to enable the "Alpha" timer (that was created dynamically from the dataset with its associated interval).
I have created a timer at design time which does this:
Friend WithEvents billy As System.Windows. Forms.Timer
Me.billy = New System.Windows. Forms.Timer(Me. components)
If I do the same
Dim billy As Timer
billy = New Timer
The timer is stuck with the name "billy" still and I am unable to change it.
I wish to name the timer with a name that is held in a string. At the moment I acn see that
Dim myString As Timer
can not work as It is an assigned string
so
Dim tmr(CInt(myStri ng)) As Timer
tmr(CInt(myStri ngt)) = New Timer
AddHandler tmr(CInt(myStri ng)).Tick, AddressOf hndlifespan
does not flag errors in intellisense but I have no idea why it asked me to convert my string into an Integer and if it will work.
I am burned out and lost !!!!!!!!
Many thanks and sorry if I made your head hurt!
Paul
Comment