View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rick Labs Rick Labs is offline
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