Passing User Defined type to Sub produces "Variable Required - can't assign to this expression" Error

Here's the code

Private Type Customer
    Name As String
    Address As String
    Spending As Single
End Type



Private Sub Form_Load()
    Dim myCustomer As Customer
   
    myCustomer.Name = "Johnny Boy"
    myCustomer.Address = "123 Main Street"
    myCustomer.Spending = 54000.3695

    showCustomer (myCustomer)
   
End Sub

Private Sub showCustomer(ByRef cust As Customer)
    txtname = cust.Name
    txtaddress = cust.Address
    txtspending = cust.Spending
End Sub
LVL 17
SqueebeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SkirdeCommented:
You could use a class module to act as your custom data type then pass the class module.  

---- in the class mod names clsMyObject.cls ---
public Name as string
public Address as String
public Spending as Single

---- in your form or basic modules ----
  dim oMyObject as clsMyObject

'--- create an instance of my custom typs
  set oMyObject as new clsMyObject

'--- put some data in your object
  oMyObject.Name = "Tester J. Test"
  oMyObject.Address = "123 Fake St."

'--- pass it along
  Call showCustomer(oMyObject)

---- in the mod you want to pass the custom object to

private sub showCustomer(byref oTemp as clsMyObjext)

'--- use the data from the custom object.
  txtname.text = oTemp.Name

end sub

There is a bunch of info on this in the MSDN ... search for "Sharing coffee" ... there are about 3 or 4 related articles about this.

hope it helps.


0
SqueebeeAuthor Commented:
I know I can use a class, but i am trying to get user defined types working.

Mike
0
SqueebeeAuthor Commented:
I know I can use a class, but i am trying to get user defined types working.

Mike
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RobMeCommented:
This will work if you change your line:

showCustomer (myCustomer)

to:

Call showCustomer(myCustomer)

You always have to use 'Call' when you use sub-routines, as these are different from functions that produce a value.

Hope you get it to work!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SqueebeeAuthor Commented:
Thank you very much. What i would not do for a more descriptive error message.

Mike
0
RobMeCommented:
They are great aren't they! ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.