|
-
May 21st, 2003, 12:42 AM
#1
Thread Starter
Frenzied Member
Public Variables? (Solved)
How and where do I declare variables that will be used by all my Forms?
Thanks in advance
Last edited by Tec-Nico; May 22nd, 2003 at 01:00 AM.
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 21st, 2003, 06:33 AM
#2
Frenzied Member
-
May 21st, 2003, 07:21 AM
#3
Thread Starter
Frenzied Member
Sounds logic, indeed... Like on VB... How do I get to make a module?
Oh... and also... Lets say I have a comboBox... How would be a procedure that would populate it?
Like:
comboBox1.Items = GetItems("DoubleType");
?
In this case I would have a Dictionary and I would get all of those that are Double Typed in my dictionary... Any ideas? (This has to be handed in in less than an hour)
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 21st, 2003, 07:26 AM
#4
PowerPoster
No in C#...
Wrap your variable in a class and make them static.
-
May 21st, 2003, 07:28 AM
#5
PowerPoster
Just enumeate through the collection and query the GetType() method and use the typeof() method to do the comparison.
-
May 21st, 2003, 08:19 AM
#6
Thread Starter
Frenzied Member
Lethal, I am really tired.. Could you please give me an example? I would really appreciate it... You will save my life (and my grade too) if you do...
Thanks in advance
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 21st, 2003, 09:35 AM
#7
PowerPoster
Example 1:
Code:
namespace VSSolutions.Sprocs
{
public class Sprocs
{
private static string addUser;
public static string AddUser
{
get { return addUser; }
set { addUser = value; }
}
public static void AddUserToSytem(int userID)
{
// Call Stored Procedure
}
}
}
Example 2:
Code:
using System;
using System.Collections;
public class EnumerateTypes
{
public static void Main()
{
ArrayList types = new ArrayList();
string name = "John Doe";
double age = 23;
types.Add(name);
types.Add(age);
foreach (Object o in types) {
if (o.GetType() == typeof(System.String)) {
Console.WriteLine("String");
}
else if (o.GetType() == typeof(System.Double)){
Console.WriteLine("Double");
}
}
}
}
-
May 21st, 2003, 03:42 PM
#8
Frenzied Member
Originally posted by Lethal
No in C#...
Wrap your variable in a class and make them static.
Damn, thought this was the VB.NET forum. Do what Lethal said, put them in a Utility class and declare them as static.
-
May 21st, 2003, 11:23 PM
#9
Thread Starter
Frenzied Member
(I was given more time since nobody finished) Thanks Lethal... I still don't grasp all of it though why is the main there? Should I remove the main from the Login Form I have it on?
Do I need to use get and set? I just wanted to be able to Declare something like...
myDictClass myDictionary;
myDictClass2 myOtherDictionary;
int i;
bool FinishProject;
and maybe some initialization as...
FinishProject = false;
Would I need to do the set and get for this too? I am sorry but I really don't get why there isn't a given place on C# to make public variable declarations for all forms in a project.
Thanks again!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 21st, 2003, 11:32 PM
#10
Thread Starter
Frenzied Member
And where should I declare a new instance of the class?
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 22nd, 2003, 12:01 AM
#11
PowerPoster
Code:
namespace MyApplicationNamespace
{
public class GlobalVariables
{
private GlobalVariables
{}
public myDictClass myDictionary;
public myDictClass2 myOtherDictionary;
public int i;
public bool FinishProject;
}
}
You can use them in your code by simply doing this:
Code:
bool myValue = GlobalVariables.FinishProject;
Also, you can check this sample I put together, you can take ideas from it:
http://localhost/VariantXWebSite/Dow...lVariables.zip
-
May 22nd, 2003, 12:23 AM
#12
Thread Starter
Frenzied Member
Thanks, I will try that right now... Please keep in touch if I can't make it work.. 
Isn't it necessary that I declare an instance of the object? will the changes made to this variables will remain persistent while the project is running?
Oh, and I think the link won't work since it says "localhost"... (I already tried it also)
Thanks!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
May 22nd, 2003, 01:00 AM
#13
Thread Starter
Frenzied Member
That worked it out, thanks a lot!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|