Returning user-defined types from functions in VB6

I am new to VB. I read online that in order to return from a function, you do something as follows:

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 name End Function 

My question is, does this syntax work for user-defined types? If not, then what is the syntax. I tried the following -

 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-> object variable or with block variable not set End Function 

But this gives me an error in the above line - "an object variable or with a non-blocking variable".

What am I doing wrong here?

+4
source share
2 answers

I believe clsDetails is not a UDT, but a class. For variables defined as objects, you need to use the SET keyword. I.e:.

 set getDetails = details 

For more information on using UDT as return values ​​or function parameters, see: Custom Type (UDT) as a parameter in the open Sub in class module (VB6) .

+9
source
 // function definition Public Function add(a, b) Dim c As integer c=Val(a) + Val(b) add=c End Function // function calling x=Text1.Text y=Text2.Text z=add(x, y) MsgBox (z) 
0
source

Source: https://habr.com/ru/post/1413962/


All Articles