Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: All-Topics
I Have one text box in that if enter an value example like this
 
"99" then in second text box it should come as "9+9"=18 output
 
How can i implement this logic in visual basic form please help me
Posted 27-Dec-12 1:41am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Dim i As Integer = 0
For Each digit In (TextBox1.Text)
           i += Val(digit)
       Next
       TextBox2.Text = i.ToString
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
First of all, you need to tag question properly to identify technology you are using.
 
As you stated in your question, it's VB project so you can use Key Up event of textbox to get value and process on it. hope you have idea how to write code to add 9+9 and set in the next text box.
 
best luck
  Permalink  
Comments
charuwaka at 27-Dec-12 7:54am
   
see sir iam developing in windows form application
 
i have two text boxes in first text box i enter "99" and in second text box the output should come as 9+9= "18" that means 18 should come as output in second text box please tell me code.......
@AmitGajjar at 27-Dec-12 8:02am
   
No one will provide code here, you have to atleast try something and post your code.
charuwaka at 27-Dec-12 8:06am
   
Same dialog i gave to one person@ one year ago
@AmitGajjar at 27-Dec-12 8:07am
   
hmm, you know world is very small. your word come back to you again. i suggest you to read first 2-3 chapters of any VB.NET book
charuwaka at 27-Dec-12 8:12am
   
Dim dt As Integer
Dim mt As Integer
Dim yr As Integer
Dim lpn As Integer
 
dt = TextBox4.Text
mt = TextBox5.Text
yr = TextBox6.Text
 
lpn = dt + mt + yr
 
TextBox7.text = Val(lpn)
 

this i tried but i don't know how to separate and add the values in same text box please help me
@AmitGajjar at 27-Dec-12 8:18am
   
let me give you some hint, store value in one variable and get left one character from that, and store in another variable and remove the left one character from first variable. then iterate through until first variable all characters are processed. at last you will have result in your second variable.
 
charuwaka at 27-Dec-12 8:40am
   
answer tho bol dena !!!
 
dekho yeto single line answer ab bathayi ye plssssssssssss
 
pleass tell me i don't understand your content
@AmitGajjar at 27-Dec-12 11:59am
   
sorry dost... agar aaj bata diya to tu kabhi sikh nahi payega(English version : if i give you code today then you will never learn it...)
charuwaka at 28-Dec-12 11:00am
   
then take it this answer i got from vb forums ******
 
Dim i As Integer = 0
For Each digit In (TextBox4.Text + TextBox5.Text + TextBox6.Text)
i += Val(digit)
Next
TextBox2.Text = i.ToString
 
Now what :) ?
 
see iam bigginer u want to help leavindg that u are testing me this is not correct
@AmitGajjar at 28-Dec-12 11:16am
   
you will not realize now but when you come at such position this will not help you. even i used to ask for help but after 1-2 days of brainstorming when i found the answer its really like proud... i want you to feel the same...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Since this sounds a LOT like you homework, I won't give you any code!
 
But it isn't difficult at all:
 
1) Create a "total" variable to hold the result. Set it to zero.
2) Loop though each character in the input string - a For Each loop will do that very easily.
2.1) Check if the character is a digit i.e. '0' to '9'
2.2) If it is, convert it to a numeric value, and add it to your total
2.3) If it isn't, either ignore it, or report the problem and exit the method - your choice.
3) After the loop, set the Text property of teh second text box to the total, using the ToString method.
  Permalink  
Comments
charuwaka at 27-Dec-12 7:51am
   
dear Griff,
 
This isn't my home home work and i am from India in India even in b.tech there in no visual basic concept and they won't home work
 
i have two text boxes in first text box i enter "99" in second text box the output should come as 9+9 = "18" .that means 18 should come as output.please tell me logic pleaseeeeeeeeeeeee
@AmitGajjar at 27-Dec-12 8:03am
   
logic is already given in the solution, you just need to write code. so simple dear.
charuwaka at 27-Dec-12 8:14am
   
Dim dt As Integer
Dim mt As Integer
Dim yr As Integer
Dim lpn As Integer
 
dt = TextBox4.Text
mt = TextBox5.Text
yr = TextBox6.Text
 
lpn = dt + mt + yr
 
TextBox7.text = Val(lpn)
 
i don't Know how to add the value in same text box please help me i don't understand your 1st answer please clearly specify!!!!!!
OriginalGriff at 27-Dec-12 9:37am
   
That is a different question to the one you originally asked, and needs a different answer.
Try:
Dim result As Integer = Integer.Parse(dt) + Integer.Parse(mt) + Integer.Parse(yr)
TextBox7.text = result.ToString()
OriginalGriff at 27-Dec-12 8:06am
   
It doesn't matter where you are from - a simple beginners problem is a simple beginners problem!
 
You have the logic you need - all you have to do is code it.
It is about one line of code per line of text in the logic, so it really, really isn't a complicated job. And you will learn a lot more doing it yourself, than by my writing it down for you! :laugh:
charuwaka at 27-Dec-12 8:38am
   
meeru enduku nannu himsistunnaru dayachesi answer cheppandi
OriginalGriff at 27-Dec-12 9:38am
   
nanu nanu to you too!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 370
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 130
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100