Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Can't get long integer right!


Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2002, 12:49 AM
vbbisbenc
Guest
 
Posts: n/a
Angry Can't get long integer right!


While I am learning Visual Basic for the first time, I'm having lots of trouble trying to solve a small problem:

I am required to develop a program:

I need to create a class to represent the very large integer of data and the typical operations/methods. It must use a character string to represent the long integer values, including to check any input given to make sure that the character array only contains characters "0 to 9" and the "+" and "-" symbol.

Then, I need to develop an application program that will test the above class by letting a user enter two long integers, and then will output the following results to the user's terminal:

+ The two individual values
+ The result of adding the two values together
+ The result of subtracting the first input from the second input
+ The result of subtracting the second input from the first input

Any help would be much appreciated!

Many Thanks!
Reply With Quote
  #2  
Old 09-02-2002, 12:58 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,885
Default

Do a search on the forum for "string math".
Reply With Quote
  #3  
Old 09-02-2002, 01:45 AM
vbbisbenc
Guest
 
Posts: n/a
Default

Did a search on "string math" but seem can't to find what I am looking for to solve my problem. If you can find a particular discussion anywhere this forum, please give me a link to access the discussion
Reply With Quote
  #4  
Old 09-02-2002, 01:51 AM
Alphanumeric's Avatar
Alphanumeric Alphanumeric is offline
Junior Contributor
 
Join Date: Mar 2001
Location: Canada
Posts: 388
Default

I'm guessing you're a beginner that would like to experiment with the different VB functions.

Rather than trying to apply masks and filters, you should try the actual functions first.

Here's a small brief tutorial.

1) Add two textboxes, call one "txtFirstNumber" and call the other "txtSecondNumber" for example's sake.

2) Add a command button.

3) In the command button's click event, add the following code:
Code:
Dim Result As Integer

Result = txtFirstNumber.Text + txtSecondNumber.Text

MsgBox "The result of " & txtFirstNumber.Text & " + " & txtSecondNumber.Text & " = " & Result
4) Run the program. Enter 5 in the first box, and 6 in the second. Press the command button, and you should get a message box saying "The result of 5 + 6 = 11.".

5) Try changing both "+"'s in the code above to either:

- for subtraction
* for multiplication or
/ for division.
__________________
ALPHANUMERIC
Reply With Quote
  #5  
Old 09-02-2002, 02:44 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,885
Default

In the Code Library is a code example about String Math written by Squirm:
http://www.xtremevbtalk.com/show...threadid=26737
Reply With Quote
  #6  
Old 09-02-2002, 02:50 AM
jayceepoo's Avatar
jayceepoo jayceepoo is offline
Senior Contributor
 
Join Date: Jul 2002
Posts: 1,021
Default

To make a correction to Step 4 of Alphanumerics post:

That answer will give a messagebox saying: "The result of 5 + 6 = 56"

If you want to add the numeric values in the text boxes, do
val(txtFirstNumber.text) + val(txtSecondNumber.text)
__________________
Jayceepoo

"I recently went to a new doctor and noticed he was located in something called the Professional Building. I felt better right away." - George Carlin
Reply With Quote
  #7  
Old 09-02-2002, 05:12 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

While that will work, it is not what the poster wanted. vbbisbenc is writing a string math class to deal with very large numbers, larger than an Integer could handle.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->