LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA Int, Cint?

Why differs the results from the function Int and CInt/CLng depending on the
value in this example?
E.g. see the values 6957 and 6960.

Private Sub CommandButton1_Click()
Dim tal As Double
Dim r As Integer

With ThisWorkbook.Sheets("Blad1")
tal = 69.5
r = 1
For i = 1 To 10
.Cells(r, 1) = "Value!"
.Cells(r + i, 1) = 100 * (tal + i / 100)
.Cells(1, 2) = "Int"
.Cells(r + i, 2) = Int(100 * (tal + i / 100))
.Cells(r, 3) = "Cint"
.Cells(r + i, 3) = CInt(100 * (tal + i / 100))
.Cells(r, 4) = "CLng"
.Cells(r + i, 4) = CInt(100 * (tal + i / 100))
Next i

tal = 169.5
r = 13
For i = 1 To 10
.Cells(r, 1) = "Value!"
.Cells(r + i, 1) = 100 * (tal + i / 100)
.Cells(r, 2) = "Int"
.Cells(r + i, 2) = Int(100 * (tal + i / 100))
.Cells(r, 3) = "Cint"
.Cells(r + i, 3) = CInt(100 * (tal + i / 100))
.Cells(r, 4) = "CLng"
.Cells(r + i, 4) = CInt(100 * (tal + i / 100))
Next i
End With
End Sub

Value! Int Cint CLng
6951 6951 6951 6951
6952 6952 6952 6952
6953 6953 6953 6953
6954 6954 6954 6954
6955 6955 6955 6955
6956 6956 6956 6956
6957 6956 6957 6957
6958 6958 6958 6958
6959 6959 6959 6959
6960 6959 6960 6960

Value! Int Cint CLng
16951 16951 16951 16951
16952 16952 16952 16952
16953 16953 16953 16953
16954 16954 16954 16954
16955 16955 16955 16955
16956 16956 16956 16956
16957 16957 16957 16957
16958 16958 16958 16958
16959 16959 16959 16959
16960 16960 16960 16960


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
save textbox as number wth Cint? Karen53 Excel Programming 7 September 23rd 07 12:00 AM


All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"