Solved

VB Public Arrays...

Posted on 2009-06-29
6
159 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now