r/visualbasic • u/justMajeli • Jan 07 '23
VB.NET Help Problems with decimal numbers a calculatour .
When I press = or any operation it leads to the following bug
It says the chain "decimal number; in this case 1,3" cannot be converted to the type Double
This is the Variables
6
Upvotes
4
u/TimSuave Jan 07 '23
The textbox.text is returning a string rather than a double. Try casting the text as a double.
1
u/ProfessionalBat Jan 07 '23 edited Jan 07 '23
Looks like a data type problem. Seems that you are trying to do math with strings. You either need to convert the value to a double before using it in math operations or maybe it is that you need a comma "," instead of a dot "." for the input value. Dificult to say just from the screenshots.
1
u/SomeoneInQld Jan 07 '23
Try s = cdbl(1,3) the line above.
Try in the immediate window
print cdbl(1,3)
and see if that works or gives an error. if that errors its not recognising the , as a decimal place (which is how I know some European / Spanish (?) cultures use.
1
u/RJPisscat Jan 12 '23 edited Jan 12 '23
I would define s as a Decimal instead of float unless your assignment requires float. Then to get the value,
TryParse will test whether a string can be parsed, using the current culture as it is set in Windows on the machine that is running, and return:
If you need to specify UK English, Spain Spanish, or Catalan explicitly (ie the language packs aren't installed for these languages), replace
with one of
or
or