Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if control property exists? 1

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
Is there a way to check if a control has a certain property?

I'm going to need to enumerate all the controls in an application to change the font properties, and I need to ensure that they all have .font.propertyname so I don't run into any errors.

I would simply just use SendMessage with WM_SETFONT (I think that's the message, not sure without looking), but of course certain controls don't have hWnd properties, so that won't work either.

Perhaps there's an easier way to do an application wide font change?

Any help or ideas would be greatly appreciated. Thanks in advance.
 
You will propbably loop thru controls, so you could wrap your loop this way:
Code:
On Error Resume Next

.... your loop here

On Error GoTo 0
This way when you try to access property that does not exist, you will simply ignore it and keep on going.

On Error GoTo 0 will get you back to the previous way of dealing with Errors.

HTH

---- Andy
 
... On Error GoTo 0 will get you back to the previous way of dealing with Errors.

Only if the "previous way" was no error trapping. On Error GoTo 0 turns off error trapping.

For example
Code:
On Error GoTo ErrorTrap [COLOR=black cyan]' Trapping Errors[/color]

On Error Resume Next    [COLOR=black cyan]' Ignoring Errors[/color]

On Error GoTo 0         [COLOR=black cyan]' Error Trapping Turned Off[/color]

On Error GoTo ErrorTrap [COLOR=black cyan]' Trapping Errors Again[/color]
 
So, what you are saying, Golom, is:
Code:
On Error GoTo MyErrorHandler

    ....some code here

On Error Resume Next
    .... your loop here
[green]'On Error GoTo 0[/green]
On Error GoTo MyErrorHandler

    ... more code here

Exit Sub
MyErrorHandler:
    ... deal with errors here

I guess I learn something new every day.
Or have my mistakes corrected :)

Good to know this.

Thanks

---- Andy
 
Just to elaborate a bit ...

When I said that On Error GoTo 0 turns off error trapping, I should have added "... in the procedure where it appears."

Error trapping will still happen but any errors will bubble up the call stack until they find an active error handler. That's why you will see errors being processed in a procedure's error handler when the actual source of the error was in some completely different procedure lower down in the call stack.

If no active error handler is found then the application raises an error to the user and terminates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top