Tuesday, July 14, 2009

Writing C# in Microsoft Visual Studio?

I have set up a form in Microsoft Visual Studio and have a text box where a user would input a number and I need to take this number and do calculations with it. My question is: How can I read the number that they type in the text box? I keep getting build errors saying that it can't chnage it from double to boolean, but if I have it declared as a boolean, then I can't do mathematical calculations with it. Any suggestions?

Writing C# in Microsoft Visual Studio?
99% of the time when you get the "cannot convert to boolean" error, it means you're using the wrong evaluation...





this code: if (myText.Text = "5") response.write("test");


will give the boolean error.





you want to use (myText.Text == "5") response.write("test");





Check that - I'd bet almost anything that's your problem.
Reply:You cant actually write C(+(++)) in Visual Basic, you need a compliler then you can build sub routines to jump in and out of the C
Reply:Parse the textbox text it to an integer. I'm not sure how to do it in c# then write your calculation code. Booleans are for yes no true false so you wondn't want to use it in calculations. keep everything double.








Microsoft Visual Studio 2005 Help Group


http://tech.groups.yahoo.com/group/Micro...
Reply:try {


if(txtMyTextBox.Text != string.Empty) {


int Number = int.Parse(txtMyTextBox.Text);


}


}


catch (FormatException ex){


//string cannot be casted to integer - take appropriate action


}


catch (OverflowException ex){


//an overflow occured - take appropriate action


}





if you want to read the string into a double use the Double.Parse (String) instead of int.Parse(String) method.





Hope this helps
Reply:It's difficult to say what your problem is without seeing code, but I'd say you're trying to perform a boolean operation on a double, which isn't allowed. It's not telling you to use booleans, it's telling you that you're trying to convert a double to a boolean and it can't do that.
Reply:ANSWER: DO NOT USE C#


Using Microsoft software is always a terrible thing to do. It is best to avoid it if possible. In several years... no one will want to own a computer with Windows on it (due to Vista and is DRM) so why on earth would you want to program in a language that will only run on a Windows machine?!





Instead try learning a useful programming language like Java or Ruby. Hell even C++ is better than C#.


If you are using Java I would recommend using Eclipse as IDE.





If you are using Ruby... Emacs would probably work the best. But I also kind of like SubEthaEdit

survey results

No comments:

Post a Comment