Results 1 to 5 of 5

Thread: [RESOLVED] Can't seem to retrieve a specified character from a string of numbers

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    22

    Resolved [RESOLVED] Can't seem to retrieve a specified character from a string of numbers

    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:

    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
    Thanks guys, this really has stumped me.
    Last edited by DinosaurusRex; Oct 25th, 2013 at 04:26 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width