Results 1 to 2 of 2

Thread: Global Code

  1. #1
    100 Club wpeacock's Avatar
    Join Date
    2015-09
    Location
    Bunbury, West Australia
    Posts
    161
    Login to Give a bone
    0

    Default Global Code

    I'm using the following code (edited) where I evaluate an options value then perform some code then use the same procedure to evaluate the options value then perform another piece of code etc etc.

    Although this works fine, it's very clunky and I'm sure it's not a good example of proper coding.

    How can I make an option's value, with its if statement global? Or rather how do I make it into user friendly code?

    Regards

    Wayne



    Code:
    Private Sub CmdDraw_Click()
        InsertSoleBoards
        InsertJacks
        InsertJackNuts
       
    End Sub
    
    '---------------------------
    Private Sub InsertSoleBoards()
     'Snip..
    
        If Opt12ReturnBay = True Then
               LHbay = -1270
               RHbay = 1270
          ElseIf Opt18ReturnBay = True Then
               LHbay = -1829
               RHbay = 1829
           Else
               LHbay = -2438
               RHbay = 2438
        End If
    'code that uses these values
    End Sub
    '----------------------------------------
    Private Sub InsertJacks()
     'Snip..
    
        If Opt12ReturnBay = True Then
               LHbay = -1270
               RHbay = 1270
          ElseIf Opt18ReturnBay = True Then
               LHbay = -1829
               RHbay = 1829
           Else
               LHbay = -2438
               RHbay = 2438
        End If
    'code that uses these values
    End Sub
    '------------------------------
    Private Sub InsertJackNuts()
     'Snip..
    
        If Opt12ReturnBay = True Then
               LHbay = -1270
               RHbay = 1270
          ElseIf Opt18ReturnBay = True Then
               LHbay = -1829
               RHbay = 1829
           Else
               LHbay = -2438
               RHbay = 2438
        End If
    'code that uses these values
    End Sub

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Global Code

    By "global", I take it that you mean that your subs use Opt## variables that need to be stored globally somewhere else. To make the subs more self-reliant, convert the global vars to "local" arguments. For example:
    Code:
    Private Sub InsertJacks( bOption As Boolean)
       If bOption = True Then
       '....
    End Sub
    Also, none of these subs appear to do anything more than setting other vars. They don't insert anything as the name would imply. You might think about abandoning these, and just use LhBay and RhBay arguments to supply the info directly to the code that needs it.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Allow Other Code Compilers for ARX Code
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2013-02-10, 08:06 AM
  2. Insert vbscript code has not code
    By buzz in forum AMEP General
    Replies: 3
    Last Post: 2008-02-09, 03:08 AM
  3. Convert VBA code to VB code
    By Robert Platt in forum VBA/COM Interop
    Replies: 20
    Last Post: 2007-08-15, 10:13 PM

Posting Permissions

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