PC Review


Reply
Thread Tools Rate Thread

"dim" problem after Service Pack Installation????

 
 
=?Utf-8?B?S2Vuc3lv?=
Guest
Posts: n/a
 
      29th May 2007
Today, I have this strange problem of dim. I don't have this problem before.
If I run the following program, variable d would automatically round up to
an integer. This happens to me any variable that I put at the end of the dim
statement if I have two or more variables.

Sub Button1_Click()
Dim a, b, c, d As Long
a = Range("c3")
b = Range("c3")
c = Range("c3")
d = Range("c3")
Range("c5") = a
Range("c6") = b
Range("c7") = c
Range("c8") = d
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      29th May 2007
You have made a classic mistake in your dim statements. Only d is a long the
rest of the variables are of type variant. Check out this link...

http://www.cpearson.com/excel/variables.htm

Darn near everything you need to know about declaring variables is right here.
--
HTH...

Jim Thomlinson


"Kensyo" wrote:

> Today, I have this strange problem of dim. I don't have this problem before.
> If I run the following program, variable d would automatically round up to
> an integer. This happens to me any variable that I put at the end of the dim
> statement if I have two or more variables.
>
> Sub Button1_Click()
> Dim a, b, c, d As Long
> a = Range("c3")
> b = Range("c3")
> c = Range("c3")
> d = Range("c3")
> Range("c5") = a
> Range("c6") = b
> Range("c7") = c
> Range("c8") = d
> End Sub
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      29th May 2007
This line:

Dim a, b, c, d As Long

Really is the same as:

Dim a as variant
Dim b as variant
Dim c as variant
Dim d As Long

Longs are positive and negative (and 0) whole numbers. They don't contain
fractions.

Did you want

Dim a as double
dim b as double
dim c as double
dim d as double

or equivalently

dim a as double, b as double, c as double, d as double



Kensyo wrote:
>
> Today, I have this strange problem of dim. I don't have this problem before.
> If I run the following program, variable d would automatically round up to
> an integer. This happens to me any variable that I put at the end of the dim
> statement if I have two or more variables.
>
> Sub Button1_Click()
> Dim a, b, c, d As Long
> a = Range("c3")
> b = Range("c3")
> c = Range("c3")
> d = Range("c3")
> Range("c5") = a
> Range("c6") = b
> Range("c7") = c
> Range("c8") = d
> End Sub


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
vista "service pack 1" problem watermark - Trustinstalled David Sherman Windows Vista General Discussion 4 23rd Dec 2007 03:59 AM
Getting pretty desperate- Please help - Using "MailMessage" and "SmtpMail" on a WinXP Prof box with iis5 and sp2 and dotnet1.1 with the latest service pack dorisferrarese@yahoo.com Microsoft Dot NET Framework 1 21st Jun 2007 11:49 AM
"1" appears "without typing" in Windows XP Service Pack 2 (Compaq EVO N1020V Laptop) johnmclaughlin48@gmail.com Windows XP General 6 3rd Oct 2006 01:07 PM
"Content-Disposition: attachment" Problem with XP Service Pack 2 Windows XP Internet Explorer 2 16th Dec 2004 10:29 PM
"Microsoft Game Studios Redistributables Pack 1" Installation popup?? Simon Johansson Windows XP General 0 18th Jul 2003 08:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 PM.