umerh Posted June 23, 2004 Share Posted June 23, 2004 Hello guys. I am a new VB.NET -> C# developer. I have 2 questions: 1. Is there anything equivilant to a Module File(vb.net) in C#. 2. I want to make a textbox such that it does not take any character except numbers. I dont want it to take abc. i want it to take 123. so can anyone help me. Umer. Link to comment Share on other sites More sharing options...
0 smurfiness Posted June 23, 2004 Share Posted June 23, 2004 If you want a textbox to accept only numbers, handle the KeyDown event and check the input, change e.Handled to false to ignore the character. A C# source file is the same as a module file in VB. Link to comment Share on other sites More sharing options...
0 +chorpeac MVC Posted June 23, 2004 MVC Share Posted June 23, 2004 If you want a textbox to accept only numbers, handle the KeyDown event and check the input, change e.Handled to false to ignore the character.A C# source file is the same as a module file in VB. agreed Link to comment Share on other sites More sharing options...
0 Steven Posted June 23, 2004 Share Posted June 23, 2004 If you want a textbox to accept only numbers, handle the KeyDown event and check the input, change e.Handled to false to ignore the character.A C# source file is the same as a module file in VB. Hrmm in VB6 you could use the isNumeric Bool does .NET have anything equal to this? :unsure: Link to comment Share on other sites More sharing options...
0 umerh Posted June 23, 2004 Author Share Posted June 23, 2004 look by module file i mean. I want to make a Global Variable so what keywords should i use to make it available through out the project. Umer Link to comment Share on other sites More sharing options...
0 smurfiness Posted June 23, 2004 Share Posted June 23, 2004 C# does not have global variables. Everything must be a member of a class. Link to comment Share on other sites More sharing options...
0 dacris2000 Posted June 23, 2004 Share Posted June 23, 2004 umerh, you can create a class that contains only static members (keyword static). That would be equivalent to making a module. Example: public class SomeGlobalStuff { public static void GlobalMethod(int something) { //do something here } public const int GlobalConstant = 0; public static int GlobalVariable = -1; public static readonly int GlobalConstant = 2; // another way to declare a constant } And then in your program you just call the stuff as such: SomeGlobalStuff.<member name> Thus, you don't need to create a new instance of SomeGlobalStuff to use the stuff in it. Link to comment Share on other sites More sharing options...
0 umerh Posted June 23, 2004 Author Share Posted June 23, 2004 thanks dacris2000. u solved my prob. but its not exactly the solution. Now i have a class called "My" and now i have the global variables in it. Thanks for the help guys. Umer. Link to comment Share on other sites More sharing options...
0 Sn1p3t Posted June 24, 2004 Share Posted June 24, 2004 Hrmm in VB6 you could use the isNumeric Bool does .NET have anything equal to this? :unsure: public static bool IsNumeric(Object Input) { ? bool returnValue = true; ? try { ? ? ?Decimal.Parse(Input); ? } catch { ? ? ?returnValue = false; ? } ? return returnValue; } Don't know if that'll work, but:Dt should :D Link to comment Share on other sites More sharing options...
0 umerh Posted June 24, 2004 Author Share Posted June 24, 2004 guys i did that number thing with APIs. I got some code from the internet is it safe to use Windows APIs in C# using InteropServices ??? Umer Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted June 24, 2004 Share Posted June 24, 2004 guys i did that number thing with APIs.I got some code from the internet is it safe to use Windows APIs in C# using InteropServices ??? Umer It is safe, but why would you need to do it that way? You can use the Microsoft.VisualBasic.Information namespace which contains an IsNumeric method. http://msdn.microsoft.com/library/default....ctisnumeric.asp Link to comment Share on other sites More sharing options...
0 umerh Posted June 25, 2004 Author Share Posted June 25, 2004 with APIs whenever i try to input a non numeric character, the XP ballon pops up and it says "Unacceptable Character" Umer. Link to comment Share on other sites More sharing options...
0 STV Posted June 27, 2004 Share Posted June 27, 2004 this is a quick way of doing the same thing in C#. lets say that i have a text box called "TextBox_PhoneNumber" and i want the text box to ignore letters. i just use the KeyPressed event and the e.Handle property to do it. in the follow code, the value of e.Handle is determined by whatever bool value "Shared.CheckTextBox_Letter()" returns, true or false. private void TextBox_PhoneNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) ? ?{ ? ?e.Handled = Shared.CheckTextBox_Letter(TextBox_PhoneNumber,e.KeyChar); ? ?}//end of TextBox_PhoneNumber_KeyPress() i have it set up so that whatever character type (symbol, letter, number, whitespace) i want to ignore i just use one of the various methods that i have created for myself. they are in a class that i call "Shared" and they are: - bool CheckTextBox_Number(string str, char ch) - bool CheckTextBox_Letter(string str, char ch) - bool CheckTextBox_Symbol(string str, char ch) - bool CheckTextBox_WhiteSpace(string str, char ch) looking back on the code above, if the user does type in a letter, the "e.KeyChar" property will have that letter stored in it. i send it through the "CheckTextBox_Letter()" method and it checks to see if that is a letter or not. if it is a letter, the methods returns true, if it is not a letter, the method returns false. remember that if "e.Handle" is set to true, it will be "handled" and thus will be ignore and not displayed. i know that the above methods and the approach is not efficient, but for the sake of explaination, ill just use those as an example. umerh, i hope that this helps you, STV Link to comment Share on other sites More sharing options...
Question
umerh
Hello guys. I am a new VB.NET -> C# developer.
I have 2 questions:
1. Is there anything equivilant to a Module File(vb.net) in C#.
2. I want to make a textbox such that it does not take any character except numbers. I dont want it to take abc. i want it to take 123. so can anyone help me.
Umer.
Link to comment
Share on other sites
12 answers to this question
Recommended Posts