Rookie
09-03-2003, 04:39 AM
is there an easy way to calculate a maths calculation within a string? ie. the user types in "2 + 5 / 2" and the answer can be returned. Ive tried using Val but it desnt seem to support division or multiplication!
String equations...Rookie 09-03-2003, 04:39 AM is there an easy way to calculate a maths calculation within a string? ie. the user types in "2 + 5 / 2" and the answer can be returned. Ive tried using Val but it desnt seem to support division or multiplication! Garmour 09-03-2003, 04:49 AM Add the microsoft script control component to your project (ctrl + t). You can then use the .eval method to evaluate string calculations. eg private sub command1_click() msgbox scriptcontrol1.eval ("1+2+3+4+5") end sub will output 15 Neodammer 09-03-2003, 04:53 AM is there an easy way to calculate a maths calculation within a string? ie. the user types in "2 + 5 / 2" and the answer can be returned. Ive tried using Val but it desnt seem to support division or multiplication! To make it short and see if you understand before writing alot lol, ill just say this, it will take alot of code there not to have errors :) If its just multiplication, division, addition, and subtraction id pretty much just make subs for each of those...Another problem you are going to face is how do you tell how many #'s they put in and where? also is it simple or complex ie. 2 + 2 = 4 or 5(2 +2)-9(2(9-2)) You could eliminate certain keyboard inputs like "()" The way i would do it is ask in some way what type of equation they will be doing, then divide that equation into multiple textbox's not just one ***will eliminate alot of error code*** Put many box's and just say if mathinputnumber8.text = "" then (do nothing with it so to speak). Well i hope i have helped alittle just my 2 cents lol Peace Kaluriel 09-03-2003, 09:21 AM is there an easy way to calculate a maths calculation within a string? ie. the user types in "2 + 5 / 2" and the answer can be returned. Ive tried using Val but it desnt seem to support division or multiplication! To make it short and see if you understand before writing alot lol, ill just say this, it will take alot of code there not to have errors :) If its just multiplication, division, addition, and subtraction id pretty much just make subs for each of those...Another problem you are going to face is how do you tell how many #'s they put in and where? also is it simple or complex ie. 2 + 2 = 4 or 5(2 +2)-9(2(9-2)) You could eliminate certain keyboard inputs like "()" The way i would do it is ask in some way what type of equation they will be doing, then divide that equation into multiple textbox's not just one ***will eliminate alot of error code*** Put many box's and just say if mathinputnumber8.text = "" then (do nothing with it so to speak). Well i hope i have helped alittle just my 2 cents lol Peace Have you never heard of PEMDAS? Removing the brackets would completely screw up everything 5+1*2 is not the same as (5+1)*2 DeX 09-03-2003, 09:28 AM Someone recently posted an expression evaluator in Random Thoughts. Check it out: http://www.visualbasicforum.com/t103509.html Garmour 09-03-2003, 09:31 AM Have you never heard of PEMDAS? Removing the brackets would completely screw up everything 5+1*2 is not the same as (5+1)*2 PEDMAS ? I was taught BODMAS (brackets, of, division, muliplication, addition, subtraction) Kaluriel 09-03-2003, 09:35 AM heh, I was taught BODMAS as well, but I got told about PEMDAS (parenthesis, exponent, division, multiplication, addition and subtraction) in the chat, it goes one step further than BODMAS by saying where exponents fit in Squishy 09-03-2003, 07:28 PM :) I learned it as BEDMAS - Brackets, Exponents, Division & Multiplication, Addition & Subtraction MikeJ 09-03-2003, 10:07 PM For anyone who cares, our 7th grade math teacher explained it to us: PEMDAS = majority of the United States BEDMAS = most of Canada (excluding Quebec) (as she was from Vancouver, I'm entitled to believe her) BODMAS = rest of the world (world being Europe and Quebec) Just my $0.02 on the matter. ~Mike P.S. I cannot believe I am saying this, but there was once a good code example on how to do math within a string at PlanetSourceCode. The link seems to be dead in my Favorites, but it probably still exists if you are up for some digging there. The only reason I'm suggesting this is because it only used native VB functions, which removed the need for the MS Script Control. DeX 09-04-2003, 04:39 AM I learnt BODMAS first of all but I never knew what the O stood for. Then a few years later we had a different maths teacher who taught us BIMDAS where the I stood for indicies. That made a lot more sense than BODMAS anyway :p. |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum