Solved

multiply extremely large numbers

Posted on 2003-12-04
11
440 Views
Last Modified: 2010-05-01
Hello Experts,

I am trying to find a way to multiply EXTREMELY large numbers( answers with more than a million numbers ) the answer should be written into an txt file. VB itself can only calculate small numbers or else it will start with things like: E+54 .

i found some source code on planet source code but it's maximum was about 150 numbers.

Greets Erik
0
Comment
Question by:WarLord
  • 2
  • 2
  • 2
  • +3
11 Comments
 
LVL 5

Expert Comment

by:mccainz2
ID: 9875616
My suggestion , dont use VB for this
Try FORTRAN.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9875669
You only could store until double values in a variable, and the result should be a double too. It hasen't to do on how much digits but how large is the number you are trying to manage.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9875680
See this:


Double data type
A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 100

Expert Comment

by:mlmcc
ID: 9875762
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 9875780
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9875888
"more than a million numbers"
maybe I read this question incorrectly but I'm assuming he meant a million places in the number in which you would never want to use vb in any form or fashion to do this. Those are really LARGE numbers.
0
 
LVL 3

Accepted Solution

by:
Hornet241 earned 125 total points
ID: 9878080
Here is an sort of answer, it works for numbers that I check using a calculator anything larger will have to be checked by hand.

create a project with 3 textboxes and a command button, copy this into the onclick of the command button

Private Sub Command1_Click()

If Len(Text2.Text) > Len(Text1.Text) Then
    num1 = Text1.Text
    num2 = Text2.Text
  Else
    num1 = Text2.Text
    num2 = Text1.Text
End If

For a = Len(num1) To 1 Step -1
  rNum1 = CInt(Mid(num1, a, 1))
  For b = Len(num2) To 1 Step -1
    rNum2 = CInt(Mid(num2, b, 1))
    result = (rNum1 * rNum2) + remainder
    tmpAns = result Mod 10
    remainder = (result - (result Mod 10)) / 10
    tStrAns = Trim(Str(tmpAns)) & num4
    num4 = tStrAns
  Next b
  If remainder > 0 Then
    num4 = Trim(Str(remainder)) & num4
  End If
  num4 = num4 & String(Len(num1) - a, "0")
  num3 = Text3.Text
  remainder = 0
  Select Case Len(num3) - Len(num4)
    Case Is < 0
      ans1 = String(Len(num4) - Len(num3), "0") & num3
      ans2 = num4
    Case Is = 0
      ans1 = num3
      ans2 = num4
    Case Is > 0
      ans1 = num3
      ans2 = String(Len(num3) - Len(num4), "0") & num4
  End Select
 
  For c = Len(ans1) To 1 Step -1
    aNum1 = CInt(Mid(ans1, c, 1))
    aNum2 = CInt(Mid(ans2, c, 1))
    result = (aNum1 + aNum2) + remainder
    tmpAns = result Mod 10
    remainder = (result - (result Mod 10)) / 10
    tStrAns = Trim(Str(tmpAns)) & StringAns
    StringAns = tStrAns
  Next c
  If remainder > 0 Then
    StringAns = Trim(Str(remainder)) & StringAns
  End If

  Text3.Text = StringAns: StringAns = "": num4 = "": remainder = 0
Next a
MsgBox "Done"

End Sub
0
 

Author Comment

by:WarLord
ID: 9883124
@Hornet241

you program works but when i take very large numbers i get an type mismatch
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 9924063
Where does the mismatch occur?
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10267461
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered Hornet241
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 418
vb6 connector to SQL Server 2 37
Added a column screws up code 5 57
VB6 ListBox Question 4 44
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question