View Full Version : Help with "dim as"
harber95
07-21-2015, 09:57 AM
How do I dim a parameter as a positive number that may be not whole (like 3.45)?
Kenneth Hobs
07-21-2015, 09:59 AM
Dim x as Double
x = -3.45
MsgBox Abs(x)
harber95
07-21-2015, 10:14 AM
What is the meaning of the msgbox? Why is x negative?
Kenneth Hobs
07-21-2015, 10:34 AM
It is that way to show illustration of concept. When checking or debugging short code snippets, I often use MsgBox() or Debug.Print. Of course you can debug by running code one line at a time by pressing F8. After a line runs/executes that way or from a debug mode session, hover cursor over a variable to see what it resolved to.
So, you can Dim a variable as a Double type but you can not Dim by positive or negative.
If you want to force a negative number to be positive, one can do it as I did.
x = -3.45
x = Abs(x)
MsgBox x
If you don't know what a command word does, put the cursor in or next to it and press F1 to get direct help.
Paul_Hossler
07-21-2015, 01:07 PM
How do I dim a parameter as a positive number that may be not whole (like 3.45)?
Like Ken says, Dim X As Double, but there's no way to Type a variable as positive floating point only - You get positive and negative so you have to handle cases where something has to be positive yourself
from Help
Double (double-precision floating-point) variables (http://www.vbaexpress.com/forum/HV10383569.htm)
are stored as IEEE 64-bit (8-byte) floating-point numbers ranging in value from
-1.79769313486231E308 to -4.94065645841247E-324 for negative values and from
4.94065645841247E-324 to 1.79769313486232E308 for positive values. The type-declaration character (http://www.vbaexpress.com/forum/HV10383569.htm) for Double is the number sign (#).
harber95
07-21-2015, 02:24 PM
Actually, I don't need to turn a negative number into a positive, I just need to condition it after the dim. And if the number is negative, then a msgbox will appear and make me insert another numeber. I can take it from here. Thanks a lot!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.