|
-
Dec 27th, 2012, 08:57 AM
#1
Thread Starter
Junior Member
[RESOLVED] How to add a value in same text box ?
i made two text boxes and a button in windows form application VS2010
in that i enter a value ex: "24" in first text box
when i press the button the ouput should come as 2+4 ="6" i.e 6 should come as out put in second text box how can i do that .please tell me the logic in code format . i tried this but stuck in implementing logic
Code:
Public Class Form1
Private Sub KryptonButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton2.Click
Dim ftn as integer
dim stn as integer
ftn = TextBox1.Text
stn= val(ftn)
stn = TextBox2.Text
End Sub
End Class
please tell me the code !!!!
Last edited by charuwaka; Dec 27th, 2012 at 09:15 AM.
-
Dec 27th, 2012, 09:32 AM
#2
Re: How to add a value in same text box ?
Is the intention to add all the digits of the number whatever its size? So 23456 would be 16, for example? In that case you need to split the text into single digits.
vb.net Code:
Dim i As Integer = 0
For Each digit In TextBox1.Text 'takes advantage of nature of string as char array
i += Val(digit)
Next
TextBox2.Text = i.ToString
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 27th, 2012, 09:58 AM
#3
Re: How to add a value in same text box ?
 Originally Posted by charuwaka
i made two text boxes and a button in windows form application VS2010
in that i enter a value ex: "24" in first text box
when i press the button the ouput should come as 2+4 ="6" i.e 6 should come as out put in second text box how can i do that .please tell me the logic in code format . i tried this but stuck in implementing logic
Code:
Public Class Form1
Private Sub KryptonButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton2.Click
Dim ftn as integer
dim stn as integer
ftn = TextBox1.Text
stn= val(ftn)
stn = TextBox2.Text
End Sub
End Class
please tell me the code !!!!
And what would you do if the user entered 124, do you splut to 12+4 or 1+24. Think past smaller size values.
-
Dec 28th, 2012, 12:48 AM
#4
Re: How to add a value in same text box ?
try this:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As Integer
If Integer.TryParse(TextBox1.Text, value) Then
Dim numbers() As Integer = Array.ConvertAll(TextBox1.Text.ToArray, Function(c) CInt(c.ToString))
Label1.Text = String.Join("+", Array.ConvertAll(numbers, Function(x) x.ToString)) & "=" & numbers.Sum.ToString
Else
Label1.Text = ""
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 28th, 2012, 01:13 AM
#5
Thread Starter
Junior Member
Re: How to add a value in same text box ?
see if user inputs values like 99 then 9+9=18 and 123 then 1+2+3=6 like this anything enters it is converted pls tel the code now
-
Dec 28th, 2012, 09:04 AM
#6
Thread Starter
Junior Member
Re: How to add a value in same text box ?
Not like that when i enter 16 then it should come as 1+6=7 and 256 then 2+5+6=13 like that out put should come
-
Dec 28th, 2012, 09:11 AM
#7
Thread Starter
Junior Member
Re: How to add a value in same text box ?
Thank You Very much my problem solved
-
Dec 28th, 2012, 09:25 AM
#8
Re: How to add a value in same text box ?
 Originally Posted by charuwaka
Thank You Very much my problem solved
Was it solved using the code paul provided? Do you understand what HIS code does?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|