Integer and String problem

# Thread: Integer and String problem

1. Junior Member
Join Date
Dec 1969
Posts
12

## Integer and String problem

I created a calender program that lets a user select a year, month, and day. Once the user selects these variables, I run the variables thru a check to see if they are valid calender dates. At one point, I check the day the user selected vs. the largest possible date you can have for a month. Ex. userday=28, june has 31 days in the month. So I check if userday &#060; june ( 28 &#060; 31 ) but I get the wrong output. I beleive one of the variables is a ingeter, and one is a string. How can I check if I have two intergers? Or, how can I change a string to an integer?

2. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## Cint() converts string to integer <eop>

.

3. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## But dont use it

as a habbit use clng<BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## Depends...

If you know that the field is going to be short, stick to Cint. In this case, we have the number of days in a month. So the greatest number will be 31, which is fine for Cint.

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Like i said

as a habbit NEVER use it....forget it even exists......there are a few cases when the number will never get too hign but more often that not you may think that for a field and eventually be wrong<BR><BR><BR>EVEN if the field will never exceed 12 use clng as a habbit.....you will not lose anything but only gain.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## No big deal, but I don't agree...

A month won&#039;t have more than 31 days. Why bother converting to long? Doesn&#039;t make sense. Stick to converting it to int. Don&#039;t make a habit out of using cint() or clng(). Look at each case specifically. I don&#039;t make fields in my database to int if a tinyint will do. It&#039;s the same sort of reasoning. I understand your point, but if the underlying data is an integer, why "go long"? I don&#039;t think it&#039;s that risky. Use clng() when appropriate, and use cint() when appropriate. We could debate this all day, I suppose, but I think I&#039;ve summed up my stance here, and I think you&#039;ve summed up yours as well. No need for further arguements.

7. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## I agree

but like i mentioned there are cases where you may THINK cint will be enough but a few month later that blows up....then you will have to change it<BR><BR><BR>so as a HABIT use clng EVERYWHERE......so when it comes to certain cases, you dont have to think if it will become a high number, you dont care cause you are using clng<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
11,334

## Nah, the dude is right

Why do something out of habit? It&#039;s a silly an argument as ALWAYS ALWAYS using & to concatenate and NEVER NEVER +. <BR><BR>The ONLY thing I&#039;ll give you why a long is better is because a 4 byte variable is more native to a windows platform, and would be more efficient. By nanoseconds maybe, but hey... throw that in your agrs :)

9. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## If i had a dollar

for the number of times i "KNEW" a value will never get too high......well all that is moot now for me cause i use wrapper functions for ALL values<BR><BR>

10. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## If there's ever more than 31 days in a month.

he&#039;s going to have a lot more to worry about than using cint(). I couldn&#039;t resist one last post... :-)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•