Thanks for the reply but would you be so kind to elaborate further?The Text of a TextBox is a String. You can call String.Split to split on the division operator and get the two numeric values. Convert them both to actual numbers and then perform the division.
One thing to keep in mind is the possibility of bad input from the user and before doing any math on anything gotten from the textbox you should make sure what they put in can be converted to a decimal and you can use Decimal.TryParse() for that after splitting the string on the "/" character:Almost made me mad for you to post a reply like that. Old Dog and new tricks related LOL. But I stand corrected! I actually way over thought that code and since you really made me mad(LOL) I found the solution to be way more easy.
In case someone looks at this. Here you go.
Dim str = TbResult.Text
Dim split = str.Split("/")
Dim numerator As String
Dim denominator As String
If (split.Count = 2) Then
numerator = split(0).ToString()
denominator = split(1).ToString()
TbDecimalFromFract.Text = numerator / denominator
End If
I know this can be converted but in this case there is no need.
THANK YOU!!
Dim Fraction As String() = TbResult.Text.Trim().Split("/"c) If Fraction.Length = 2I Then Dim Numerator, Denominator As Decimal If Decimal.TryParse(Fraction(0I), Numerator) Then If Decimal.TryParse(Fraction(1I), Denominator) Then TbDecimalFromFract.Text = (Numerator / Denominator).ToString() Else TbDecimalFromFract.Text = "Invalid Denominator" End If Else TbDecimalFromFract.Text = "Invalid Numerator" End If End If
One thing to keep in mind is the possibility of bad input from the user and before doing any math on anything gotten from the textbox you should make sure what they put in can be converted to a decimal and you can use Decimal.TryParse() for that after splitting the string on the "/" character:
Dim Fraction As String() = TbResult.Text.Trim().Split("/"c) If Fraction.Length = 2I Then Dim Numerator, Denominator As Decimal If Decimal.TryParse(Fraction(0I), Numerator) Then If Decimal.TryParse(Fraction(1I), Denominator) Then TbDecimalFromFract.Text = (Numerator / Denominator).ToString() Else TbDecimalFromFract.Text = "Invalid Denominator" End If Else TbDecimalFromFract.Text = "Invalid Numerator" End If End If