-
June 13th, 2002, 03:46 AM
#1
Executing code
I have "1+1" in my text1, how to make text1 = "2" now? I tried cint(text1), type mismatch. Of course, I can get all the integers using instr and add them using standard variables, but is there anyway to execute the code in textbox? Example: if I have "10-4+6" it would give me "12", or if I have "10/5+5" it would give me "7". There has got to be a function to perform this task. Thanks.
-
June 13th, 2002, 04:25 AM
#2
Regards
Debashish Chakrabarty
SCJP
******************************
Cool Site for SCJP aspirants at:
http://www.geocities.com/wahjava
******************************
-
June 13th, 2002, 05:01 AM
#3
Is there anyway to do this without a control?
-
June 13th, 2002, 06:29 AM
#4
Text1.Text = 10 - 4 + 6
If Text1.Text = "12" Then
MsgBox "Text1 = 12"
End If
Text1.Text = 10 / 5 + 5
If Text1.Text = "7" Then
MsgBox "Text1 = 7"
End If
End Sub
Cubbie
-
June 13th, 2002, 06:00 PM
#5
Haven't got time to code it all up for you, but I'd use something like this:
Grab string from textbox
Create array of special characters ( * / + - () ) etc
Begin Loop
Check first character of textbox, if its numeric or - (for negative numbers) keep checking until you hit one of the special characters. When you hit that character, convert the previous x characters into a double, and store in an array.
Store the next character (the operator) in another array and keep checking the string until you get to the next special character or the end of the string
End Loop
This is where it will be slightly more difficult.....trying to work out your precedence.
Begin Loop
Run through your Operator array looking for your first operation (ie brackets) Store that index in nDx(0). Store the length in characters of the NUMBER (nDxLen(0)). If the first operator isn't found, then run through again looking for the second operator(s) ( * or / ) etc etc.
End Loop
Now you start to do the calculations.
Begin Loop
Get the index number of your first operator in its own array, take x from that number to get the index (where x is stored in nDxLen(0). Get the first operator (unless the first operator is a "(") and search through for the second number. etc etc
End Loop
Apologies if this isn't too clear - I'm in a little bit of a hurry today but I hope this gives you an idea.
-
June 14th, 2002, 05:10 AM
#6
Yeah, I was thinking about seeking out math operators and do the numbers in between, but that's to much hassle, and since I'm already using windows common controls, I need to create a setup program anyway, so I'll just add the script control. Thanks for you help tho.
-
June 15th, 2002, 04:10 PM
#7
Just do this
text1.text = 10 - 4 + 6
'then the text1.text will be 12
'you can use the - + / *
'when you want 11 in your textboxdo
text1.text = "1" & "1" 'Then he will set the numbers behind eachother and not count them up
Bert Willekens,
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
|