What I am wanting to do is pass some information from my app to a new DLL project I have created.
In the DLL I have 2 test forms (frm123, frm456). What I need to do is send 2 parameters over to the DLL, when the DLL recieves the info it would then determine which form to open.
In the DLL I have in the Main Module ' I will use arg(0) later
Code:
Module PSAModMain
Function Main(ByVal Args() As String) As Integer
Dim ClientNum As String
Dim Version As String
ClientNum = Args(0).Trim
Version = Args(1).Trim
Dim frm As New Form
frm.Name = "frm" & Version
frm.Show()
End Function
End Module
I am wanting to take the second arg and assemble it into the form name then open the form. I think this will work.
But, on the app side on a button click sub I do not know how to reference it.
My DLL is called PSA100.dll
I can load the individual forms e.g
Code:
Dim myPSAform As New PSA100.frm123
myPSAform.Show()
But that does not help passing args so that the dll can decide which form to load.
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
If the values you want to pass to frm123 are MANDATORY values that need to be passed in order for the form to operate correctly, then I would add a constructor and pass the values there.
So in frm123, you would put
Code:
Private _Value1 as string
Private _Value2 as string
Public Sub New(Value1 as string, Value2 as string)
_Value1 = Value1
_Value2 = Value2
End Sub
then when you create an instance of the form, you would do so like this:
Code:
Dim myForm as new PSA100.frm123("Hello", "World")
so _value1 would equal "Hello", and _Value2 would equal "World" for that instance of frm123.
I do not want to pass values to frm123. I want to pass values to the DLL module so that the DLL can determine which form to open.
Code:
Function Main(ByVal Args() As String) As Integer
Dim ClientNum As String
Dim Version As String
ClientNum = Args(0).Trim
Version = Args(1).Trim ' 123 or 456 or something
Dim frm As New Form
frm.Name = "frm" & Version
frm.Show()
End Function
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
Ok, I see what you are trying to do. The problem is you are just declaring your form as the base "Form" datatype, and not actually making it a form of a specific type.
Just giving the form the name of what form you want it to be does not change the fact that you are doing
Code:
Dim frm As New Form
and not
Code:
Dim frm As New frm123
How many forms will this DLL contain? Unless it is some huge about, or subject to change frequently, I would think the easiest way to go about it would be a select case in the entry point of your DLL to look at the param passed, and create a strongly typed instance of whatever form needs to be created, based on the param.
OK, so your app takes a survey that has different versions?
So when you take the survey the version is saved to the DB for the Client. Then when you go back to view it you want to send the client number and version to the DLL. The DLL then sees the clientID and the version and loads the form that matches the version?
***************************************************
Smartacus comes packaged "As Is With No Warranty"
Yes! But I can not get the app to recognize the args. When I enter say PSA100. intellisense only shows the form names. How can I get it to see a function in the main module?
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
I will play around with ot and see if I can help. There are a lot of smart guys on here that most likely know how to get this done. It is an interesting idea that I would also like to learn and put in the knowledge coffer
***************************************************
Smartacus comes packaged "As Is With No Warranty"
Yes! But I can not get the app to recognize the args. When I enter say PSA100. intellisense only shows the form names. How can I get it to see a function in the main module?
Based on the code you posted above, the function "Main" has no access modifer, so its default is private. You can't see private members in a referenced assembly, they are internal only. Try making it public.
Public Module PSAModMain
Public Function Main(ByVal Args() As String) As Integer
Dim ClientNum As String
Dim Version As String
ClientNum = Args(0).Trim
Version = Args(1).Trim
Dim frm As New Form
frm.Name = "frm" & Version
frm.Show()
End Function
End Module
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
Ok, just so we have things straight here you did the following:
1) Created a standard application (either console or winforms exe)
2) Added a second project which is a class library (dll)
3) In the second project, you have a public module with a public Sub Main
4) You added a reference to the class library DLL in your EXE project
5) You can not access the Sub Main in the dll project via ClassLibraryName.Main()
OK, I now have a reference to the DLL from my EXE project.
What I need to figure out now is concatenating a string into a form name so when I use the NEW it will recognize.
Code:
Public Module Module1
Public Function Main(ByVal ClientNum As Integer, ByVal Version As String) As Integer
Dim strFormName As String
strFormName = "frm" & Version ' This would give the form a name like frm123
Dim frm As New strFormName 'Type 'strFormName' not defined
frm.ShowDialog()
End Function
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
The problem is you are trying to take something you expect to be strongly typed (your specific different form types) but dynamically create an instance of it and expect to be able to access all its properties and controls that are specific to the given forms you designed.
Lets illustrate the point here:
Create a new winforms project, and in addition to the "Form1" that gets created, add a frmTest1 and frmTest2.
In the form1, add a button and a combobox. In the combobox enter the names of these 2 new forms (frmTest1, and frmTest2)
In the button click code in form1, add this:
Code:
Dim myForm As Form = DirectCast(Activator.CreateInstance(Type.GetType("WindowsApplication1." & ComboBox1.Text)), Form)
myForm.ShowDialog()
myForm.Dispose()
Then run it and you can see that selecting frmTest1 or frmTest2 from the combo, and clicking the button does create whatever instance you specified, and it is doing it entierly from a string variable specifing the type.
The problem is, the given instance you are creating is being cast to type "form" and not the derived form type of frmTest1 or frmTest2. So while the instance actually is of frmTest1 or frmTest2, the code doesn't know that, because you dynamically created the form.
So they way you would be able to access specific properties and controls on the dynamicaly created form, would be to cast it to its specific type. This however defeats the purpose of making the forms dynamic in the first place, because you would need a select case with all the form types in order to determine which form you created, so that you could take whatever action is needed for that given form. By that point you would just use a select case to strongly type the forms at creation time anyway.
That isn't to say you can't do this at all. There are ways to mitigate it and make it work, it just depends on what exactly these forms need to do. For example, you could have an intermediate form class in your inheritence chain that has some common methods to all your dynamic forms, then it would be safe to cast to this intermediate type on any of your dynamic forms, and call methods on it.
For example, lets say each of these dynamic forms has a "save" method which saves all the data the user enters. Obviously since each form is different, the save routine needs to be coded in each form to save data for that given form.
So you could create a base form class that inherits from "Form" and have your dynamic forms inherit from this base class. The routines common to all forms can go in this base form class so that you can cast to it and call the shared routines. As long as you override them in the individual forms, those are the routines that will be called.
Attached is an example project to show this in action