Results 1 to 2 of 2
  1. #1
    ntambomvu is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Johannesburg south africa
    Posts
    91

    is option explicit the same as "private" in dbase 4 ver 2

    Hello There
    Trying to learn Access the difficult way ( by myself)
    I used to use dbase 4 ver 2 (dos)
    Can someone tell me if "option explicit" in VBA is the same thing as we called "private"


    in dbase?

    thanks

    fred

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    option explicit : means you MUST define your variables,
    Dim i as integer
    dim sTxt as string

    ALWAYS use this. Its good for finding mistakes.
    If you dont use it and you mistype a variable, sTxr = "bob"
    your results can come out wrong, since the code is looking for sTxt.
    Explicit will alert you to this.

    PRIVATE , is like Dim but for the entire module.
    dim is for a single subroutine or function

    the module holds all the subroutines and the variable declared here can be seen by ALL subs in the module.
    a form has a module code.

    (note I cannot use the 'code' flag here...the website keeps messing it up)

    Private msName as string

    sub btnGo_click()
    dim i as integer
    msgbox msName
    end sub

    sub btnStop_click()
    msgbox msName
    end sub


    in the code above, msName can be seen by all subs.
    but the i in
    btnGo_click can ONLY be seen by btnGo_click

    and other modules cannot see module level variables.
    but all modules can see Public vars.

    dim (for subs)
    private (for modules)
    public (for everything, global)




Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-08-2018, 08:18 AM
  2. Replies: 1
    Last Post: 02-28-2017, 12:29 PM
  3. Replies: 3
    Last Post: 08-05-2016, 12:59 PM
  4. Replies: 5
    Last Post: 12-04-2015, 10:19 AM
  5. Replies: 1
    Last Post: 09-07-2015, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums