I'm stuck - Hope to get some help!


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
It's confusing because in VB, Type.GetType("MyFormName") and GetType(MyFormName) are named the same thing, but the first is a static method of System.Type and the second one is a language construct that compiles the raw type into the application.
I'm going to kill this VB. I looked at the CRM example (which only comes in VB by the way), and started from there. But killed three hours of my sleep over it, until Chan jumped in and helped.



But your point is well taken.

Ben, a long time ago, you had mentioned you had gotten a new [good] program that converts VB to C#. Could you please convert the CRM Application to C# and attach the solution here. There are actually several samples in VB that are not in C# samples.



The equivalent language construct in C# is typeof(), so you should call it like this:



StartForm(typeof(frmStore));



not



StartForm(GetType(frmStore));
I just tried you way and works perfect. You're "D" man! Smile



P.S. Of course you're going to get some help
You're not only an scholar but a Gentleman as well! Wink



Thanks for the great support!

..ßen
StrataFrame Team
S
StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Ah, the reason that it's giving you that is you're using GetType in C#.  If you use Type.GetType() (the static method on the System.Type class), it expects a string name for the type.  It's confusing because in VB, Type.GetType("MyFormName") and GetType(MyFormName) are named the same thing, but the first is a static method of System.Type and the second one is a language construct that compiles the raw type into the application.

The equivalent language construct in C# is typeof(), so you should call it like this:

StartForm(typeof(frmStore));

not

StartForm(GetType(frmStore));

The second one only works in VB (without the ; Wink)

P.S. Of course you're going to get some help Smile

Ben Hayat
Ben Hayat
Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Ahh, never mind Chan; I had forgotten to put Double Quotes around. Thank you very much!

..ßen
Ben Hayat
Ben Hayat
Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Thanks Chan;



But adding Type gives me this error:

'frmStore' is a 'type', which is not valid in the given context


..ßen
Chan
Chan
Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)Advanced StrataFrame User (701 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

Try



private void tsmStore_Click(object sender, EventArgs e)

{

// frmStore is the class name for store

StartForm(Type.GetType("MyNameSpace.frmStore"));

}




HTH
Ben Hayat
Ben Hayat
Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)Advanced StrataFrame User (518 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I'm stuck with a compile error and can't see it.



I have a simple method that starts a given form:

private void StartForm(System.Type MyFormType)

{

Form loForm;

loForm = Activator.CreateInstance(MyFormType) as Form;

loForm.Show();

}





Then for each item from the menu, I call this method and pass the class name of my form:

private void tsmStore_Click(object sender, EventArgs e)

{

// frmStore is the class name for store

StartForm(GetType(frmStore));

}





I then get this error:

'frmStore' is a 'type' but is used like a 'variable'





I'm passing the type of class name, but still like it.



What am I missing?



Thanks!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search