|
-
December 7th, 2000, 10:29 AM
#1
User defined type as a parameter
I want open a new dialog from an other
In a Module is defined:
Type MAMA_MEASURE_COLLISION
lUserId As Long
lStatus As Long
End Type
I want to use this user defined type as a Parmeter in one Public Sub:
Public Sub DoCollisionMessageDlg(msg As MAMA_MEASURE_COLLISION)
End Sub
But I got a Compile error
Stephan
-
December 7th, 2000, 11:48 AM
#2
Re: User defined type as a parameter
Hi, to use UDT as parameter or return value in PUBLIC procedure:
1. Change your project type to ActiveX EXE (or DLL).
To change your project to ActiveX, you'll have to do few things
- add bas module and Sub Main() in it
- in Sub Main() show your startup form
- change your startup object to Sub Main
- set Start mode to Standalone (menu Project, Properties, Component tab)
2. Put your UDT declaration in CLASS module with instancing = 6(GlobalMultiUse)
If your project is Standard EXE, you can pass UDT only if your Sub is Friend:
Friend Sub DoCollisionMessageDlg(msg As MAMA_MEASURE_COLLISION)
'
End Sub
-
December 7th, 2000, 11:53 AM
#3
Re: User defined type as a parameter
>If your project is Standard EXE, you can pass UDT only if your Sub is Friend:
corr.:
If your project is Standard EXE, you can pass UDT only if your Sub is Friend or Private
-
December 8th, 2000, 09:36 AM
#4
Re: User defined type as a parameter
'How to:
'a) Exchange by Val
'b) Exchange by Ref
'c) Exhange an array of Udt by Val
'Here is a way to pass Udt from/to activex (exe or dll) to/from
'standard exe.
'1--------------------------------
'activex.exe code:
'class ClsmyUdt
'the only class of a .exe activex used as a remote component
'instancing = multiuse
'the name of project is PmyRecServer
Option Explicit
Public Type udtRec
nome As String
indice As Integer
arr As Variant
End Type
Public Function passamyudt(ByRef myudt As udtRec) As udtRec
myudt.indice = myudt.indice + 1
passamyudt = myudt
End Function
Public Function passsabyval(ByVal mu As Variant) As Variant
If TypeOf mu Is udtRec Then
mu.indice = mu.indice + 1
Else
'not a udtrect!!
End If
passsabyval = mu
End Function
Public Function passsaArraybyval(ByVal mu As Variant) As Variant
Dim intX As Integer
For intX = 0 To UBound(mu)
If TypeOf mu(intX) Is udtRec Then
mu(intX).indice = mu(intX).indice + 1
Else
'not a udtrect!!
End If
Next intX
passsaArraybyval = mu
End Function
'2--------------------------------
'Standard exe code
'it has ony one form, with all code inside. No bas module required, no 'class required
'Three commadbutton:
'caption:
'a) Exchange by Val
'b) Exchange by Ref
'c) Exhange an array of Udt by Val
Option Explicit
Dim g_aDatiUSFTxt() As Variant
Private myServer As ClsmyUdt
Dim localmyudt As PmyRecServer.udtRec
Private Sub Command1_Click()
localmyudt.indice = localmyudt.indice + 1
Dim tmpvar As Variant
tmpvar = localmyudt
Set myServer = New ClsmyUdt
localmyudt = myServer.passsabyval(tmpvar)
Set myServer = Nothing
With localmyudt
Debug.Print .indice
MsgBox "ByVal, udt.indice = " & .indice
End With
End Sub
Private Sub Command2_Click()
localmyudt.indice = localmyudt.indice + 1
Set myServer = New ClsmyUdt
localmyudt = myServer.passamyudt(localmyudt)
Set myServer = Nothing
With localmyudt
Debug.Print .indice
MsgBox "ByRef, udt.indice = " & .indice
End With
End Sub
Private Sub Command3_Click()
Dim intX As Integer
localmyudt.indice = localmyudt.indice + 1
Dim tmpvar As Variant
tmpvar = Array(localmyudt)
Set myServer = New ClsmyUdt
tmpvar = myServer.passsaArraybyval(tmpvar)
Set myServer = Nothing
For intX = 0 To UBound(tmpvar)
localmyudt = tmpvar(intX)
With localmyudt
Debug.Print .indice
MsgBox "ByVal, udt.indice = " & .indice
End With
Next intX
End Sub
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|