Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VB6 to VBA conversion. Form vs. UserForm differences. Object variable types

Hi,

I'm converting some VB6 forms and classes to run in VBA. Having some real
trouble with converting forms in general and the class modules behind the
forms. Below is a highly simplified example of the trouble - basically
a "Type Mismatch" situation.

I've been doing a ton of F8'ing and looking at both the Locals Window and
the Watches window to try to see why there is a mismatch. Also fooled
around with:

varname1 Is varname2 [tests if both point to same object]
IsObject(identifier) [simple true/false]
TypeName(varname) [returns the type name of the variable, "object" if
object.]

In VB you Dim as Form
In VBA you Dim as userForm or "the-actual-name-of-the-form-class"

Before I throw in the towel and just go with a generic "object" type take a
look at this and see if you can point the way out. (example below)

Any additional info on VBA vs. VB (Forms vs. UserForms) would be greatly
appreciated. I'm new to class modules and event processing and its been a
steep learning curve. Any other great references, books, tutorials very
much appreciated.

Yes, after I "down grade" the code from VB6 to VBA (Office 2000) I need to
upgrade it to VB.NET. Fun!

THANKS!!!

Rick


[create a new form with one ListBox1 on it]

Private i As Integer
Private m_listBox1 As ListBox '<=== why doesn't this work?
'Returns run time error 13 type mismatch???
'Private m_listBox1 As Object '<=== yet this does

Private Sub UserForm_Initialize()
i = 0
Set m_listBox1 = Me.ListBox1
End Sub

Private Sub UserForm_Click()
i = i + 1
m_listBox1.AddItem (i)
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VB6 to VBA conversion. Form vs. UserForm differences. Object variable types

Rick,

In Excel/VBA there are two distinct objects named ListBox. The
first is in the Excel typelib is the list box that is available
on the Forms command bar. The second is in the MSForms typelib,
and it the one you use on UserForms. Because the Excel typelib
has a higher priority in the compiler than the MSForms typelib,
the compiler uses Excel's ListBox. You need to qualify ListBox
with the name of the typelib in which it resides.

Change

Private m_listBox1 As ListBox
to
Private m_listBox1 As MSForms.ListBox

Using 'As Object' works because Object can hold any sort of
object, and the assignment is made at run time, not compile time.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Rick Labs" wrote in message
om...
Hi,

I'm converting some VB6 forms and classes to run in VBA. Having

some real
trouble with converting forms in general and the class modules

behind the
forms. Below is a highly simplified example of the trouble -

basically
a "Type Mismatch" situation.

I've been doing a ton of F8'ing and looking at both the Locals

Window and
the Watches window to try to see why there is a mismatch. Also

fooled
around with:

varname1 Is varname2 [tests if both point to same object]
IsObject(identifier) [simple true/false]
TypeName(varname) [returns the type name of the variable,

"object" if
object.]

In VB you Dim as Form
In VBA you Dim as userForm or

"the-actual-name-of-the-form-class"

Before I throw in the towel and just go with a generic "object"

type take a
look at this and see if you can point the way out. (example

below)

Any additional info on VBA vs. VB (Forms vs. UserForms) would

be greatly
appreciated. I'm new to class modules and event processing and

its been a
steep learning curve. Any other great references, books,

tutorials very
much appreciated.

Yes, after I "down grade" the code from VB6 to VBA (Office

2000) I need to
upgrade it to VB.NET. Fun!

THANKS!!!

Rick


[create a new form with one ListBox1 on it]

Private i As Integer
Private m_listBox1 As ListBox '<=== why doesn't this work?
'Returns run time error 13 type mismatch???
'Private m_listBox1 As Object '<=== yet this does

Private Sub UserForm_Initialize()
i = 0
Set m_listBox1 = Me.ListBox1
End Sub

Private Sub UserForm_Click()
i = i + 1
m_listBox1.AddItem (i)
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VB6 to VBA conversion. Form vs. UserForm differences. Object variable types

Chip,

Thanks very much for clearing up the difference between:

Private m_listBox1 As MSForms.ListBox 'newer activeX control
'vs.
Private m_listBox1 As ListBox 'old Excel control
'and the same for textbox

Was just wondering if there was any way I could have chased down your
solution myself with standard VBA tools? I only had the "type mismatch"
error clue and despite considerable effort I could not "discover" your
solution on my own.

A programmer friend of mind strongly suggested that I bag VBA entirely and
just write stuff in VB and control Excel from there. He insisted that the VB
development environment would be much better to chase down this type of
object referencing/scoping/visibility challenge. Is that true? If so, what
specific tool(s) in VB would you recommend looking at? Perhaps it is time to
break free of VBA.

Another C++ friend recommends that I get some software that will show me
inter window communications (messages) just to get a feel for that. Nothing
too deep, just a feel. I have a tiny exposure to these already. It's mind
boggling.

I assume most API calls from VB6/VBA will be different than from VB.net.
Other than the few VB6/VBA API calls I use currently I'll probably just stop
learning anything at the VB6/VBA level and move up to VB.Net/Foundation
Classes. Ultimately everything I do will have to go to VB.Net and Excel. Do
you see any point in doing things first in VB6 then moving up to VB.NET?

Thanks again.

Rick



"Chip Pearson" wrote in message
...
Rick,

In Excel/VBA there are two distinct objects named ListBox. The
first is in the Excel typelib is the list box that is available
on the Forms command bar. The second is in the MSForms typelib,
and it the one you use on UserForms. Because the Excel typelib
has a higher priority in the compiler than the MSForms typelib,
the compiler uses Excel's ListBox. You need to qualify ListBox
with the name of the typelib in which it resides.

Change

Private m_listBox1 As ListBox
to
Private m_listBox1 As MSForms.ListBox

Using 'As Object' works because Object can hold any sort of
object, and the assignment is made at run time, not compile time.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Rick Labs" wrote in message
om...
Hi,

I'm converting some VB6 forms and classes to run in VBA. Having

some real
trouble with converting forms in general and the class modules

behind the
forms. Below is a highly simplified example of the trouble -

basically
a "Type Mismatch" situation.

I've been doing a ton of F8'ing and looking at both the Locals

Window and
the Watches window to try to see why there is a mismatch. Also

fooled
around with:

varname1 Is varname2 [tests if both point to same object]
IsObject(identifier) [simple true/false]
TypeName(varname) [returns the type name of the variable,

"object" if
object.]

In VB you Dim as Form
In VBA you Dim as userForm or

"the-actual-name-of-the-form-class"

Before I throw in the towel and just go with a generic "object"

type take a
look at this and see if you can point the way out. (example

below)

Any additional info on VBA vs. VB (Forms vs. UserForms) would

be greatly
appreciated. I'm new to class modules and event processing and

its been a
steep learning curve. Any other great references, books,

tutorials very
much appreciated.

Yes, after I "down grade" the code from VB6 to VBA (Office

2000) I need to
upgrade it to VB.NET. Fun!

THANKS!!!

Rick


[create a new form with one ListBox1 on it]

Private i As Integer
Private m_listBox1 As ListBox '<=== why doesn't this work?
'Returns run time error 13 type mismatch???
'Private m_listBox1 As Object '<=== yet this does

Private Sub UserForm_Initialize()
i = 0
Set m_listBox1 = Me.ListBox1
End Sub

Private Sub UserForm_Click()
i = i + 1
m_listBox1.AddItem (i)
End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


All times are GMT +1. The time now is 09:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"