Solved

VB Public Arrays...

Posted on 2009-06-29
6
165 Views
Last Modified: 2012-05-07
Hi,
Im trying to tidy up some code i have, by creating some public functions etc..

Through out my code i have lots of different Subs, many of which have the same 3 arrays in them:

Add0Array = Array("", "0", "00", "000", "0000", "00000")
DisabledArray = Array("10202", "20202", "514", "40200", "80202", "222") 'array to hold UAC values of disabled users
DomainArray = Array("172.20.xxx.xx", "172.20.xx.xx")

I want to declare these publicly like a few of my other key variables, however i cant seem to work out how?

Option Explicit
 
Public StrDomain As String
Public ADG As String
 
Public objConnection As New ADODB.Connection
Public objCommand As New ADODB.Command
Public objRecordset As New ADODB.Recordset
 
Public JPStart As New SpeedUp
Public JPEnd As New SpeedUp
Public JPboarders As New AddBoarders
 
Public DisabledArray()
Public Add0Array()
Public DomainArray()
 
Add0Array = Array("", "0", "00", "000", "0000", "00000")
DisabledArray = Array("10202", "20202", "514", "40200", "80202", "222") 'array to hold UAC values of disabled users
DomainArray = Array("172.20.xx.xx", "172.20.xx.xxx")

Open in new window

0
Comment
Question by:jamiepryer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24734608
You can declare it as Public inside a module and fill the arrays when the application load
0
 

Author Comment

by:jamiepryer
ID: 24734619
Hi,
thanks for the reply, but im new to this all ......

 can i not just define the values of the array once, along with all my other public variables, rather then within each of the Subs?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24734642
If you want to acess the arrays in all project you can do this:
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox(Add0Array(0).ToString)
    End Sub
 
End Class
 
 
Module myVariables
 
    Public DisabledArray() As String = {"", "0", "00", "000", "0000", "00000"}
    Public Add0Array() As String = {"10202", "20202", "514", "40200", "80202", "222"}
    Public DomainArray() As String = {"172.20.xx.xx", "172.20.xx.xxx"}
 
End Module

Open in new window

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:jamiepryer
ID: 24734659
Hi,
Where would i put that code, sorry?
Im doing this in VB, within excel (2003)
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 250 total points
ID: 24734689
You have choose Microsoft Visual Basic.Net area :)
In the VBE (ALT+F11) insert a new module. In that module declare the public variables
' MODULE
Option Explicit

Public DisabledArray()
Public Add0Array()
Public DomainArray()

Then, in thisWorkBook, fill the arrays

Option Explicit

Private Sub Workbook_Open()
    Add0Array = Array(" ", "0", "00", "000", "0000", "00000")
    DisabledArray = Array("10202", "20202", "514", "40200", "80202", "222") 'array to hold UAC values of disabled users
    DomainArray = Array("172.20.xx.xx", "172.20.xx.xxx")
End Sub
 
After this you can use in everywhere.
0
 

Author Closing Comment

by:jamiepryer
ID: 31597838
thanks for the help
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question