Click here to Skip to main content
15,887,318 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionretrieval of XML information & Copy to excel Files Pin Pin
Member 1450608920-Jun-19 13:29
Member 1450608920-Jun-19 13:29 
AnswerRe: retrieval of XML information & Copy to excel Files Pin Pin
Richard Deeming21-Jun-19 1:07
mveRichard Deeming21-Jun-19 1:07 
QuestionProblem cropping an image. SOLVED Pin
mo14928-Jun-19 6:07
mo14928-Jun-19 6:07 
AnswerRe: Problem cropping an image. more info Pin
mo14928-Jun-19 9:46
mo14928-Jun-19 9:46 
GeneralRe: Problem cropping an image. more info Pin
Dave Kreskowiak8-Jun-19 16:29
mveDave Kreskowiak8-Jun-19 16:29 
GeneralRe: Problem cropping an image. more info Pin
mo14928-Jun-19 23:34
mo14928-Jun-19 23:34 
AnswerRe: Problem cropping an image. Pin
Gerry Schmitz8-Jun-19 12:05
mveGerry Schmitz8-Jun-19 12:05 
QuestionHow using reflection invoke when method wants a specific object type Pin
Member 85736427-Jun-19 4:45
Member 85736427-Jun-19 4:45 
I have written two simple classes (clsMessage and clsHello). I create an instance of clsMessage and call the Message1 function passing the specific clsHello class that exposes the correct MessagBox to me. When call then Message2 function passing a generic object that expose the correct MessageBox.

these are the classes:

Public Class clsMessage
    Public Function Message1(Of T As {clsHello, IHello})(ByVal value As String) As T
        Return (New clsHello(value))
    End Function
    Public Function Message2(Of T)(ByVal value As String) As T
        Return DirectCast((New clsHello(value)), Object)
    End Function
End Class

Public Class clsHello
     Implements IHello

     Dim _value As String
     Sub New(ByVal value As String)
         _value = value
     End Sub

     Public Sub Hello() Implements IHello.Hello
         Call MsgBox(String.Concat("Hello: ", _value))
     End Sub
End Class

Public Interface IHello
     Sub Hello()
End Interface

these are code that works:

Dim objMessage As New clsMessage
Dim objHelloSpecific As clsHello = objMessage.Message1(Of clsHello)("My name specific")
objHelloSpecific.Hello()
objHelloSpecific = Nothing
Dim objHelloGeneric As Object = objMessage.Message2(Of Object)("My name generic")
objHelloGeneric.Hello
objHelloGeneric = Nothing
objMessage = Nothing

But if using reflection not works and I don't know how to write the invoke method:

Dim typMessage As System.Type = Reflection.Assembly.GetExecutingAssembly.GetType("WindowsApplication1.clsMessage")
Dim typHello As System.Type = Reflection.Assembly.GetExecutingAssembly.GetType("WindowsApplication1.clsHello")
Dim refMessage As Object = typMessage.GetConstructor({}).Invoke({})
Dim funHelloSpcecific As Reflection.MethodInfo = typMessage.GetMethod("Message1")
Dim funHelloGeneric As Reflection.MethodInfo = typMessage.GetMethod("Message2")
Try
    Dim refHelloSpecific As Object = funHelloSpcecific.Invoke(Nothing, {"My name specific"})
    refHelloSpecific.Hello()
    refHelloSpecific = Nothing
Catch ex As Exception
    Call MsgBox(String.Concat("refHelloSpecific: ", ex.Message))
End Try
funHelloSpcecific = Nothing
Try
    Dim refHelloGeneric As Object = funHelloGeneric.Invoke(Nothing, {"My name generic"})
    refHelloGeneric.Hello
    refHelloGeneric = Nothing
Catch ex As Exception
    Call MsgBox(String.Concat("refHelloGeneric: ", ex.Message))
End Try
funHelloGeneric = Nothing
refMessage = Nothing
typHello = Nothing
typMessage = Nothing

The error is: Impossibile eseguire operazioni con associazione tardiva in tipi o metodi per i quali ContainsGenericParameters è true (Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true)

question: can someone help me to write the invoke method correctly? thank you.
Giorgio

AnswerRe: How using reflection invoke when method wants a specific object type Pin
Richard Deeming7-Jun-19 4:53
mveRichard Deeming7-Jun-19 4:53 
GeneralRe: How using reflection invoke when method wants a specific object type Pin
Member 85736427-Jun-19 7:07
Member 85736427-Jun-19 7:07 
QuestionHow to change txt color in MessageBox with API Pin
MasterGamerFX30-May-19 23:44
MasterGamerFX30-May-19 23:44 
AnswerRe: How to change txt color in MessageBox with API Pin
Richard Deeming31-May-19 0:46
mveRichard Deeming31-May-19 0:46 
QuestionHow to clear a bindingsource without deleting from database Pin
desanti30-May-19 3:47
desanti30-May-19 3:47 
AnswerRe: How to clear a bindingsource without deleting from database Pin
Richard MacCutchan30-May-19 4:01
mveRichard MacCutchan30-May-19 4:01 
GeneralRe: How to clear a bindingsource without deleting from database Pin
desanti30-May-19 6:58
desanti30-May-19 6:58 
GeneralRe: How to clear a bindingsource without deleting from database Pin
Richard MacCutchan30-May-19 7:01
mveRichard MacCutchan30-May-19 7:01 
GeneralRe: How to clear a bindingsource without deleting from database Pin
desanti30-May-19 8:56
desanti30-May-19 8:56 
GeneralRe: How to clear a bindingsource without deleting from database Pin
Richard MacCutchan30-May-19 21:44
mveRichard MacCutchan30-May-19 21:44 
AnswerRe: How to clear a bindingsource without deleting from database Pin
Gerry Schmitz31-May-19 5:53
mveGerry Schmitz31-May-19 5:53 
QuestionVisual Basic : Entity Framework update only one table in model from database Pin
desanti30-May-19 2:20
desanti30-May-19 2:20 
QuestionListView DrawItem() e.Bounds gives different Height when item is selected. SOLVED. Pin
mo149228-May-19 2:54
mo149228-May-19 2:54 
AnswerRe: ListView DrawItem() e.Bounds gives different Height when item is selected. Pin
Richard MacCutchan28-May-19 6:20
mveRichard MacCutchan28-May-19 6:20 
GeneralRe: ListView DrawItem() e.Bounds gives different Height when item is selected. Pin
mo149228-May-19 6:24
mo149228-May-19 6:24 
Questionvb.net and Excel ribbon Pin
JR21218-May-19 21:07
JR21218-May-19 21:07 
AnswerRe: vb.net and Excel ribbon Pin
JR21210-Jun-19 10:51
JR21210-Jun-19 10:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.