G+_J. Peter Haliburton Posted March 27, 2014 Share Posted March 27, 2014 I finished watching all the Coding 101 episodes, and jumped into making a GUI program. It doesn't do anything yet, but I was excited to get this much to run. I'll post a link to the code, if I can make it work. Else, expect questions. Link to comment Share on other sites More sharing options...
G+_Dean T Posted March 27, 2014 Share Posted March 27, 2014 Looking forward to seeing you get it finished. Give a shout if you get stuck. Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted March 27, 2014 Author Share Posted March 27, 2014 I'm stuck. Trying to figure out how to read the variable from one text box and then write the calculation result back into another box. It doesn't seem to like anything I did to make it work in the console. Quit button is working, but no solutions on the page refresh yet. I'll pound away at it a bit longer before officially asking for help. Link to comment Share on other sites More sharing options...
G+_Dean T Posted March 27, 2014 Share Posted March 27, 2014 Double click on the calculate button to get up that section of code. Here I am going to assume the box that says length is called TextBox1. The text boxs can only be strings so you need some conversions so play something similar to this. string lengthInput = TextBox1.Text; (This takes the text thats in the text box and puts it in to a string for you) int lengthInt = Int32.Parse(lengthInput); (change this to a float or decimal if needed of course) Now you have your number so also add your calculation code in the same button section youre currently working in. I now assume you have a total value which I will assume is an int called total. Im also assuming calculated textbox is called TextBox2. So you need to change the total to a string and output it to the box like this: TextBox2.Text = total.ToString(); (This simply says what ever is in the second text box equals your total int but in string format. So when you click the calculate button it will take the text from the first box, convert it to an int, float or decimal depending on what your calculation is. Then runs your calculation which you should have a total value which you then convert to a string and it displays in the second box. Link to comment Share on other sites More sharing options...
G+_Dean T Posted March 29, 2014 Share Posted March 29, 2014 Any luck? J. Peter Haliburton Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted March 29, 2014 Author Share Posted March 29, 2014 I didn't get a chance to do any coding yesterday. Today I was working in Linux Mint, and tried to get MonoDevelop running there to play with programming, but it would not work. Guess I'll have to boot back into Windows 7. Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted April 1, 2014 Author Share Posted April 1, 2014 Dean T I tried your suggestions and made things worse. There is something fundamental that I don't know yet. Here is a link to my code. https://github.com/JPHaliburton/Shared/tree/master/HullSpeed Link to comment Share on other sites More sharing options...
G+_Dean T Posted April 1, 2014 Share Posted April 1, 2014 Ah I see where youve went wrong. Youve did the conversion of whats in the text box from within the text box code rather than as part of the button function. I will put up my code and you can compare them. You were not far off. Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted April 1, 2014 Author Share Posted April 1, 2014 I have tried many things. Probably easier to start from scratch at this point, once I understand how it is supposed to work. Link to comment Share on other sites More sharing options...
G+_Dean T Posted April 1, 2014 Share Posted April 1, 2014 Youve just been thinking about it more than you had too. There was too much code for what was needed as the only code that we needed to run was on a single button press. Here is the full solution folder you can open as I dont have github https://www.dropbox.com/s/j8es2g9x7nw177m/HullExample.zip Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted April 1, 2014 Author Share Posted April 1, 2014 Thanks. I can see what was confusing me. The IDE was putting in a lot of stuff that I didn't need. Mostly, "TextChanged" was in the lines where the boxes were designed, and related items were also in the cs file. It is easier to understand what does what in your code. Link to comment Share on other sites More sharing options...
G+_Dean T Posted April 1, 2014 Share Posted April 1, 2014 Yeah there were some text change area put in there thats usually put in if you double click on the text boxes. I just removed those and then put all the code within the button click. I see if kind of like an if statement. If button is clicked then run this code. If button is clicked, take text from box, change to double, do calculation, change to string and put in other text box. Now try and think what you can add to your program for your next challenge :) Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted April 2, 2014 Author Share Posted April 2, 2014 Thanks to Dean T, my program is well underway. It now also checks the input, and writes an error message, if the entry is not what is expected. private void Do_Calculation(object sender, RoutedEventArgs e) { // lwl is a double for use in the sqrt function double lwl; // Check that provided entry is a decimal number bool testIn = double.TryParse(lwlIn_Box.Text, out lwl); if (testIn == false) { error_Alert.Text = ("That was not an acceptable number! Try again."); } // Calculate the maximum speed of the boat rounded to 2 decimal places. double speed = Math.Round(1.34 * Math.Sqrt(lwl), 2); // Write to speed_Box the calculated speed in a string format speed_Box.Text = speed.ToString(); } private void Refresh_Screen(object sender, RoutedEventArgs e) { lwlIn_Box.Clear(); speed_Box.Clear(); error_Alert.Text = (""); } private void Quit_Application(object sender, RoutedEventArgs e) { this.Close(); } Link to comment Share on other sites More sharing options...
G+_Dean T Posted April 2, 2014 Share Posted April 2, 2014 Very good. Youre getting the hang of it I see. Link to comment Share on other sites More sharing options...
G+_J. Peter Haliburton Posted April 3, 2014 Author Share Posted April 3, 2014 The latest code update and the exe file are now available at https://github.com/JPHaliburton/Shared/tree/master/C%23/HullSpeed Link to comment Share on other sites More sharing options...
Recommended Posts