Thanks:  0
Likes:  0
Dislikes:  0

# Thread: varType of a variable

1. ## varType of a variable

All,

I have to calculate the value of several variables and need to keep the ones that are integer, drop the ones that are not. However, varType returns the value not as I expect it.

For example (the code below), res1 equal to 13 and varType(res1) returns a value of 2 (Integer), this is as expected. But, res2 equal to 7, and varType(res2) returns a value of 5 (Double-precision floating-point number), which is not what I expected.

How can I keep the res2 that is integer? Thanks!

==============code==================
i = 7
j = 6
k = 3
m = 2
n = 1

res1 = i + j
msgbox varType(res1)

res2 = i + j - k * m / n
msgbox varType(res2)

2. ## Re: varType of a variable

res2 = i + j - k * m / n
msgbox varType(CInt(res2))

:-}
Janna

3. ## Re: varType of a variable

Originally posted by jbotash:
res2 = i + j - k * m / n
msgbox varType(CInt(res2))

:-}
Janna
<font size="2" face="Verdana, Arial, Helvetica">i think this method would always return you the variable type as INT even if the value of res2 is in decimal also.

better would be to check it using a if condition

if cdbl(cint(res2)=res2 then
'The value is a integer
else
'The value is a floating point
end if

4. ## Re: varType of a variable

Janna and Tarun, Thanks for your input.

I am using ...

if res2 - CInt(res2) = 0 then
'res2 is an integer
else
'res2 is a floating point
end if

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.