Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Variable List Arguments

views
     
TSAthono
post Mar 1 2006, 09:33 PM, updated 20y ago

Getting Started
**
Junior Member
227 posts

Joined: Dec 2005
I have pretty much figured out how to pass variables to and from VB and C++ programs. Now I need to do the same for Variable List Arguments (where you have those elipses... in the argument list.

This seems to be a whole lot trickier and takes things to another level of complexity.

Does anyone have any ideas?

Variable List Arguments are described here:
http://msdn.microsoft.com/library/default....c_.va_start.asp

In C you can declare a function like this
int average( int first, ... )
Where the ellipses denote a variable argument list.
If I have a function like that in a c++ DLL and I want to link a Visual Basic GUI to it, how would that function be declared in the Visual Basic program?

The Visual Basic 6 text I have talks about something called Optional Variant but it looks like it will only apply for one variable and not a list of unknown variables.


This post has been edited by Athono: Mar 2 2006, 01:07 AM
nxfx
post Mar 2 2006, 08:59 AM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


I think you have to so something like this

Private Declare Function YourFunction "YourDLL.dll" (ByVal x As String) As Long

anthony_yio
post Mar 2 2006, 07:44 PM

........
Group Icon
Elite
1,828 posts

Joined: Jan 2003


QUOTE(Athono @ Mar 1 2006, 09:33 PM)
I have pretty much figured out how to pass variables to and from VB and C++ programs.  Now I need to do the same for Variable List Arguments (where you have those elipses... in the argument list.

This seems to be a whole lot trickier and takes things to another level of complexity.

Does anyone have any ideas?

Variable List Arguments are described here:
http://msdn.microsoft.com/library/default....c_.va_start.asp

In C you can declare a function like this
int average( int first, ... )
Where the ellipses denote a variable argument list.
If I have a function like that in a c++ DLL and I want to link a Visual Basic GUI to it, how would that function be declared in the Visual Basic program?

The Visual Basic 6 text I have talks about something called Optional Variant but it looks like it will only apply for one variable and not a list of unknown variables.
*
Not quite sure but I believe VB language does not have variable argument list. (even if it has, you can't just pass it directly to C variable argement list. )

I guess you need to use optional or if you are OOP minded, you might need to consider function overload.






TSAthono
post Mar 3 2006, 12:25 AM

Getting Started
**
Junior Member
227 posts

Joined: Dec 2005
QUOTE(anthony_yio @ Mar 2 2006, 05:44 AM)
Not quite sure but I believe VB language does not have variable argument list. (even if it has, you can't just pass it directly to C variable argement list.  )

I guess you need to use optional or if you are OOP minded, you might need to consider function overload.
*
I found a little about it.

http://www.thevbzone.com/s_projects.htm

has come code that at least simulates variable argument list using the function call:

Private Function Function1(ParamArray vntParameters() As Variant) As Boolean

like this:


CODE
Private Function Function1(ParamArray vntParameters() As Variant) As Boolean
 
  Dim vntParms() As Variant
 
  vntParms = vntParameters
 
  Function1 = Function2(vntParms)
 
End Function

Private Function Function2(ByRef vntParameters As Variant) As Boolean
 
  Dim strMsg     As String
  Dim lngCounter As Long
 
  strMsg = "Parameter Array = " & Chr(13) & Chr(13)
  For lngCounter = LBound(vntParameters) To UBound(vntParameters)
     
     If IsMissing(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "MISSING" & Chr(13)
       
     ElseIf IsEmpty(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "EMPTY" & Chr(13)
       
     ElseIf IsNull(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "NULL" & Chr(13)
       
     ElseIf IsArray(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "ARRAY (" & CStr(LBound(vntParameters(lngCounter))) & " To " & CStr(UBound(vntParameters(lngCounter))) & ")" & Chr(13)
       
     ElseIf IsObject(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "OBJECT (" & CStr(ObjPtr(vntParameters(lngCounter))) & ")" & Chr(13)
       
     Else
        strMsg = strMsg & "VALUE = " & CStr(vntParameters(lngCounter)) & Chr(13)
     End If
  Next
 
  MsgBox strMsg, vbOKOnly + vbInformation, " "
  Function2 = True
 
End Function

Private Sub Form_Load()
 
  Debug.Print Function1("Hello World!", 123456, Me.Icon, Split("1,2,3,4", ","), vbNull)
  Unload Me
 
End Sub


but this does not help in me trying to pass it to VC
anthony_yio
post Mar 3 2006, 11:38 AM

........
Group Icon
Elite
1,828 posts

Joined: Jan 2003


QUOTE(Athono @ Mar 3 2006, 12:25 AM)
I found a little about it.

http://www.thevbzone.com/s_projects.htm

has come code that at least simulates variable argument list using the function call:

Private Function Function1(ParamArray vntParameters() As Variant) As Boolean

like this:
CODE
Private Function Function1(ParamArray vntParameters() As Variant) As Boolean
 
  Dim vntParms() As Variant
 
  vntParms = vntParameters
 
  Function1 = Function2(vntParms)
 
End Function

Private Function Function2(ByRef vntParameters As Variant) As Boolean
 
  Dim strMsg     As String
  Dim lngCounter As Long
 
  strMsg = "Parameter Array = " & Chr(13) & Chr(13)
  For lngCounter = LBound(vntParameters) To UBound(vntParameters)
     
     If IsMissing(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "MISSING" & Chr(13)
       
     ElseIf IsEmpty(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "EMPTY" & Chr(13)
       
     ElseIf IsNull(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "NULL" & Chr(13)
       
     ElseIf IsArray(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "ARRAY (" & CStr(LBound(vntParameters(lngCounter))) & " To " & CStr(UBound(vntParameters(lngCounter))) & ")" & Chr(13)
       
     ElseIf IsObject(vntParameters(lngCounter)) = True Then
        strMsg = strMsg & "OBJECT (" & CStr(ObjPtr(vntParameters(lngCounter))) & ")" & Chr(13)
       
     Else
        strMsg = strMsg & "VALUE = " & CStr(vntParameters(lngCounter)) & Chr(13)
     End If
  Next
 
  MsgBox strMsg, vbOKOnly + vbInformation, " "
  Function2 = True
 
End Function

Private Sub Form_Load()
 
  Debug.Print Function1("Hello World!", 123456, Me.Icon, Split("1,2,3,4", ","), vbNull)
  Unload Me
 
End Sub


but this does not help in me trying to pass it to VC
*
For this one, you would need to pass a VARIANT of type VT_ARRAY from C/C++ to VB. Nope, variable arg list can't be passed in like this.


 

Change to:
| Lo-Fi Version
0.0146sec    1.59    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 01:37 PM