ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fancy Object Declaration (https://www.excelbanter.com/excel-programming/290130-fancy-object-declaration.html)

rci

Fancy Object Declaration
 


Hi all...

I cut my teeth on code with line numbers and goto statements... so all
this newfangled object stuff is mind bending.

Current issue: Trying to be good be explicit object declaration.

My reward for trying to be good by declaring objects explicitly is that in
some cases, where code USED to work (because VBA was smart enough to handle
things without declaration) I now don't, in all cases, know what the heck
object was created...

Example:

MyFunction()

Dim oChart

Set oChart = ChartSpace1.Charts(0)

End Function



....used to be just dandy

....now: Substitute "Best Guess" with many different object types

Public oChart as "Best Guess"
-----------------------------------------------------

MyFunction()

Set oChart = ChartSpace1.Charts(0)

End Function

chokes because my "best guess" as to what the object is suppossed to be is
always wrong.

Type mispatch error.

How do I discover what ChartSpace1.Charts(0) is trying to create? Since VBA
apparently knows what this is... (because it is aware of the mismatch) I
wonder why the Error message fails to say?

Anyway, advice on declaring this properly is very much appreciated.

Thanks,

Mike

rci

Fancy Object Declaration
 
rci wrote:


Belay that...

I discovered the TypeName() method of determining the exact object.

Best regards,

Mike


: Hi all...

: I cut my teeth on code with line numbers and goto statements... so all
: this newfangled object stuff is mind bending.

: Current issue: Trying to be good be explicit object declaration.

: My reward for trying to be good by declaring objects explicitly is that in
: some cases, where code USED to work (because VBA was smart enough to handle
: things without declaration) I now don't, in all cases, know what the heck
: object was created...

: Example:

: MyFunction()

: Dim oChart

: Set oChart = ChartSpace1.Charts(0)

: End Function



: ...used to be just dandy

: ...now: Substitute "Best Guess" with many different object types

: Public oChart as "Best Guess"
: -----------------------------------------------------

: MyFunction()

: Set oChart = ChartSpace1.Charts(0)

: End Function

: chokes because my "best guess" as to what the object is suppossed to be is
: always wrong.

: Type mispatch error.

: How do I discover what ChartSpace1.Charts(0) is trying to create? Since VBA
: apparently knows what this is... (because it is aware of the mismatch) I
: wonder why the Error message fails to say?

: Anyway, advice on declaring this properly is very much appreciated.

: Thanks,

: Mike


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com