473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Creating dynamic forms from a varible name

Hello:

Here is the situation. VB.NET

I have several forms and I have a XML file that can start with a
particular for for debugging/layout reasons. This is a mdi project.
Normaly you would load a form as follows:

Dim frmT As frmTrans
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Thus you could have a menu option to kick off a child form. What I
need is a way to have the form class as a varible name. Such as:

dim f as string = "frmTrans"
Dim frmT As f
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Is there a way of doing this?

Thanks,

Sal

sfp04212005

Nov 21 '05 #1
2 1387
I think you need to use reflection for this..

I do something similar, using an XML based menu structure with each menu
loading a dll and calling a function... The function may in turn load a
form.

This is done using the following function which is called such as follows:

obj=loadmebyname("myclassfilename.dll","myclass",n othing)
obj.functionname
Hope this helps.. function follows:
Regards
Simon
Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ByVal
vstrClassName As String, ByVal vArgs() As Object) As Object

'************************************************* ***********************************

'dynamically load object from assembly for late binding purpose

'
************************************************** ***********************************

Dim objAssembly As Reflection.Assembly

Dim objtemp As Object

Dim Params() As Object

'MsgBox(Application.StartupPath)

Try

If Dir(Application.StartupPath & "\" & vstrAssemblyName).Equals("") Then

Err.Raise(-1, "LoadMeByName", "assembly could not found, wrong assembly name
given ")

Exit Function

End If

objAssembly = objAssembly.LoadFrom(Application.StartupPath & "\" &
vstrAssemblyName)

objtemp = objAssembly.CreateInstance(vstrClassName, True,
Reflection.BindingFlags.CreateInstance, Nothing, vArgs, Nothing, Nothing)

If objtemp Is Nothing Then

Err.Raise(-1, "LoadMeByName", "assembly could not found, wrong assembly name
given ")

Exit Function

End If

' LoadMeByName = objtemp

Return objtemp

Catch

End Try

End Function

<sa********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Hello:

Here is the situation. VB.NET

I have several forms and I have a XML file that can start with a
particular for for debugging/layout reasons. This is a mdi project.
Normaly you would load a form as follows:

Dim frmT As frmTrans
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Thus you could have a menu option to kick off a child form. What I
need is a way to have the form class as a varible name. Such as:

dim f as string = "frmTrans"
Dim frmT As f
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Is there a way of doing this?

Thanks,

Sal

sfp04212005

Nov 21 '05 #2
Try using reflection by importing the System.Reflection namespace. You can
do something like this:

Dim currentAsm As [Assembly] 'Instance of current executing assembly
Dim asmTypes() As Type 'An array of all type of the executing
assembly
Dim typeNamespace As String 'the namespace of a given type
Dim constructorArguments() As Object 'any parameters you pass for the New()
Dim typeToCreate As String = "frmTrans" 'The name of the type you want
Dim instanceOfType As Object 'The actual instance of the type.

'Create instance of executing assembly
currentAsm = [Assembly].GetExecutingAssembly()

'Get the types from the assembly
asmTypes = currentAsm.GetTypes()

'Iterate through the types and find the one you want
For Each objType As Type In asmTypes
'Get the namespace of the current type
typeNamespace = objType.Namespace & "."

'If we find a match, then create an instance of that type
If Type.GetType(typeNamespace & typeToCreate, False, True) Is objType Then
'Create your arguments if necessary
args = new object() {"argument1"}

'Create instance of type
instanceOfType = objType.InvokeMember(Nothing, _
BindingFlags.Public Or BindingFlags.NonPublic Or _
BindingFlags.Instance Or BindingFlags.CreateInstance _
, Nothing, Nothing, args)
End If
Next

Doing a search on Reflection and pull up other examples. Hope this helps.

"sa********@gmail.com" wrote:
Hello:

Here is the situation. VB.NET

I have several forms and I have a XML file that can start with a
particular for for debugging/layout reasons. This is a mdi project.
Normaly you would load a form as follows:

Dim frmT As frmTrans
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Thus you could have a menu option to kick off a child form. What I
need is a way to have the form class as a varible name. Such as:

dim f as string = "frmTrans"
Dim frmT As f
frmT = New frmTrans
frmT.formDate = Now.Date
frmT.MdiParent = Me
frmT.Show()

Is there a way of doing this?

Thanks,

Sal

sfp04212005

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
3
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to...
5
by: matt | last post by:
hello, i am on an interesting project. in this project, i have to create dynamic data-entry forms for offline-users to fill out, save locally, and eventually postback to our app (when back...
1
by: phpnewbie2007 | last post by:
I have 2 dynamic PHP dropdowns: The second dropdown populates from the first, depending on what is selected in the first. The page is showing issues in a department: The first dropdown...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
3
by: JohnHo | last post by:
I am trying to use the filter method with a form Using the Access/VBA documentation I have created a filter which looks like this me.filter = "lngCaseID = 18905" me.filter on = true
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.