Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 725
  • Last Modified:

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
0
Squeebee
Asked:
Squeebee
  • 3
  • 2
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now