![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#11
| |||
| |||
|
|
ThatŽs what iŽve tried but it ends up with an exception that the object type cant be converted to the target type. Displaying the name of the constant is no problem... My code in the module: Public Const Company As String = "TestCompany" My code in the main application: Dim PublicField As FieldInfo PublicField = FormType.GetField("Company") MsgBox(PublicField.Name.ToString) <- that works perfectly, displaying "Company" MsgBox(PublicField.GetValue(PublicField).ToString) <- no way :-( Any idea? Thanks, Andy CT wrote: This is one way: fi.GetValue(fi).ToString Feel free to use a conversion function instead of the ToString method, depedning on the type of constant you have, i.e. CInt for and Integer etc: Dim x As Integer = CInt(fi.GetValue(fi)) |
#12
| |||
| |||
|
|
Hmm, this works for me: Dim assemblyToLoad As [Assembly] ' Load assembly from file assemblyToLoad = [Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll") ' Find the assembly module Dim assemblyModule As [Module] = assemblyToLoad.GetModule("ClassLibrary.dll") ' Find the Module type. Dim moduleType As Type = _ assemblyModule.GetType("ClassLibrary.Module1") ' Get the public Company constant Dim PublicField As FieldInfo PublicField = moduleType.GetField("Company") MsgBox(PublicField.Name.ToString) MsgBox(PublicField.GetValue(PublicField).ToString) |
#13
| |||
| |||
|
|
No way, it doesn't want to work here... Maybe you can send a copy of the main project and the library project to andy.mail (AT) zwickau-net (DOT) de? Or can I call a function from the module library, which throws the variables i would like to have? Thank you, Andy CT wrote: Hmm, this works for me: Dim assemblyToLoad As [Assembly] ' Load assembly from file assemblyToLoad = [Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll") ' Find the assembly module Dim assemblyModule As [Module] = assemblyToLoad.GetModule("ClassLibrary.dll") ' Find the Module type. Dim moduleType As Type = _ assemblyModule.GetType("ClassLibrary.Module1") ' Get the public Company constant Dim PublicField As FieldInfo PublicField = moduleType.GetField("Company") MsgBox(PublicField.Name.ToString) MsgBox(PublicField.GetValue(PublicField).ToString) |
#14
| |||
| |||
|
|
Oh no, my fault! I handled the wrong dll file, now it works. One of those days, eh? ;-) |
|
Oh no, my fault! I handled the wrong dll file, now it works. Thanks for all your patience, Carsten! I hope youŽll have a very nice and relaxed weekend! Best regards and thanks again, Andy Andy wrote: No way, it doesn't want to work here... Maybe you can send a copy of the main project and the library project to andy.mail (AT) zwickau-net (DOT) de? Or can I call a function from the module library, which throws the variables i would like to have? Thank you, Andy CT wrote: Hmm, this works for me: Dim assemblyToLoad As [Assembly] ' Load assembly from file assemblyToLoad = [Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll") ' Find the assembly module Dim assemblyModule As [Module] = assemblyToLoad.GetModule("ClassLibrary.dll") ' Find the Module type. Dim moduleType As Type = _ assemblyModule.GetType("ClassLibrary.Module1") ' Get the public Company constant Dim PublicField As FieldInfo PublicField = moduleType.GetField("Company") MsgBox(PublicField.Name.ToString) MsgBox(PublicField.GetValue(PublicField).ToString) |
#15
| |||
| |||
|
|
CT, thanks for your very quick answer. Is it possible to include forms in assemblies so the assembly can be a complete program which is called from the main application? Can you recommend an assembly tutorial to me? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |