|
Hi,
If know a form named "Form1", how to get the form object and show it ?
'**************************************
Dim myFormName As String="Form1"
Dim myFormObject As System.Windows.Forms.Form
'...
'How to get myFormObject of "Form1" ?
'How to show "Form1" ?
'...
'**************************************
Thanks
kaiwnyt
|
|
|
|
|
|
You're question and code sample are very confusing and don't lend themselves to an clear explaination of what you're doing. THe best I can tell you without a better description of the problem is:
Dim myForm As New Form1
myForm.Show()
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Do you mean that you just know the name of the form and you would like to display it?
You can try to look in the Forms collection to match the name and display that form, using the Show method.
Hope this helps
Chandra
|
|
|
|
|
This is not a trivial task.
If all you have is the simple form name as a string, then you need to use some sort of Reflection to create an instance of that type, AND you have to use the full name of the type, which is "Namespace.Type".
Here's one approach:
"Loading Classes on the Fly"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet10082002.asp
Here's a similar way, that does not use a configuration file. I just used the assembly name, which should work, unless you or another developer has placed the forms in a different namespace.
Either way, you have to know the namespace of the type. If it happens to be the same as the assembly, which usually it will be, then you're in good shape. If not, you just have to know the namespace, and prepend it to the form name. (And don't forget to use proper exception handling. Do as I say, not as I do.)
Imports System.Reflection
Module Module1
Friend Function GetFormUsingGetType(ByVal formName As String) As Form
Dim myAssembly As [Assembly] = [Assembly].GetExecutingAssembly
Dim myForm As Form
Dim myFormName As String
Dim myType As Type
Dim myAssemblyNameObj As AssemblyName = myAssembly.GetExecutingAssembly.GetName
Dim myAssemblyName As String
myAssemblyName = myAssemblyNameObj.Name
myType = myAssembly.GetType(myAssemblyName & "." & formName, True, True)
myFormName = myType.FullName
myForm = CType(myAssembly.CreateInstance(myFormName), Form)
Return myForm
End Function
Friend Function GetFormUsingActivator(ByVal formName As String) As Form
Dim myForm As Form
Dim myFormName As String
Dim myAssemblyNameObj As AssemblyName = [Assembly].GetExecutingAssembly.GetName
Dim myAssemblyName As String
Dim obj As System.Runtime.Remoting.ObjectHandle
myAssemblyName = myAssemblyNameObj.Name
myFormName = myAssemblyName & "." & formName
obj = Activator.CreateInstance(myAssemblyName, myFormName)
myForm = CType(obj.Unwrap, Form)
Return myForm
End Function
End Module
|
|
|
|
|
I am creating a network instant messaging program in VS 2005. I want it to work in much the same way as msn Messenger, as in a realtime chat where multiple people can input messages to one single chat box that is shown on each pc. I am unsure how to go about sending and recieving messages and was wondering if anyone could point me in the right direction.
Posted by The ANZAC
|
|
|
|
|
I was working on a similar problem only a week ago! What a coincidence!
Anyway, if you have a network drive set up (a drive on a computer that all computers in your house can access), create a text file. Then when somebody submits some text, just take that text and add it to the main file. From there, just show the contents of that main file in another text box. Simple, and a lot easier than learning networking!
I hope you can figure it out. Let me know if you need more help!
|
|
|
|
|
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Network chat is one of those ubiquitous apps that every newbie wants to make. All you have to do is type "vb.net chat[^]" into Google and you'll come up with about 4,000,000 hits, most of which have code examples of what you want to do.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Trust me, it works great! And a lot easier than networking!
Just try it!
|
|
|
|
|
UltraCoder wrote: And a lot easier than networking!
And totlay useless if the two people who are chatting are not part of the same network, like say, on the Internet!
You were wondering why nobody was downloading the stuff from your site? This could be a clue...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
VB.NET
For my application i need to create arrays on runtime.
How will i do that?
Or do i have to make something like a method which creates an array while developing and make an instance of it at runtime to rename it finally?
Thanks
-- modified at 17:24 Friday 3rd November, 2006
|
|
|
|
|
keninfo wrote: Or do i have to make something like a method which creates an array while developing and make an instance of it at runtime to rename it finally?
I don't understand what this means.
To be honest, I don't understand your question. do you want to assign an array, or create a variable that wasn't in your code before ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Just create a method that creates your Array and call that method at runtime! Or, just put the code that creates the array in the "Form.Load" procedure.
Or do you want to know how to create an array?
|
|
|
|
|
Like Christian, I can't figure out what you really want to do. You're post sounds a bit confused.
Are you looking for something like this?
Dim myArray() As String
creates an array of Strings.
You might want to explain what your trying to do in more detail and include a code snippet showing where you want this array to show up.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Ok, maybee a wrong start of this discussion.
Let's try it again.
I am writting an application (kind of callcenter server), which controls the traffic from a telephone system (PABX).
The application let me insert callcenter agents(name and number), extentions(name and number) and callcenter groups(name and number).
When i insert a callcenter group an array has to be created with the callcenter group number as it's name. finally i can add agents to the group array.
So, for example:
Two agenst were inserted:
200 Bill
201 Albert
Then two extentions were made:
100 extention 100
101 extention 101
Finally one group is made:
400 Sales
After creating the group, an array has to be created with 400 as it's name.
The agents have to be added to the group array.
So, i know how to make an array: Dim groupArray() as Integer.
And i know how to add agents to the array.
But during runtime there have to be an array created everytime when a group is made and the array name has to be the number of the groep.
Thanks
regards
|
|
|
|
|
I think what you probably need is a dynamic array of collections, so you can add a collection every time a new group is created.
Hope this helps
Chandra
|
|
|
|
|
Ok,
But how will i do that?
|
|
|
|
|
It sounds like you looking more for a database than a collection of arrays. You've just described the layout of three different tables and their relationships.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Yes, i can imagine.
But i want to solve this with arrays.
|
|
|
|
|
Google this: "jagged arrays vb .net"
|
|
|
|
|
So you say that you need to create variables dynamically? Well, that's not possible in VB.NET. Why? Because noone ever needs to do that. Ever.
You say that you need to create an array that has a specific name. Strictly speaking that is not possible either, as an array doesn't even have a name.
When you create an array object you get a reference to the object. That reference is usually assigned to a reference variable. For example:
Dim a As String[] = New String[42];
Here the statement New String[42] creates the actual array, and the value of that statement is the reference to the array. The variable a can hold a reference to an object of the type String[] . The reference to the array is stored in the variable.
You can have any number of references to a specific object. Example:
Dim b As String[] = a;<br />
Dim c As String[] = a;
Now you have three references to the array, but there is still only one array. You have three references with different names, and the array doesn't have a name at all.
---
b { font-weight: normal; }
|
|
|
|
|
OK. Here's what you need to do. Or what I would do.*
I would use a HashTable of ArrayLists. Quick, easy, efficient, fairly robust, good cost/benefit ratio. Downside: Not strongly-typed.
You don't want to use raw arrays because you would either have to oversize them to begin with (how many? 1000? 5000? Wasteful and error prone), OR you would have to keep ReDim'ing them (bad performance). You could use ArrayList to get around that problem, but you still have no good keyed access to your entries.
That's where the HashTable comes in.
The HashTable (or Dictionary<..>, depending on your version and requirements) simply stores entries of Key and Value pairs.
In this case your Key would be the Call Center number, and it's Value would be an ArrayList.
The ArrayList would store the Agent objects.
Every time you hit a new call center, you create a new hashtable entry using the call center number as the key, and a new arraylist with the Agent on that call as it's initial value, which effectively allows you to "create a new variable at runtime with a particular name".
(Or, instead of storing the agent object in the arraylist slot, you could create a hashtable of Agents, and just store a reference to that agent's entry in the arraylist slot.)
How do you know it's a new call center? By using the ContainsKey function of the hashtable, or by simply trying to access the item with that key. If it doesn't exist, you get back Null. If it does exist, you add the agent (or a reference to the agent) to its arraylist. Simple.
If you're not familiar with hashtables, take an hour or so and read up on them. Set one up and play with it. Don't be afraid of them. Very powerful tool.
*Now. All that having been said, this is NOT the only way or best way to engineer this, it's just a quick-and-dirty as far as I look at it.
Keep in mind what Dave K. said. What you're really doing here is modeling and managing entity relationships. Call Centers, Agents, Calls, Extensions...
Which means you might be better served to use a strongly-typed DataSet, with Tables and DataRelations to begin with. You are probably going to need to do that eventually anyway.
Hope this helps. Good luck.
|
|
|
|
|
Hello OldWarhorse,
Thanks a lot for your tips.
I will try the hashtable.
Regards
|
|
|
|
|
Hello, i'd like to know that does the MMControl exist in vb.net? if so...where do i add it from?
thanx in advance
|
|
|
|