Título: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 01:47 am
Este codigo que les dejo me arreglo una duda que tenia la cual me la respondio Google a una liga interesante ( Almenos para mi xP ) intentaba hacer algo similar a esto: Private Sub Form_Load() Dim Args() As Variant ReDim Args(0 To 1) Args(0) = "hola Mundo" Args(1) = "12" CallByName Me, "Mensaje", VbMethod, Args() End Sub Public Sub mensaje(mensaje As String, Optional hola As Long) MsgBox mensaje, vbOKOnly, hola End Sub
pero no daba y google me respodio: http://www.devx.com/tips/Tip/15422 ' Required for use in VB5! Public Enum VbCallType VbMethod = 1 VbGet = 2 VbLet = 4 VbSet = 8 End Enum Public Function CallByNameEx(Obj As Object, _ ProcName As String, CallType As VbCallType, _ Optional vArgsArray As Variant) Dim oTLI As Object Dim ProcID As Long Dim numArgs As Long Dim i As Long Dim v() On Error GoTo Handler Set oTLI = CreateObject("TLI.TLIApplication") ProcID = oTLI.InvokeID(Obj, ProcName) If IsMissing(vArgsArray) Then CallByNameEx = oTLI.InvokeHook( _ Obj, ProcID, CallType) End If If IsArray(vArgsArray) Then numArgs = UBound(vArgsArray) ReDim v(numArgs) For i = 0 To numArgs v(i) = vArgsArray(numArgs - i) Next i CallByNameEx = oTLI.InvokeHookArray( _ Obj, ProcID, CallType, v) End If Exit Function Handler: Debug.Print Err.Number, Err.Description End Function
con lo cual ahora el CallByName bueno mejor dicho CallByNameEx acepta ahora expresiones de este tipo: Call CallByNameEx(Me, "xx", VbMethod, x) Call CallByNameEx(Me, "xx", VbMethod, Array(1, 2)) Result=CallByNameEx(Me, "xx", VbMethod, x)
siendo que antes array() o pasandole un vector a CallByName No servia Private Sub Form_Load() Dim Args() As Variant ReDim Args(0 To 1) Args(0) = "hola Mundo" Args(1) = "12" CallByNameEx Me, "Mensaje", VbMethod, Args() End Sub Public Sub mensaje(mensaje As String, Optional hola As Long) MsgBox mensaje, vbOKOnly, hola End Sub
Sangrienta Luna Infernal!¡.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: LeandroA en 27 Marzo 2010, 03:15 am
Interesante che, que aplicación sera TLI? saves cual es la refencia¿?
Saludos.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 06:45 am
TypeLib Information
TLBInf32.dll
Sangriento Infierno Lunar.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 06:49 am
Agregando la referencia... TypeLib Information: ' Required for use in VB5! Public Enum VbCallType VbMethod = 1 VbGet = 2 VbLet = 4 VbSet = 8 End Enum Public Function CallByNameEx(Obj As Object, ProcName As String, CallType As VbCallType, Optional vArgsArray As Variant) On Error GoTo Handler Dim oTLI As TLIApplication ' // Set oTLI = CreateObject("TLI.TLIApplication") Dim ProcID As Long Dim numArgs As Long Dim i As Long Dim v() As Variant Set oTLI = New TLIApplication If Not oTLI Is Nothing Then ProcID = oTLI.InvokeID(Obj, ProcName) If IsMissing(vArgsArray) Then CallByNameEx = oTLI.InvokeHook(Obj, ProcID, CallType) End If If IsArray(vArgsArray) Then numArgs = UBound(vArgsArray) ReDim v(numArgs) For i = 0 To numArgs v(i) = vArgsArray(numArgs - i) Next i CallByNameEx = oTLI.InvokeHookArray(Obj, ProcID, CallType, v) End If End If Exit Function Handler: Debug.Print Err.Number, Err.Description End Function
Sangriento Infierno Lunar!¡.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: Karcrack en 27 Marzo 2010, 13:03 pm
Tambien podrias hacer esto, no? Private Sub Form_Load() Dim vParams(1) As Variant vParams(0) = "Hi ho" vParams(1) = 1500 CallByName Me, "Mensaje", VbMethod, vParams() End Sub Public Sub Mensaje(ByRef vParams() As Variant) Call MsgBox(vParams(0), , vParams(1)) End Sub
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: seba123neo en 27 Marzo 2010, 15:06 pm
Tambien podrias hacer esto, no? Private Sub Form_Load() Dim vParams(1) As Variant vParams(0) = "Hi ho" vParams(1) = 1500 CallByName Me, "Mensaje", VbMethod, vParams() End Sub Public Sub Mensaje(ByRef vParams() As Variant) Call MsgBox(vParams(0), , vParams(1)) End Sub
si, yo tambien pense eso, pero el tema aca es que al pasarle el, array te pase cada indice del mismo al parametro correspondiente. saludos.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 17:59 pm
Tambien podrias hacer esto, no? Private Sub Form_Load() Dim vParams(1) As Variant vParams(0) = "Hi ho" vParams(1) = 1500 CallByName Me, "Mensaje", VbMethod, vParams() End Sub Public Sub Mensaje(ByRef vParams() As Variant) Call MsgBox(vParams(0), , vParams(1)) End Sub
la cosa que si algun parametro es distinto a variant por ejemplo una revoltura de variados parametros de distintos tipos NO FUNCIONA y este era mi problema y no me hubiera gustado estar convirtiendo dentro cada parametro al real.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: Karcrack en 27 Marzo 2010, 18:24 pm
He estado investigando mas sobre TLI32 y es muy muy interesante... >:D http://support.microsoft.com/kb/q224331/ :D
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: BlackZeroX en 27 Marzo 2010, 19:01 pm
He estado investigando mas sobre TLI32 y es muy muy interesante... >:D http://support.microsoft.com/kb/q224331/ :D No dije yo esto pero...: Puedes obtener las funciones/procesos/Propiedades y sus parametros con sus tipos respectivos... Sangrienta Luna Infernal!¡.
Título: Re: [Source] CallByNameEx y argumentos aleatorios
Publicado por: LeandroA en 28 Marzo 2010, 05:54 am
che me gusto esa libreria mirando la ayuda vi que se pueden enumerar todas las constantes eventos funcion etc de una librerira Private Sub Form_Load()
Dim SIType As SearchItem Dim SIMember As SearchItem With TypeLibInfoFromFile("msvbvm60.dll") .SearchDefault = tliStConstants For Each SIType In .GetTypes For Each SIMember In .GetMembers(SIType.SearchData) Debug.Print SIMember, _ .GetMemberInfo(SIType.SearchData, SIMember.InvokeKinds, SIMember.MemberId).Value Next Next End With
End Sub
|