﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » I'm stuck - Hope to get some help!</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 18:05:00 GMT</lastBuildDate><ttl>20</ttl><item><title>I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9307.aspx</link><description>I'm stuck with a compile error and can't see it.&lt;br&gt;
&lt;br&gt;
I have a simple method that starts a given form:&lt;br&gt;
[quote]    private void StartForm(System.Type MyFormType)&lt;br&gt;
    {&lt;br&gt;
      Form loForm;&lt;br&gt;
      loForm = Activator.CreateInstance(MyFormType) as Form;&lt;br&gt;
      loForm.Show();&lt;br&gt;
    }&lt;br&gt;
[/quote]&lt;br&gt;
&lt;br&gt;
Then for each item from the menu, I call this method and pass the class name of my form:&lt;br&gt;
[quote]    private void tsmStore_Click(object sender, EventArgs e)&lt;br&gt;
    {&lt;br&gt;
      // frmStore is the class name for store&lt;br&gt;
      StartForm(GetType(frmStore));&lt;br&gt;
    }&lt;br&gt;
[/quote]&lt;br&gt;
&lt;br&gt;
I then get this error:&lt;br&gt;
[quote]'frmStore' is a 'type' but is used like a 'variable'&lt;br&gt;
[/quote]&lt;br&gt;
&lt;br&gt;
I'm passing the type of class name, but still like it.&lt;br&gt;
&lt;br&gt;
What am I missing?&lt;br&gt;
&lt;br&gt;
Thanks!</description><pubDate>Tue, 05 Jun 2007 09:34:07 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9315.aspx</link><description>[quote]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.[/quote]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.&lt;br&gt;
&lt;br&gt;
But your point is well taken.&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
[quote]The equivalent language construct in C# is typeof(), so you should call it like this:&lt;br&gt;
&lt;br&gt;
StartForm(typeof(frmStore));&lt;br&gt;
&lt;br&gt;
not&lt;br&gt;
&lt;br&gt;
StartForm(GetType(frmStore));[/quote]I just tried you way and works perfect. You're "D" man! :)&lt;br&gt;
&lt;br&gt;
[quote]P.S. Of course you're going to get some help[/quote]You're not only an scholar but a Gentleman as well! ;)&lt;br&gt;
&lt;br&gt;
Thanks for the great support!</description><pubDate>Tue, 05 Jun 2007 09:34:07 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9312.aspx</link><description>Ah, the reason that it's giving you that is you're using GetType in C#.&amp;nbsp; If you use Type.GetType() (the static method on the System.Type class), it expects a string name for the type.&amp;nbsp; 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. &lt;P&gt;The equivalent language construct in C# is typeof(), so you should call it like this:&lt;/P&gt;&lt;P&gt;StartForm(typeof(frmStore));&lt;/P&gt;&lt;P&gt;not &lt;/P&gt;&lt;P&gt;StartForm(GetType(frmStore));&lt;/P&gt;&lt;P&gt;The second one only works in VB (without the ; ;))&lt;P&gt;P.S. Of course you're going to get some help :)</description><pubDate>Tue, 05 Jun 2007 08:34:40 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9310.aspx</link><description>Ahh, never mind Chan; I had forgotten to put Double Quotes around. Thank you very much!</description><pubDate>Tue, 05 Jun 2007 00:49:58 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9309.aspx</link><description>Thanks Chan;&lt;br&gt;
&lt;br&gt;
But adding Type gives me this error:&lt;br&gt;
[quote]'frmStore' is a 'type', which is not valid in the given context[/quote]</description><pubDate>Tue, 05 Jun 2007 00:47:37 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: I'm stuck - Hope to get some help!</title><link>http://forum.strataframe.net/FindPost9308.aspx</link><description>Hi,&lt;br&gt;
Try&lt;br&gt;
&lt;br&gt;
private void tsmStore_Click(object sender, EventArgs e)&lt;br&gt;
[codesnippet]{&lt;br&gt;
// frmStore is the class name for store&lt;br&gt;
StartForm(Type.GetType("MyNameSpace.frmStore"));&lt;br&gt;
}[/codesnippet]&lt;br&gt;
&lt;br&gt;
HTH</description><pubDate>Tue, 05 Jun 2007 00:18:52 GMT</pubDate><dc:creator>Chan</dc:creator></item></channel></rss>