title: Returning User defined types from Functions in VB6
body: <p>I am new to VB. I read online that in order to return from a function, you do something as follows -</p>
  
  <pre><code>Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
      Dim Res as integer
      Res = x + y
      Add = Res       ' use the function's name
  End Function
  </code></pre>
  
  <p>My question is, does this syntax also work for user defined types? If not, what is the syntax. I tried the following - </p>
  
  <pre><code>Public Function getDetails() As clsDetails
  
  Dim details As clsDetails
  
  Set details = New clsDetails
  
  With details
     .X = "R"
     .Y = "N"
     .Z = "N"
     ' more code follows
  End With
  
  getDetails = details 'gives error-&gt; object variable or with block variable not set
  
  End Function
  </code></pre>
  
  <p>But this gives me an error on the above line - "object variable or with block variable not set".</p>
  
  <p>What am I doing wrong here?</p>