Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Public Arrays...

Posted on 2009-06-29
6
Medium Priority
?
168 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

722 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