473,783 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1401
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=loadmebynam e("myclassfilen ame.dll","mycla ss",nothing)
obj.functionnam e
Hope this helps.. function follows:
Regards
Simon
Public Shared Function LoadMeByName(By Val vstrAssemblyNam e 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.Asse mbly

Dim objtemp As Object

Dim Params() As Object

'MsgBox(Applica tion.StartupPat h)

Try

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

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

Exit Function

End If

objAssembly = objAssembly.Loa dFrom(Applicati on.StartupPath & "\" &
vstrAssemblyNam e)

objtemp = objAssembly.Cre ateInstance(vst rClassName, True,
Reflection.Bind ingFlags.Create Instance, Nothing, vArgs, Nothing, Nothing)

If objtemp Is Nothing Then

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

Exit Function

End If

' LoadMeByName = objtemp

Return objtemp

Catch

End Try

End Function

<sa********@gma il.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.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.Reflecti on 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 constructorArgu ments() 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].GetExecutingAs sembly()

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

'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.Namespa ce & "."

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

'Create instance of type
instanceOfType = objType.InvokeM ember(Nothing, _
BindingFlags.Pu blic Or BindingFlags.No nPublic Or _
BindingFlags.In stance Or BindingFlags.Cr eateInstance _
, Nothing, Nothing, args)
End If
Next

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

"sa********@gma il.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
1983
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 element. BUT, I don't want that value to be in the actual HTML form, I want it to be created in my submit function. For instance:
1
17673
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
3
6831
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 figure out, if there is a way of using polymorphic way (if that is a word) of doing this particular property. A sample of my code is as follows: DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new Size(95, 20),...
5
2543
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 online). data validation is required on the form. i had looked at using PDF-forms for this.. Adobe's "LifeCyle Forms" would work perfectly. with it one can pass in xml to their webservice & get back PDF-form binaries. however, Adobe's pricing is...
1
1918
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 consists of departments- It has 3 options All issues, dept A, dept B If dept A is chosen in the first dropdown, the second dropdown shows all members in dept A and all issues are shown for dept A are shown below. Now if i choose a member in second...
0
2729
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, cannot serch by combine 3 table) Example I have the query table below, how do I make the code to seach based on the query from this: SELECT Product.ID, Product.Description, Quantity.Quantity, Quantity.SeialNo, Quantity.SupplierID,...
3
1410
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
2966
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. Making a selection from list/box A (Qtr) selects a fiscal quarter, which then refreshes the values in list/box B (Mth), which shows the 3 months in that fiscal quarter, which then refreshes the values in list/box C (MthDate), which returns the date...
2
3330
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 code. <HTML> <HEAD> <TITLE> Add/Remove dynamic rows in HTML table </TITLE> <script type="text/javascript" src="script.js"> // JavaScript Document var c=0;
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10081
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.