I'm relatively new to VB, and I'm coding a graphing calculator to familiarize myself with it. I haven't figured out how to to the x^n function yet though.
I made a function to retrieve a certain number from a text box, where the first character is "^", and the second/second and third are numbers.
An example of this not working is: 2^2 = 1.12589990684262E+15 (Where tbNum1 is "2" and tbOpr is "^2"
Here is my code for the entire function:
Thanks guys, this really has stumped me.Code:'tbopr IS WHERE THE SPECIFIED POWER GOES (x^n) 'tbNum1 IS THE FIRST NUMBER, WHICH IS RAISED TO THE POWER "p" 'tbCalcOut IS THE TEXT BOX THE ANSWER IS OUTPUTTED TO, AND THE NUMBER THAT IS RAISED TO _ 'THE POWER "p" IF IT ISN'T EQUAL TO 0. Private Function Power() Dim p As Integer = 1 If Len(tbOpr.Text) = 2 Then p = Convert.ToInt16(GetChar(tbOpr.Text, 2)) ElseIf Len(tbOpr.Text) = 3 Then p = Convert.ToInt16(GetChar(tbOpr.Text, 2) & GetChar(tbOpr.Text, 3)) Else MsgBox("Power is too high.", , "Error") End If If tbCalcOut.Text <> "" And tbCalcOut.Text <> "0" Then tbNum1.Text = tbCalcOut.Text tbCalcOut.Text = tbNum1.Text ^ p ElseIf tbCalcOut.Text = "0" Or tbCalcOut.Text = "" And tbNum1.Text <> "" And _ tbNum1.Text <> "0" Then tbCalcOut.Text = tbNum1.Text ^ p End If End Function




Reply With Quote
