Posted March 4, 2020 Hi, i am attempting to convert a text box on a winForm into string so i can display the results on a message box. i have treid to convert to string using the code seen bellow however to no avail. anyone got any tips? surname = Convert.ToString(textBoxText.Text); Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 the .text property is a string. Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 You should probably declare some blank variables, use the text box to set the variable then just call the variable as the message box content Main Rig:- Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS | Server:- Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0) Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 Author 22 minutes ago, Master Disaster said: You should probably declare some blank variables, use the text box to set the variable then just call the variable as the message box content how do you call the variabe from a messgae box? Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 You should honestly start with console applications. You seems to have lots of very very basic issues which are all covered in basic console programming. You are currently trying to run before learning to walk. Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 48 minutes ago, Daniboi said: how do you call the variabe from a messgae box? That was probably a typo. You can't "call" variables. You pass them into methods as arguments when you call those. Meaning you create a message box, then use the text from from your text box to set the message box text before you open it. string caption = "Hello"; string message = textBoxText.Text; MessageBoxButtons buttons = MessageBoxButtons.YesNo; MessageBox.Show(message, caption, buttons); Remember to either quote or @mention others, so they are notified of your reply Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 Author 3 hours ago, Franck said: You should honestly start with console applications. You seems to have lots of very very basic issues which are all covered in basic console programming. You are currently trying to run before learning to walk. i have done console stuff but my class moved on Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2020 Author 3 hours ago, Eigenvektor said: That was probably a typo. You can't "call" variables. You pass them into methods as arguments when you call those. Meaning you create a message box, then use the text from from your text box to set the message box text before you open it. string caption = "Hello"; string message = textBoxText.Text; MessageBoxButtons buttons = MessageBoxButtons.YesNo; MessageBox.Show(message, caption, buttons); so how can i get this to work? string surname = textBoxText.text MessageBox.Show("The total cost is " + cost.ToString("c") + " and the amount you're ordering is " + quanty + " the colour is " + colour + "and the fabic is "+fabType+" You should collect it on the " + date + ".When collecting please refer to the surname which is" + surname); for me it comes up blank Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 5, 2020 9 hours ago, Daniboi said: so how can i get this to work? string surname = textBoxText.text MessageBox.Show("The total cost is " + cost.ToString("c") + " and the amount you're ordering is " + quanty + " the colour is " + colour + "and the fabic is "+fabType+" You should collect it on the " + date + ".When collecting please refer to the surname which is" + surname); for me it comes up blank What do you mean by "blank"? Are you trying to say the message box is empty? Cause that seems unlikely. Or are you trying to say the surname is an empty string? In that case I would suspect the text box you're trying to get the text from and the message box on your UI you've entered text into are not the same. Maybe share a bit more of your actual code, because it's really hard to guess at what you're doing with such a small snippet. Remember to either quote or @mention others, so they are notified of your reply Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now