Speeding up my code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Reed

    #1

    Speeding up my code

    All,
    I have built a database recently which resides on a network server which
    is constantly being re-structured. This is something I have no control over
    so have had to incorporate a means by which the backend moving will not
    cause too much of a headache and anyone can fix.
    I decided to use an INI file to store several variables which can and often
    do change.
    I've also added a logging procedure which writes events to a text file to
    aid me with ironing bugs out. Every time an event occurs, the READ_INI
    procedure is being called to find out paths and file names to write to which
    seems a little inefficient to me.

    I have a splash screen within the database and was thinking that I could use
    the 'Splash Loading' time to set the variables within the ini so that I do
    not have to keep reading the values within them.

    I'm still in the early stage of learning VBA so have no idea on how to do
    this. Could someone offer any advice on what to do?

    Many thanks,

    Mark


  • Bri

    #2
    Re: Speeding up my code

    Mark Reed wrote:
    All,
    I have built a database recently which resides on a network server which
    is constantly being re-structured. This is something I have no control over
    so have had to incorporate a means by which the backend moving will not
    cause too much of a headache and anyone can fix.
    I decided to use an INI file to store several variables which can and often
    do change.
    I've also added a logging procedure which writes events to a text file to
    aid me with ironing bugs out. Every time an event occurs, the READ_INI
    procedure is being called to find out paths and file names to write to which
    seems a little inefficient to me.
    >
    I have a splash screen within the database and was thinking that I could use
    the 'Splash Loading' time to set the variables within the ini so that I do
    not have to keep reading the values within them.
    >
    I'm still in the early stage of learning VBA so have no idea on how to do
    this. Could someone offer any advice on what to do?
    Yes, reading in these values once at the start of the app is the way to
    go. If you load them into a global variable then they will be accessable
    from anywhere in the code. One downside to this is that if the code gets
    'Ended' (ie untrapped error gives user the Debug or End option and they
    hit End) then these values get dumped. Global variables are declared in
    a Modual not in a forms code.

    Air Code (in a Modual):

    Option Compare Database
    Option Explicit

    Public stPath2BE as string

    Function Whatever() as String
    blah
    blah
    Stuff to read your INI file
    End Function

    Air Code (in your splash form):

    Option Compare Database
    Option Explicit

    Private Sub On_Open(Cancel as Integer)
    stPath2BE = Whatever()
    End Sub


    --
    Bri

    Comment

    • Mark Reed

      #3
      Re: Speeding up my code

      Cheers very much for the info Bri. After a little more research (Which I
      should have done first), combined with your post, I came up with the
      following which is called when the splash form is opened:


      Option Compare Database
      Option Explicit

      Global NETWORK_DRIVE As String
      Global LOG_DIRECTORY As String
      Global LOG_FILE_EXTENS ION As String
      Global ARCHIVE_DIRECTO RY As String
      Global CUSTOM_INI_LOCA TION As String
      Global XP_USERNAME As String
      Global XP_COMPUTERNAME As String


      Public Sub Init_Globals()
      NETWORK_DRIVE = KEY_Value("Keys ", "network_drive" )
      LOG_DIRECTORY = KEY_Value("keys ", "Log_directory" )
      LOG_FILE_EXTENS ION = KEY_Value("keys ", "log_file_exten sion")
      ARCHIVE_DIRECTO RY = KEY_Value("keys ", "archive")
      CUSTOM_INI_LOCA TION = KEY_Value("keys ", "custom_ini ")
      XP_USERNAME = fOSUserName
      XP_COMPUTERNAME = Environ("Comput ername")

      End Sub

      My question is that there are some variables that I would like to set in the
      same manner but I do not have the information available when the database is
      first opened. Can I save setting the GLOBAL values until later and just set
      them once the needed info is available?

      If this is the case, is it just a matter of saying 'THIS_GLOBAL =
      WHATEVER_IS_NOW _AVAILABLE' once I can reference the needed information?

      TIA,

      Mark

      "Bri" <not@here.comwr ote in message
      news:9TTrg.1320 87$iF6.94032@pd 7tw2no...
      Mark Reed wrote:
      >All,
      > I have built a database recently which resides on a network server
      >which is constantly being re-structured. This is something I have no
      >control over so have had to incorporate a means by which the backend
      >moving will not cause too much of a headache and anyone can fix.
      >I decided to use an INI file to store several variables which can and
      >often do change.
      >I've also added a logging procedure which writes events to a text file to
      >aid me with ironing bugs out. Every time an event occurs, the READ_INI
      >procedure is being called to find out paths and file names to write to
      >which seems a little inefficient to me.
      >>
      >I have a splash screen within the database and was thinking that I could
      >use the 'Splash Loading' time to set the variables within the ini so that
      >I do not have to keep reading the values within them.
      >>
      >I'm still in the early stage of learning VBA so have no idea on how to do
      >this. Could someone offer any advice on what to do?
      >
      Yes, reading in these values once at the start of the app is the way to
      go. If you load them into a global variable then they will be accessable
      from anywhere in the code. One downside to this is that if the code gets
      'Ended' (ie untrapped error gives user the Debug or End option and they
      hit End) then these values get dumped. Global variables are declared in a
      Modual not in a forms code.
      >
      Air Code (in a Modual):
      >
      Option Compare Database
      Option Explicit
      >
      Public stPath2BE as string
      >
      Function Whatever() as String
      blah
      blah
      Stuff to read your INI file
      End Function
      >
      Air Code (in your splash form):
      >
      Option Compare Database
      Option Explicit
      >
      Private Sub On_Open(Cancel as Integer)
      stPath2BE = Whatever()
      End Sub
      >
      >
      --
      Bri
      >

      Comment

      • Bri

        #4
        Re: Speeding up my code

        Once the variable is declared Public (use Public vs Global as they are
        the same thing, but Public is more consistant with other versions) it is
        initialized to 0 for numbers, empty string for text, Nothing for object,
        etc. You can assign a real value to it at any time. Doing them all in
        one place makes it easier to track them down later.

        --
        Bri

        Mark Reed wrote:
        Cheers very much for the info Bri. After a little more research (Which I
        should have done first), combined with your post, I came up with the
        following which is called when the splash form is opened:
        >
        >
        Option Compare Database
        Option Explicit
        >
        Global NETWORK_DRIVE As String
        Global LOG_DIRECTORY As String
        Global LOG_FILE_EXTENS ION As String
        Global ARCHIVE_DIRECTO RY As String
        Global CUSTOM_INI_LOCA TION As String
        Global XP_USERNAME As String
        Global XP_COMPUTERNAME As String
        >
        >
        Public Sub Init_Globals()
        NETWORK_DRIVE = KEY_Value("Keys ", "network_drive" )
        LOG_DIRECTORY = KEY_Value("keys ", "Log_directory" )
        LOG_FILE_EXTENS ION = KEY_Value("keys ", "log_file_exten sion")
        ARCHIVE_DIRECTO RY = KEY_Value("keys ", "archive")
        CUSTOM_INI_LOCA TION = KEY_Value("keys ", "custom_ini ")
        XP_USERNAME = fOSUserName
        XP_COMPUTERNAME = Environ("Comput ername")
        >
        End Sub
        >
        My question is that there are some variables that I would like to set in the
        same manner but I do not have the information available when the database is
        first opened. Can I save setting the GLOBAL values until later and just set
        them once the needed info is available?
        >
        If this is the case, is it just a matter of saying 'THIS_GLOBAL =
        WHATEVER_IS_NOW _AVAILABLE' once I can reference the needed information?
        >
        TIA,
        >
        Mark

        Comment

        Working...