The IDE changes what I type

M

MikeB

Two different problems in my continueing VBA journey.

I'm trying to find every 100th incidence of a counter.

I have

Option Compare Database
Option Explicit

Sub Main()
Dim i As Integer
For i = 1 To 120 Step 1
AmI100 (i)
Next i
End Sub

Sub AmI100(ByVal i As Integer)
Dim li As Long
Dim ii As Integer
li = CLng(i) / CLng(100)
Debug.Print "li: " & li
ii = i / 100
Debug.Print "ii: " & ii
If li = CLng(ii) Then
Debug.Print "Printing line " & i & " at " & Now()
End If
End Sub


It's still not working.

I *always* get that
li = CLng(i) / CLng(100) = 1
and
ii = i / 100 = 1

Also, if I type
li = CLng(i) / 100.00
in the IDE, it is automatically changed to:
li = CLng(i) / 100#

Why is that?

Thanks
 
M

MikeB

You know what, nevermind, I found

If (i Mod 100) = 0 Then


and as for the IDE changing 100.00 into 100#, I'd be happy if someone
could explain that to me.

Thanks.
 
D

Dirk Goldgar

MikeB said:
You know what, nevermind, I found

If (i Mod 100) = 0 Then


and as for the IDE changing 100.00 into 100#, I'd be happy if someone
could explain that to me.


They are equivalent constants. The decimal point in 100.00 implies that the
constant must be a floating-point number, and "#" is the type-declaration
character for the Double (double-precision floating point) data type. The
VB editor is just clarifying your code -- helpfully, it thinks.
 
G

Guest

The IDE always reformats your code after it has accepted it.
For example, if you type

dim Fred as integer

the IDE will change that to

Dim Fred As Integer

This is to indicate that 'Auto Syntax Check' is turned on, and
has automatically checked your syntax.

The suffix $ for string, # for real is a very old part of BASIC,
older than 'Hungarian' notation, recognised by and integrated
into the compiler. C Hungarian notation used prefixes, but that
is based on the fact that it is very difficult to keep track of type
information in C. In languages like BASIC that handle variables
better, the type information is rightly viewed as less important
than the logical content of the variable, so suffixes were preferred.

(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top