VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 307,146 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,732 people online right now. Registration is fast and FREE... Join Now!




Calculating with x y.

 

Calculating with x y.

tom1597530

29 Oct, 2009 - 10:11 AM
Post #1

New D.I.C Head
*

Joined: 16 Oct, 2009
Posts: 13

Hello. I don't know how do you call it in English, but I need help with calculating x + x to be 2x. So, I have Command1, Text1 and Text2 and when I'll write in text1 etc. 3x + 4x and click Command1 it will show 7x in Text2. But When I'll write 3x+y+x, it will calculate 4x+y into the Text2. WHEN IT'S TOO COMPLICATED, THEN JUST HELP ME WITH x + x; y + y;....

THANX.

I mean too complicated for you smile.gif. THX

User is offlineProfile CardPM
+Quote Post


vb5prgrmr

RE: Calculating With X Y.

29 Oct, 2009 - 07:21 PM
Post #2

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 486



Thanked: 30 times
My Contributions
Ahhh... a problem from the past... (Old teacher did this problem with an example of using a stack class...)

Okay, you need to loop through the string looking for the operators (+-*/) and testing for forced operator precidence (operations wrapped in parens). Then don't forget about natural operator precidence, * & / before + & - (Left to right).

So, in your example of 3x + y + x you would first search for forced operator precidence and do any calculations within the inner most set of parens...
((4x * 3x) + (12y * 2y)) - (6x + y)

Then search for operators...
(12x + 24y) - (6x + y)
6x + 23y

(That is if I remember my math right...)




Good Luck



User is offlineProfile CardPM
+Quote Post

tom1597530

RE: Calculating With X Y.

30 Oct, 2009 - 07:59 AM
Post #3

New D.I.C Head
*

Joined: 16 Oct, 2009
Posts: 13

I don't get it. Why is 3x + y +x = 6x +23Y and not 4x + y??????????
User is offlineProfile CardPM
+Quote Post

vb5prgrmr

RE: Calculating With X Y.

5 Nov, 2009 - 11:45 PM
Post #4

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 486



Thanked: 30 times
My Contributions
I switched from your example to my example and did not put enough lines between so you would know the difference...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:52PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month