Results 1 to 3 of 3

Thread: [RESOLVED] BigInteger substraction errors

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Resolved [RESOLVED] BigInteger substraction errors

    I want to substract BigInteger value from another BigInteger value, but I´ve got the following errors:

    1.'BigInteger' is a type and cannot be used as an expression.
    2.Syntax error in cast operator; two arguments separated by comma are required.
    3.Value of type 'System.Numerics.BigInteger' cannot be converted to 'String'.

    My code:

    Code:
    Option Strict On
    Imports System.Numerics
    
    Public Class Form3
        Dim number1 As BigInteger
        Dim number2 As BigInteger
        Dim result As BigInteger
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            number1 = CType(TextBox1.Text, BigInteger)
            number2 = CType(TextBox2.Text, BigInteger)
            result = CType(TextBox3.Text, BigInteger)
            result = CType(TextBox1.Text, BigInteger) - CType(Val(TextBox2.Text, BigInteger))
            TextBox3.Text = result
        End Sub
    End Class
    2-why two arguments?
    3-why biginteger isn´t able to handle numbers directly?

    Thanks.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: BigInteger substraction errors

    The second error is due to
    Code:
    CType(Val(TextBox2.Text, BigInteger))
    you shouldn't have the Val bit in there.

    Not sure what you mean about BigInteger not being able to handle numbers directly either.

    That entire bit of code could be simplified to
    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim number1 = CType(TextBox1.Text, BigInteger)
        Dim number2 = CType(TextBox2.Text, BigInteger)
        Dim result = number1 - number2
    
        TextBox3.Text = result.ToString()
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: BigInteger substraction errors

    So it seems like that it´s neccessary to declare the array alogside with biginteger type and requiered component. The other is pretty simple. Now its much more clear. Thanks a lot!

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