Solved

VB Public Arrays...

Posted on 2009-06-29
6
160 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now