473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I determine if a control has a specific property

I'm looping through controls on my form and grabbing the TabIndex off
each one, but when it hits a control w/out a TabIndex (like a timer) it
crashes. So, how do i check to see if the current control has a
specific property?
Thanks

Apr 12 '06 #1
9 4246
"rmiller" <Cu*************@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
I'm looping through controls on my form and grabbing the TabIndex off
each one, but when it hits a control w/out a TabIndex (like a timer) it
crashes. So, how do i check to see if the current control has a
specific property?
Thanks


The very easiest and most straight forward way is to add error handling. The
app's not crashing, it's hitting a point that needs your attention. When it
fails to get the attention it deserves, then, it crashes.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Apr 12 '06 #2
Thanks Ken. The issue occurs in a for loop. Got an example of how to
handle this error
Ryan

Apr 12 '06 #3
"rmiller" <Cu*************@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Thanks Ken. The issue occurs in a for loop. Got an example of how to
handle this error
Ryan


Uh oh <g> In dotNetish? Not really <g> This is converted from VB6. No
Try/Catch stuff (no "real" dotNet experience here).

The first one ignores all errors raised from accessing an invalid property..
if all you're doing is checking tab indexes, that may be all you'd need. The
second has a "trap" that shows a box if the error is anything other than the
one we're trying to trap. (there seems to be so much more typing involved in
dotNet, it's nuts)
'==========
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim c As System.Windows.Forms.Control
Dim i As Short

On Error Resume Next

For Each c In Me.Controls
i = c.TabStop 'this is enough to raise the error
'Here you can check for Err.Number <> 0 if you want.
Next c

Err.Clear()
End Sub

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command2.Click
Dim c As System.Windows.Forms.Control
Dim i As Short

On Error GoTo ErrorTrap

For Each c In Me.Controls
i = c.TabStop 'this is enough to raise the error
Next c

Terminate:
Exit Sub

ErrorTrap:
If Err.Number = 438 Then
Resume Next
Else
MsgBox("Error " & Err.Number)
Resume Terminate
End If
End Sub
'==========

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Apr 12 '06 #4
Hmmm...something's still not right. Here's the code:

If KeyCode = 9 Then
Set curCtl = Me.ActiveControl
If Not (curCtl Is Nothing) Then
curTabIndex = curCtl.TabIndex
For Each ctl In Me.Controls
If Not (ctl Is curCtl) Then
If ctl.TabIndex = (curTabIndex + 1) Then ///Here's
where the error pops up
ctl.SetFocus
Exit Sub
End If
End If
Next
End If
End If

As you can see i need to go to the next ctl not ignore the error and
move to the next line.

Apr 12 '06 #5
Hmmm...something's still not right. Here's the code:

If KeyCode = 9 Then
Set curCtl = Me.ActiveControl
If Not (curCtl Is Nothing) Then
curTabIndex = curCtl.TabIndex
For Each ctl In Me.Controls
If Not (ctl Is curCtl) Then
If ctl.TabIndex = (curTabIndex + 1) Then ///Here's
where the error pops up
ctl.SetFocus
Exit Sub
End If
End If
Next
End If
End If

As you can see i need to go to the next ctl not ignore the error and
move to the next line.

Apr 12 '06 #6
Hmmm...something's still not right. Here's the code:

If KeyCode = 9 Then
Set curCtl = Me.ActiveControl
If Not (curCtl Is Nothing) Then
curTabIndex = curCtl.TabIndex
For Each ctl In Me.Controls
If Not (ctl Is curCtl) Then
If ctl.TabIndex = (curTabIndex + 1) Then ///Here's
where the error pops up
ctl.SetFocus
Exit Sub
End If
End If
Next
End If
End If

As you can see i need to go to the next ctl not ignore the error and
move to the next line.

Apr 12 '06 #7
rMiller,

A timer is not a control (It is sad that some from Microsoft have used
Control for every Component that could be placed in the toolbox).

Control are class from Forms and WebUI

This is the 1.x list from forms
http://msdn.microsoft.com/library/de...shierarchy.asp

Tabindex is a member of control, so it will always be in a derived control
(although it can be overridden in a way that it does nothing)

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore there should not be any problem if you are looping through a
control collection if it is about TabIndex.

It is something else with things as selectedindex which are part of the
derived classes as ListControl, therefore I check this almost forever. There
where a for will be used is mostly needed to check if it is value or text
that has to be set.

I hope this helps,

Cor


"rmiller" <Cu*************@gmail.com> schreef in bericht
news:11*********************@v46g2000cwv.googlegro ups.com...
I'm looping through controls on my form and grabbing the TabIndex off
each one, but when it hits a control w/out a TabIndex (like a timer) it
crashes. So, how do i check to see if the current control has a
specific property?
Thanks

Apr 13 '06 #8
Well, control or not. When i loop through the controls it thinks it is
one. To solve the problem I broke it by first setting the newTabIndex
to -1 then setting it to the next controls TabIndex. If this control
doesn't have a TabIndex it errors, but resumes next and the newTabIndex
remains -1. I then do a check for the -1 value and proceed if it isn't.

On Error Resume Next
Dim ctl As Control
Dim curCtl As Control
Dim curTabIndex As Integer
Dim newTabIndex As Integer

If KeyCode = 9 Then
Set curCtl = Screen.ActiveControl
If Not (curCtl Is Nothing) Then
curTabIndex = curCtl.TabIndex
For Each ctl In Screen.ActiveForm.Controls
If Not (ctl Is curCtl) Then
newTabIndex = -1
newTabIndex = ctl.TabIndex
If newTabIndex <> -1 And newTabIndex = (curTabIndex
+ 1) Then
ctl.SetFocus
Exit Sub
End If
End If
Next
End If
End If

Apr 13 '06 #9
Well, control or not. When i loop through the controls it thinks it is
one. To solve the problem I broke it by first setting the newTabIndex
to -1 then setting it to the next controls TabIndex. If this control
doesn't have a TabIndex it errors, but resumes next and the newTabIndex
remains -1. I then do a check for the -1 value and proceed if it isn't.

On Error Resume Next
Dim ctl As Control
Dim curCtl As Control
Dim curTabIndex As Integer
Dim newTabIndex As Integer

If KeyCode = 9 Then
Set curCtl = Screen.ActiveControl
If Not (curCtl Is Nothing) Then
curTabIndex = curCtl.TabIndex
For Each ctl In Screen.ActiveForm.Controls
If Not (ctl Is curCtl) Then
newTabIndex = -1
newTabIndex = ctl.TabIndex
If newTabIndex <> -1 And newTabIndex = (curTabIndex
+ 1) Then
ctl.SetFocus
Exit Sub
End If
End If
Next
End If
End If

Apr 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2851
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
2
9478
by: CJack | last post by:
hi, i have a window form with different controls. i want to loop through all the controls and write the types and lables of each control in a file. I dnt know how to determine the type of a control...
1
7691
by: mdb | last post by:
I want to determine whether the SHIFT key is depressed, but NOT during a key up/down/pressed event. How can I do that?
2
7618
by: Ben Dilts | last post by:
Using VB.NET, is there a way to determine if the Shift key is down (or the Control key, etc.)? ~BenDilts( void );
4
2493
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
5
2792
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
4
4492
by: ABC | last post by:
I want to check the form's controls have or not the specific properties or events. How to determine or gather the properties list under the run-time environment?
3
11560
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the...
10
43489
by: John Brown | last post by:
Hi there, Does anyone know how to (generically) determine the currently active form for an application using a "static" function (so I can call it from anywhere). There is no offiical way I've...
0
7260
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
7384
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,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5685
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,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
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...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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.