home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / COM / VariantSafeArray / VBCOMobject < prev   
Encoding:
Visual Basic class definition  |  2000-05-04  |  3.7 KB  |  112 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "VBCOMObject"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. '
  15. ' VBCOMObject
  16. '
  17. ' (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  18. '
  19. '
  20. Option Explicit
  21. '
  22. 'This function will illustrate the use of Variant BSTR types passed by Value.
  23. 'The String passed as a parameter is checked to be equal to 'test', and if so
  24. 'returns the value of 99, else returns 77.  The parameter is also modified before
  25. 'the funtion returns.
  26. '
  27. Public Function processStringByVal(ByVal str)
  28.    Dim value As Integer
  29.    If str = "test" Then
  30.     value = 99
  31.    Else: value = 77
  32.    End If
  33.    str = "in VB -> processStringByVal!"
  34.     processStringByVal = value
  35. End Function
  36. '
  37. 'This function will illustrate the use of Variant BSTR types passed by Reference.
  38. 'The String passed as a parameter is checked to be equal to 'test', and if so
  39. 'returns the value of 39, else returns 12.  The parameter is also modified before
  40. 'the funtion returns.
  41. '
  42. Public Function processStringByRef(ByRef str)
  43.    Dim value As Integer
  44.    If str = "test" Then
  45.     value = 39
  46.    Else: value = 12
  47.    End If
  48.    str = "in VB -> processStringByRef!"
  49.    processStringByRef = value
  50. End Function
  51. '
  52. 'Attempts to simulate passing an object, or null to a function.  The return value
  53. 'from this function will either be a String stating that a Null was passed, or
  54. 'a String containing a description of the type of Object that was passed.  Note:
  55. 'This method will only work if the Object passed is a known Variant type.  The
  56. 'Object used as a parameter is also assigned the return value in this pass by
  57. 'value example.
  58. '
  59. Public Function processObjectByVal(ByVal val)
  60.     Dim value As String
  61.    If val = Null Then
  62.     value = "Null was passed to the function processNullByVal"
  63.     Else: value = "You passed in a " & TypeName(val)
  64.     End If
  65.     val = value
  66.     processObjectByVal = value
  67. End Function
  68. '
  69. 'Attempts to simulate passing an object, or null to a function.  The return value
  70. 'from this function will either be a String stating that a Null was passed, or
  71. 'a String containing a description of the type of Object that was passed.  Note:
  72. 'This method will only work if the Object passed is a known Variant type.  The
  73. 'Object used as a parameter is also assigned the return value in this pass by
  74. 'reference example.
  75. '
  76. Public Function processObjectByRef(ByRef val)
  77.     Dim value As String
  78.    If val = Null Then
  79.     value = "Null was passed to the function processNullByRef"
  80.     Else: value = "You passed in a " & TypeName(val)
  81.     End If
  82.     val = value
  83.     processObjectByRef = value
  84. End Function
  85. '
  86. 'This Section deals with passing SafeArrays of Objects, ints, chars and Strings
  87. '
  88. '
  89. ' Takes an Object Array and Returns a String Array
  90. '
  91. Public Function processObjectArray(ParamArray objar())
  92.     Dim result(10)
  93.     Dim i As Integer
  94.     For i = LBound(objar) To UBound(objar)
  95.         result(i) = " Param type is " & TypeName(objar(i))
  96.         objar(i) = "modified in processObjectArray"
  97.     Next i
  98.     processObjectArray = result
  99. End Function
  100. '
  101. ' Takes a String array and and returns an integer Array
  102. '
  103. Public Function processStringArray(ParamArray strarr())
  104.     Dim result(10)
  105.     Dim i As Integer
  106.     For i = LBound(strarr) To UBound(strarr)
  107.         result(i) = i
  108.         strarr(i) = "Modifying the param in processStringArray"
  109.     Next i
  110.     processStringArray = result
  111. End Function
  112.