?
Solved

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

Posted on 2003-03-13
6
Medium Priority
?
625 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:Squeebee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Expert Comment

by:Skirde
ID: 8131358
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
 
LVL 17

Author Comment

by:Squeebee
ID: 8131375
I know I can use a class, but i am trying to get user defined types working.

Mike
0
 
LVL 17

Author Comment

by:Squeebee
ID: 8131407
I know I can use a class, but i am trying to get user defined types working.

Mike
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Accepted Solution

by:
RobMe earned 200 total points
ID: 8131554
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
 
LVL 17

Author Comment

by:Squeebee
ID: 8131592
Thank you very much. What i would not do for a more descriptive error message.

Mike
0
 

Expert Comment

by:RobMe
ID: 8132105
They are great aren't they! ;)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question