How To Declare A Variable With VBA Dim

To declare a variable, means to allocate a portion of the computer’s memory to hold the contents of that variable.

“Dim” means “Dimension”, or “allocate a portion of the computer’s memory.”

“Dim intNumber As Integer” – means that we need the computer to allocate 2 bytes of the computer’s total RAM memory to hold a variable which can contain a number between -32,767 and 32,767.

So if we only need to store a number between 0 and 255 we should only use a “byte” datatype, because an “Integer” would be “overkill”.

This is not necessarily a huge concern now because a computer’s resources are greater than in the past.

So what’s 1 byte versus 2 bytes when you have 4 Gigabytes (a billion bytes) to work with? Well each program running on your computer wants a piece of that 4 GB.

Dimensioning (“Dimming”) variables is also used by the “Option Explicit” statement, and helps maintain program control. It helps you to make you aware when you type the wrong things into your VBE window.

Read more here: https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/data-type-summary

For some more in depth information, get the full course at http://vbahowto.com/course



Free! Subscribe To Our YouTube Channel!

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather
Tags: ,




 

Call Erik Now