+ Reply to Thread
Results 1 to 6 of 6

Question about difference between variables

  1. #1
    Registered User
    Join Date
    10-25-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    25

    Question about difference between variables

    I have been in an online class for about 5 weeks now and we have been doing programing with VBA and it has all been pretty simple. Mostly me just taking the example and rewriting it to fit what I needed it to do. Now I am trying to actually understand stuff. What is the difference between "As String" and "As Double"? Or if someone knows a website I can go to that will explain things along these lines? I have searched on google but yet to come up with a website that explains theses items.
    Last edited by jaje21; 10-27-2011 at 03:18 PM.

  2. #2
    Registered User
    Join Date
    05-17-2009
    Location
    Port St. Lucie, FL
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Question about difference between variables

    jaje21,
    "As String" is a "data type" which is a fixed length or variable length. Fixed length is 1 to approximately 65400. Variable length is 0 to approximately 2 billion.
    "As Double" is a "data type" which is -1.79769313486231E308 to
    -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
    This can be found in Excel. Open a Visual Basic Editor page, select help. Type Data type in search window.
    hth

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Question about difference between variables

    Hi jaje21,

    When you DIM a variable you need to tell VBA how much room, in memory, to leave for that variable. The AS part helps VBA to know how much room to leave for variables of different types.

    As VBA runs down its code and moves to a Subroutine it sees your DIM statements and creates variables and uses them while in that Sub. When the Sub ends the memory and variable space is cleared.

    Things get a lot more fun with Static or Global variables that aren't erased when a Sub or Function ends.

    Back in the old days I remember trying to write faster code and having a loop with a variable in it. The variable that was used the most, if you put it first in the DIM statments was found first. My opponent didn't know how this would matter so I won this race.

    Search the net for Excel VBA Variable Global Static for more information.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Question about difference between variables

    There's a table of variables here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    10-25-2011
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Question about difference between variables

    Thank you for both of yours help. I guess what I really need to know is, is there a difference in using "double" vs "string." I could post my workbook and assignment so that you all know exactly what I am doing, but essentially I am making a form that allows me to sell someone an item using check boxes and option boxes to modify it. When I hit the process order box I am trying to tell it how to use the info that was selected.

    Ahh that is super helpful Roy. Thank you for the page.
    Last edited by jaje21; 10-26-2011 at 04:01 AM. Reason: Didn't see Roy's post

  6. #6
    Registered User
    Join Date
    05-17-2009
    Location
    Port St. Lucie, FL
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Question about difference between variables

    jaje21,
    Think of it this way:
    Numbers you can use double as a declared variable (i.e Dim Interest as Double).
    String is typically used for words(i.e. Dim Interest as String).
    You can not do any math functions(add, subtract, multiply, or divide) on a string.

    Using the wrong Dim on a variable is like:
    " Remember this number Blue"
    hth

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1