B
B
bogdanswag2021-01-18 21:27:48
C++ / C#
bogdanswag, 2021-01-18 21:27:48

How to convert string from textbox to int for further operations?

I'm making a single dice game. an ordinary randomizer in a few lines of code, but very problematic to implement because of the stupidity with the conversion. according to Google's advice, you can convert a variable through Convert.ToInt32(); or via IntParse(); however, this is half the trouble. while entering any number to use the program in the textbox, the program crashes with an exception where it shows me that I'm a moron and my code does not want to convert the string entered into the textbox.
6005d306a2e81514931497.jpeg
the code breaks at this point and no further transformations and operations are performed.
where am i dumb?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fallenyasha, 2021-01-18
@bogdanswag

Int32.TryParse(textBox1.Text, out var text);
Int32.TryParse(textBox2.Text, out var text2);
Int32.TryParse(textBox3.Text, out var text3);

B
bogdanswag, 2021-01-19
@bogdanswag

Now the issue is changing. Tripars really solved the problem, but only partially. My debugger is broken, otherwise I cannot explain that it does not show the sequence of code execution. judging by the fact that the sun highlights the variables after text2 with gray, the code reaches (or bypasses) them. rndv was created to check whether the randomizer works at all and whether the coincidence of text with a random number is real.
600710c37ba1d685344877.jpeg
what is the problem?
the transformation is really happening, otherwise I would not have caught the message boxes that are written in the ifs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question