dcsimg
Results 1 to 3 of 3

Thread: The value could not be parsed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2018
    Posts
    126

    The value could not be parsed

    I have got error about value could not be parsed with the following code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim str As String
            str = TextBox1.Text
    
            Dim d As BigInteger
            d = 0
            d = evaluate(str)
            Dim vysledok As BigInteger = BigInteger.Parse(d.ToString)
            TextBox2.Text = d.ToString
        End Sub
        Private Function evaluate(ByVal str As String) As BigInteger
            Dim expr As Expression = New Expression(str)
            Dim d1 As BigInteger = BigInteger.Parse(d1.ToString)
            d1 = 0
            d1 = CType(BigInteger.Parse(expr.calculate.ToString).ToString, BigInteger)
            Return d1
        End Function
    I readed on the net that it firsts convert the values to Double and then to BigInteger. But there are .parse and .tostring commands, but it does not work either. Next, negativa values arenīt allowed, but thatīs not that important now. Thanks a lot.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,706

    Re: The value could not be parsed

    What is it with you and CType? You consistently misuse it, and have once again. You seem to expect that it does magic, but it does not.

    I don't know which line is causing you trouble, but the line with CType is messed up, as usual. You call BigInteger.Parse, which would result in a BigInteger, which you then try to turn into a string, then turn back into a BigInteger with CType. This line:

    d1 = CType(BigInteger.Parse(expr.calculate.ToString).ToString, BigInteger)

    does EXACTLY the same thing as this line would:

    d1 = BigInteger.Parse(expr.Caculate.ToString)

    except that the line you have is slower....well, aside from the fact that neither line is likely to work, and failure takes just as long for one as for the other.

    It looks like you are using NCalc, which, once again, won't work for you. However, you used .Calculate where it looks like NCalc would use Evaluate, so perhaps you aren't using NCalc. NCalc won't work for you anyways, because it will fail if you try to pass it a number larger than what would work with a Double, and if you are willing to stay within the size limit on Double, then you might as well just use Double and drop BigInteger entirely.
    My usual boring signature: Nothing

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,403

    Re: The value could not be parsed

    Just like to add,

    Code:
            d = evaluate(str)
            Dim vysledok As BigInteger = BigInteger.Parse(d.ToString)
    evaluate is suppose to return a BigInteger but on the next line you parse "d" to a BigInteger. "d" is already a BigInteger.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width