View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Dimension problem

Alex,

VB is doing exactly what it should. When you declare variables
with the syntax

dim i , j, k, As Integer

only the variable k is an integer. I and j are Variants. Your
syntax is the same as

Dim i As Variant, j As Variant, k As Integer

When you assign a value of 3.7 to i and j, VBA gives the variant
a subtype of Double. Whether you should declare more than one
variable on a single line of code is a matter of personal
programming style. I don't like it, but others do. Go with your
own style.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"APH" wrote in message
...
Hi - can someone explain the following please?

if I set up:

dim i , j, k, As Integer

i = 3.7
j = 3.7
k = 3.7

MsgBox i
MsgBox j
MsgBox k

Do the first two MsgBox show 3.7 and only the third as 4.00

In my basic understanding I am assuming that VB will only dim

the variable
immediately to the left of As Integer and for the others it

waits to set
their type until it comes across them. If this is right, is

it bad
programming to declare similar cariable types on a single linbe

thanks

Alex