Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exclamation Point attached to variable name

Status
Not open for further replies.

prost

Structural
Jan 2, 2002
583
I saw something in someone else's code--an exclamation point at the end of a variable name. I was unfamiliar with the usage, looked it up, read that the exclamation point is used to specify a variable as precision Single.

Usage: "dummy!" will make the variable "dummy" a Single precision variable.

Why would someone use the exclamation point? Why not just make all floating point (real) variables Double precision?
 
Replies continue below

Recommended for you

The main reason would be either for storage space or for compatibility with some legacy or embedded application. When Excel was first created, most microprocessors could not do 64-bit floating point, and single-precision was the norm.

btw # evokes double. However, the characters are not parsed by VBA. You declare type using Dim. The appended characters are for the programmer to keep track of types.

TTFN

FAQ731-376
 
Those characters are in fact parsed by vba.



=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Try this
Code:
Sub mytest()
 Dummy1! = (Application.WorksheetFunction.Pi())
 Dummy2# = (Application.WorksheetFunction.Pi())
 Dummy1! = Dummy1! * 1E+17
 Dummy2# = Dummy2# * 1E+17
 Debug.Print Dummy1! - Dummy2#
End Sub
The printed difference is
157376256

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Why not just make all floating point (real) variables Double precision?
That's what I do and I think what most people do.

But, if you have a large program computationally intensive program with lots of variables, I believe you can save memory and speed execution by using single vs double if you don't need the extra accuracy. That was probably more important in the old days. Hard to imagine there are many practical cases when it makes a big difference anymore.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Also as IRStuff says - it may help compatibility or comparability with older applications that used single precision.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Thanks for the exclamation, and the reminder that not so long ago, we really didn't have that much space in RAM or hard drive to use, and sometimes had to be careful with memory allocation.
 
that's funny, 'exclamation' on the brain. I meant "Thanks for the explanation,"
 
Thanks, EP. The help file implied otherwise.

TTFN

FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor