|
-
Jun 18th, 2004, 01:51 AM
#1
Thread Starter
Registered User
how to add in textbox?[resolve]
hi its me again asking stupid question.
just forgive me...i would like to ask this question hanging in my head...
how to add in the textbox?
for example when the user input 8+ 2 and press "enter" it gives a value of 10.
a sort of simple calculator..
thanks in advance..
Last edited by LoNeR; Jun 19th, 2004 at 02:44 AM.
-
Jun 18th, 2004, 04:47 AM
#2
Hyperactive Member
-
Jun 18th, 2004, 05:17 AM
#3
PowerPoster
Originally posted by Libero
Tetxbox1.Text = 8+2
Sorry but that is dangerous. It only works if Option Strict is Off.
Use
Textbox1.Text =str(8+2)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 07:49 AM
#4
Hyperactive Member
I think you need something like that:
Code:
Dim i As Byte
Dim str As String = TextBox2.Text
Dim car As Char
While i < str.Length
car = str.Chars(i)
If Char.IsSymbol(car) Then
Dim str1 As String = str.Substring(0, i)
Dim str2 As String = str.Substring(i + 1)
Dim dec1 As Decimal = Decimal.Parse(str1)
Dim dec2 As Decimal = Decimal.Parse(str2)
Dim res As Decimal
Select Case car
Case Is = "+"
res = dec1 + dec2
Case Is = "-"
res = dec1 - dec2
Case Is = "/"
res = dec1 / dec2
Case Is = "*"
res = dec1 * dec2
End Select
str = res.ToString
Exit While
End If
i += 1
End While
TextBox2.Text = str
End Sub
It's not fully tested and you have to be careful !!
With more time, it's possible do better, obviously
Good job
Live long and prosper (Mr. Spock)
-
Jun 18th, 2004, 08:46 AM
#5
Frenzied Member
VB Code:
Dim ans as integer 'or long, double, etc
ans = 8 + 2
Textbox1.Text = Cstr(ans)
-
Jun 18th, 2004, 09:00 AM
#6
PowerPoster
Hi alextyx,
WOW! Do you use sledgehammers to crush olives over there
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 09:11 AM
#7
Hyperactive Member
Hi Taxes, happy to see you again
Really, probably I miss the request, it's always the same problem with language I think. You have not idea in how many threads I don't dare to enter, bacuase I'm not sure about the request.
Anyway, I think Loner wants to put its enter in a textbox and then have the result in another or in the same textbox, but also writing its entire formula in a textbox, too!!!
So you can't start from 8+2 but from the string "8+2" (Textbox2.text in my example) . Meet the difference and let me know your impression
If, once again, I missed the request.....then
Loner, which was your request?
Live long and prosper (Mr. Spock)
-
Jun 18th, 2004, 09:29 AM
#8
PowerPoster
Hi alextyx,
You may have a point. In which case:
textbox1.text=str(val(textbox2.text)+val(textbox3.text))
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 09:47 AM
#9
Hyperactive Member
Perhaps taxes, but I understood Loner wanted to write its formula, using a single textbox like the display of a calculator!
This is the problem!
If you use two textboxes for your input, then you have to use a button to define which kind of operation you want to perfom: adding, multipling, ecc.... isn't it?
I think the problem was:
I have in my textbox1.text (I use textbox2, to be original )the string "8+2" or "12,3*4" or...so on. Give me the result!
Obviously if I'm the only who thought so, among many english people, probably I was wrong, but my approach is for that kind of problem.
Live long and prosper (Mr. Spock)
-
Jun 18th, 2004, 10:02 AM
#10
PowerPoster
Hi alextyx,
Yes. Valid comment and quite right. The problem you then have is the "Rules of Arithmetic".
I think I will just use a calculator
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 10:19 AM
#11
Hyperactive Member
-
Jun 18th, 2004, 10:49 AM
#12
PowerPoster
That's not a bad idea. My favourite singer is Paverotti (I've even named my Rottweiller after him ) and I can't understand a word he sings.
Wait a minute... do you mean the Latin I learned at school is no good over there now
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 11:29 AM
#13
Hyperactive Member
First lesson: PavArotti not PavErotti!
About latin....uhm...I don't know if it's useful know, perhaps it depends on the last Latin Service Pack you installed. If you kept your language system upgraded until the 16th century's releases, it should be good enough!
bye
Live long and prosper (Mr. Spock)
-
Jun 18th, 2004, 04:59 PM
#14
PowerPoster
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 08:50 PM
#15
Thread Starter
Registered User
halu guys thanks for the great idea and suggs..
Perhaps taxes, but I understood Loner wanted to write its formula, using a single textbox like the display of a calculator!
This is the problem!
yes your right alex...i want the user to input any no. in the single textbox add,mul,div or sub... and when he press the enter key it gives a sufficient answer...
simple calculator...
tanx guys..
-
Jun 19th, 2004, 12:40 AM
#16
Fanatic Member
perhaps this.
VB Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim re As New Regex("\d+\s*(\*|\/|\+|\-)\s*\d+")
If Not (re.Match(TextBox1.Text)).Success Then
MessageBox.Show("invalid")
Else
Dim arr() As String = Regex.Split(TextBox1.Text, "\s*[*,/,+,-]\s*")
If (Regex.Match(TextBox1.Text, "\s*\+\s*")).Success Then
TextBox1.Text = Integer.Parse(arr(0)) + Integer.Parse(arr(1))
ElseIf (Regex.Match(TextBox1.Text, "\s*\-\s*")).Success Then
TextBox1.Text = Integer.Parse(arr(0)) - Integer.Parse(arr(1))
ElseIf (Regex.Match(TextBox1.Text, "\s*\/\s*")).Success Then
TextBox1.Text = Integer.Parse(arr(0)) / Integer.Parse(arr(1))
ElseIf (Regex.Match(TextBox1.Text, "\s*\*\s*")).Success Then
TextBox1.Text = Integer.Parse(arr(0)) * Integer.Parse(arr(1))
End If
End If
End If
End Sub
i don't know if this is the efficient one.
-
Jun 19th, 2004, 01:15 AM
#17
Thread Starter
Registered User
tanx monk...it really helps..
more power...
BTW what is this???
Usa ako ka tawo. Bakakon nga tawo.
Di ka kauyon nako pero usahay
ako ang tao nga imong mauyonan. Ngano?
Diman gud ko mosulti sa tinuod.
-
Jun 19th, 2004, 01:19 AM
#18
Fanatic Member
it means.
i'm a person, a dishonest one.
you won't like me but sometimes
you like me most. why?
cause i don't tell the truth exactly.
it's a bisayan phrase. my native tongue.
-
Jun 19th, 2004, 01:49 AM
#19
Thread Starter
Registered User
Originally posted by brown monkey
it means.
it's a bisayan phrase. my native tongue.
thanks monk...
im just curious and a stupid one..
-
Jun 19th, 2004, 02:55 AM
#20
Hyperactive Member
-
Jun 19th, 2004, 03:04 AM
#21
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
|