Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default dim objects and dim long

I was wondering if someone could explain to me why it is we dim objects and
long. Where is it important to do and why. I have been puzzled by this. I
have read lots trying to figure this out. What it means and the purpose of
it's application I am strugling with.
--
Thanks!
Shane W
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default dim objects and dim long

Its all a matter of memory space and values these variables can
represent.....

A long variable uses 4 bytes and can hold integer values from -2,147,483,648
to 2,147,483,647
as opposed to Integer variables that uses 2 bytes and can hold integer
values from -32,768 to 32,767

Typically Long is used if you intend to refer to worksheet rows, where the
value can run to 65,536

--
Cheers
Nigel



"whylite" wrote in message
...
I was wondering if someone could explain to me why it is we dim objects and
long. Where is it important to do and why. I have been puzzled by this.
I
have read lots trying to figure this out. What it means and the purpose
of
it's application I am strugling with.
--
Thanks!
Shane W



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default dim objects and dim long

I do it for a much more selfish reason.

If I add "Option Explicit" to the top of a module (or have the VBE do it for me
via tools|options|Editor tab|check require variable declaration), I know that
most of my typos will stop my code from compiling.

Then I don't have to spend minutes/hours looking at code like this:
ctr1 = ctrl + 1
(One is ctr-one and one is ctr-ell)
trying to find why my counter isn't incrementing.

And if I declare my variables nicely:

Dim wks as worksheet
not
dim wks as object
and not
dim wks as variant

I get to use the VBE's intellisense.

If I use "dim wks as worksheet", then I can type:
wks.
(including the dot)
and the VBE will pop up a list of all the properties and methods that I can
use. It saves time coding (for me anyway).

And one final selfish reason.

If I use a variable like:

Dim ThisIsACounterOfValidResponses as Long

I can type
Thisis
and hit ctrl-space and the VBE will either complete the variable name or give me
a list of things that start with those characters.

And by using a combination of upper and lower case letters in my variables, the
VBE will match the case found in the declaration statement.

ps. From what I've read, if you declare a variable as Integer, the modern pc
will have to spend time converting it to long. So I've stopped using "dim x as
integer". It's safer for me and quicker for the pc.



whylite wrote:

I was wondering if someone could explain to me why it is we dim objects and
long. Where is it important to do and why. I have been puzzled by this. I
have read lots trying to figure this out. What it means and the purpose of
it's application I am strugling with.
--
Thanks!
Shane W


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default dim objects and dim long

So in other words objects is used for naming. I think I get it now. Instead
of having to type so much you can make declarations to shorted key strokes.
Now I use integer a lot in my programming. With long I can shorten this up?
Can you give me an example?

--
Thanks!
Shane W


"Dave Peterson" wrote:

I do it for a much more selfish reason.

If I add "Option Explicit" to the top of a module (or have the VBE do it for me
via tools|options|Editor tab|check require variable declaration), I know that
most of my typos will stop my code from compiling.

Then I don't have to spend minutes/hours looking at code like this:
ctr1 = ctrl + 1
(One is ctr-one and one is ctr-ell)
trying to find why my counter isn't incrementing.

And if I declare my variables nicely:

Dim wks as worksheet
not
dim wks as object
and not
dim wks as variant

I get to use the VBE's intellisense.

If I use "dim wks as worksheet", then I can type:
wks.
(including the dot)
and the VBE will pop up a list of all the properties and methods that I can
use. It saves time coding (for me anyway).

And one final selfish reason.

If I use a variable like:

Dim ThisIsACounterOfValidResponses as Long

I can type
Thisis
and hit ctrl-space and the VBE will either complete the variable name or give me
a list of things that start with those characters.

And by using a combination of upper and lower case letters in my variables, the
VBE will match the case found in the declaration statement.

ps. From what I've read, if you declare a variable as Integer, the modern pc
will have to spend time converting it to long. So I've stopped using "dim x as
integer". It's safer for me and quicker for the pc.



whylite wrote:

I was wondering if someone could explain to me why it is we dim objects and
long. Where is it important to do and why. I have been puzzled by this. I
have read lots trying to figure this out. What it means and the purpose of
it's application I am strugling with.
--
Thanks!
Shane W


--

Dave Peterson

Reply
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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Long Long Long Nested If Function sed Excel Discussion (Misc queries) 4 December 9th 09 06:44 PM
Clearing cells takes long, long time unclemuffin Excel Discussion (Misc queries) 9 August 17th 07 02:22 AM
Dynamically Assign Objects to Form Objects. The Vision Thing Excel Programming 2 December 11th 04 04:02 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM


All times are GMT +1. The time now is 02:35 AM.

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

About Us

"It's about Microsoft Excel"