Solved

VB Public Arrays...

Posted on 2009-06-29
6
166 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

630 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