473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how can a math operator be set as a variable?

Public sValue1 As String, sValue2 As String
Public dValue1 As Double, dValue2 As Double
Public vOper

vOper = "*" 'set operator
variable to "multiply"

sValue1 = txtMain1.Text 'get first string
value
sValue2 = txtMain2.Text 'get second string
value

dValue1 = CDbl(sValue1) 'convert first string
value to double
dValue2 = CDbl(sValue2) 'convert second string
value to double
dResult = (dValue1 & vOper & dValue2)
txtMain2.Text = CStr(dResult)

Jul 17 '05 #1
1 4203
On Tue, 25 Jan 2005 01:12:32 GMT, "andrew" <hd***@hotmail.com> wrote:
[snip some code]
I would start off by saying something in the body of the message.
Option Explicit

Public dValue1 As Double, dValue2 As Double
Private sOper As String * 1

Private Sub Form_Load()
sOper = "*"
dValue1 = Val(txtMain1.Text)
dValue2 = Val(txtMain2.Text)

dResult = Eval(dValue1, sOper, dValue2)
txtMain2.Text = CStr(dResult)
End Sub

Function Eval(Val1 As Double, Op As String, Val2 As Double) As Double
Select Case Op
Case "+"
Eval = Val1 + Val2
Case "-"
Eval = Val1 - Val2
Case "*"
Eval = Val1 * Val2
Case "/"
Eval = Val1 / Val2
Case "^"
Eval = Val1 ^ Val2
Case Else
Eval = 0
' or could raise an error
End Select
End Function

--
auric underscore underscore at hotmail dot com
*****
When you say "I wrote a program that crashed Windows", people just stare
at you blankly and say "Hey, I got those with the system, *for free*".
-- Linus Torvalds
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
7
by: Wernfried Schwenkner | last post by:
I've found the discussion about Math.Log and the error with Math.Log(8,2) on Google. Unfortunatly the full thread isn't on my news server, so I can't reply. The problem doesn't only depend...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
1
by: Pawel | last post by:
How do you use a (pow) statement in visual c++.net 2003 standard edition? I want to calculate something and then display it to the user. But in a windows based enviornment not dos. What do you...
6
by: Mitchell Vincent | last post by:
Just making sure I'm not missing the boat here, but are there any special routines for doing currency math (fixed precision stuff) in .NET? The wonderful problems of doing math on decimals tend...
13
by: david ullua | last post by:
Hi, In Expand.c of BSD system, I met the following codes, the expression (column & 07) if used to compare variable column and 7, if column<=7, it returns true, else false. It use (column & 07)...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
13
by: =?Utf-8?B?TWFyaw==?= | last post by:
Need help with a variable... This variable is used to keep track of permissions and can contain 1,2,4,8,16,32,64,128 Or it can contain a sum of one more of the above values. For example, if...
0
by: M.-A. Lemburg | last post by:
On 2008-10-25 20:19, Akira Kitada wrote: Thanks. The errors you are getting appear to be related to either some missing header files or a missing symbol definition to enable these - looking...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.