473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to add numbers in a textbox

Hi...
How to add 4+6 when you use two textbox, the first textbox is for the input and the other one if for the output..
Oct 5 '07 #1
11 16426
debasisdas
8,127 Expert 4TB
As you have posted a question in the articles section it is being moved to Visual Basic Forum.

MODERATOR.
Oct 5 '07 #2
creative1
274 100+
Spit the string(4+6) and store in two variables. then add them and display result in other textbox.
Oct 5 '07 #3
jrtox
89
What if 2+3+3-4.?
Very wise using 1 txtbox only.
Oct 5 '07 #4
Ali Rizwan
925 512MB
Hi...
How to add 4+6 when you use two textbox, the first textbox is for the input and the other one if for the output..
Try this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub command1_click()
  3.  
  4. text2.text= val(text2) + val(text1)
  5. text1.text=""
  6.  
  7. end sub
  8.  
  9.  
Now every time you enter a value in text1 it will added to previous one.
This code is for Adding.
You can made for subtraction yourself.

GOODLUCK
ALI
Oct 5 '07 #5
jrtox
89
Try this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub command1_click()
  3.  
  4. text2.text= val(text2) + val(text1)
  5. text1.text=""
  6.  
  7. end sub
  8.  
  9.  
Now every time you enter a value in text1 it will added to previous one.
This code is for Adding.
You can made for subtraction yourself.

GOODLUCK
ALI

That will do,
but as i understand the post.
the problem is, Text1 is only for Input like 6+4.
and and text2 is for output like the answer 10.

not text1.text which is 6 plus(+) text2.text which is 4
Oct 5 '07 #6
Hi...
How to add 4+6 when you use two textbox, the first textbox is for the input and the other one if for the output..
Tell your problem clearly.
How will you give input?

If you give the input 4 in Text1 and 6 in Text2 following code works well
Expand|Select|Wrap|Line Numbers
  1. Text1.Text=val(Text1.Text)+val(text2.text)

If you give the input 4+6 in Text1 and nothing in Text2 then following code works well
Expand|Select|Wrap|Line Numbers
  1. i=1
  2. c=0
  3. Do While c=0
  4. If (i=Len(Trim(Text1)) Then
  5.    Exit Do
  6. End If
  7. If (mid(Text1,i,1)='+' ) Then
  8.    Text2=val(mid(Text1,1,i-1))+val(mid(Text1,i+1)
  9.    c=1
  10. End If
  11. i=i+1
  12. Loop
  13.  
Waiting for ur reply
Oct 5 '07 #7
Kosmos
153 100+
Just checking...you're talking about VBA correct? or actual VB?
Oct 5 '07 #8
kadghar
1,295 Expert 1GB
Hi...
How to add 4+6 when you use two textbox, the first textbox is for the input and the other one if for the output..
write a code that searches character by character for numbers and signs, the easiest example would be with a couple of arrays something like this

Expand|Select|Wrap|Line Numbers
  1. public function Maths(byval Str1 as string) as double
  2. dim i as integer
  3. dim j as integer
  4. dim k as integer
  5. dim Int1 as integer
  6. dim Str2 as string
  7. dim Arr1() as double 'lets store here the numbers
  8. dim Arr2() as integer 'and here the operators (1 for sum, 2 for diference)
  9. j=0
  10. k=0
  11. redim arr1( j )
  12. for i = 1 to len(str1)
  13.     int1=asc(mid(str1,i,1))
  14.     if (int1 >= 48 and int1 <= 57) or int1 = 46 then str2 = str2 & chr(int1)
  15.     if int1= 43 or int1 = 45 then
  16.         redim preserve arr2 (k)
  17.         arr2(k) = int(int1/2)-20
  18.         arr1(j) = str2
  19.         str2 = ""
  20.         k=k+1
  21.         j=j+1
  22.         redim preserve arr1(j)
  23.     end if
  24. next
  25. arr1(j) = str2
  26. maths = arr1(0)
  27. for i = 1 to ubound(arr1)
  28.     if arr2(i-1) = 1 then
  29.         maths = maths + arr1(i)
  30.     else
  31.         maths = maths - arr1(i)
  32.     end if
  33. next
  34. end function
That'll be the main idea
Just make sure not to use negative numbers HTH
Oct 5 '07 #9
Killer42
8,435 Expert 8TB
I believe you can also use the Microsoft Script Control to evaluate an expression in a string, like that. Try a search here, as it has been covered before.
Oct 5 '07 #10
Just checking...you're talking about VBA correct? or actual VB?
Shall i know whats VBA???
Oct 6 '07 #11
Killer42
8,435 Expert 8TB
Shall i know whats VBA???
Visual Basic is a complete development environment and language, including a compiler to produce applications in Exe form, or DLLs.

Visual Basic for Applications (VBA) is a "trimmed down" version of the language built into various products (possibly just the MS Office product?) as a scripting language.
Oct 7 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Supra | last post by:
how do i get 2 different number in same row? using random example: 4 2 5 6 7 4 1 7 9 8 3 3 <===== i want different number but not same as opposite 8 5
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
1
by: Luzuko | last post by:
I would like to know how can i restrict textbox input in VB.net using code instead of VB.net controls. e.g If i want a user to type numbers only in a textbox(ID number textbox), how can i make...
2
by: Vbbeginner07 | last post by:
Hi all Wonder if anyone can help me out to solve this: please find the code of textbox that accepts only characters and one textbox that accepts only numbers: (vb) textbox for accepting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.