User Defined Types and Overloaded Operators

G

Guest

Currently Excel allows operands of various types to be used in formulas.
Operands such as Number, Cell References, Names, Labels, and Functions are
among those currently allowed. I am interested in whether or not it is
possible to build a user defined type, essentially a string of concatenated
chunks of information. In addition, is it possible to overload the Excel's
calculation operators?

Thank You,
 
G

Guest

hi
yes it is possible to overload excel. but not excel specificly. you are
limited by available resorces ie hard drive size, memory, processer speed,
other, ect.
yes, you can write your own functons. they are called UDFs(User Defined
Functions)
function something()
some code
end function

good for creating special formula or other functions for the user. do a
google on excel functions. they are fairly easy but can get rather
complicated depending.

Regards
FSt1
 
C

Chip Pearson

yes it is possible to overload excel. but not excel specificly. you are
limited by available resorces ie hard drive size, memory, processer speed,

I don't think that is what he means by overloading. An example of the
overloading in the context of the original question would be to have two (or
more) functions with the same name but that take a different type(s) and
number of input parameters. As a very simple example,

Public Function MyTest(D As Double)
' code
End Function

Public Function MyTest(S As String)
' code
End Function

If overloading were possible in VBA, the compiler would automatically select
which MyTest function to use based on the data type of the parameter. Thus

R = MyTest(123.456)
' and
R = MyTest("abcd")

would actually call two different MyTest procedures, each selected by the
data type of the input parameter.

Overloading an operator mean to have one symbol (e.g., '+') whose behavior
depends on the data types that are being processed by the '+' operation. (In
this example, the '+' is in fact overloaded within VBA: if used with
strings, "abc" + "def", it acts as a & concatenator and when used with
numbers it acts as the normal numeric addition operator.

Alas, no overloading is possible in VBA.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
G

Guest

Chip Pearson said:
I don't think that is what he means by overloading. An example of the
overloading in the context of the original question would be to have two (or
more) functions with the same name but that take a different type(s) and
number of input parameters. As a very simple example,

Public Function MyTest(D As Double)
' code
End Function

Public Function MyTest(S As String)
' code
End Function

If overloading were possible in VBA, the compiler would automatically select
which MyTest function to use based on the data type of the parameter. Thus

R = MyTest(123.456)
' and
R = MyTest("abcd")

would actually call two different MyTest procedures, each selected by the
data type of the input parameter.

Overloading an operator mean to have one symbol (e.g., '+') whose behavior
depends on the data types that are being processed by the '+' operation. (In
this example, the '+' is in fact overloaded within VBA: if used with
strings, "abc" + "def", it acts as a & concatenator and when used with
numbers it acts as the normal numeric addition operator.

Alas, no overloading is possible in VBA.

It is my understanding that Excel 2007 allows one to develop Add-ins using
C++. Since C++ allows the overloading of mathematical operators such as "+",
can one overload Excel's mathematical operators? Although I am interested in
overloading functions, I am more interested in overloading the mathematical
operators which are used by most user when writing formulas. For example,

column A B C
row 1 "Widget1" "Widget2" = A1+A2
result "someresult"

where "someresult" is based upon the logic contained within the overloaded
operator "+".

Thank You,
 
C

Chip Pearson

It is my understanding that Excel 2007 allows one to develop Add-ins using
C++.

XLA-type add-ins must be written in VBA. Since Excel 2000, Excel has
supported COM Add-Ins and since 2002 has supported Automation Add-Ins, each
of which can be written in any language that supports COM, including C++. In
Excel 2003 and 2007, you can also write add-ins and class libraries in any
NET language you like. Internal to a C++ or NET add-in, you can do any sort
of overloading you want, in the sense that "overload" means in C++. However,
you cannot overload any operators in a worksheet formula. For example, there
is no way to change the meaning of the '+' operator in a formula to add
numbers and concatenate strings. Nor can you create your own operators.

Overloading is really a function of the compiler as much as it is of the
runtime libraries, and you can't use features of the C++ compiler to work
with Excel formula. It would certainly be nice, but sadly can't be done.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top