Data accessibility among modules in a VB.NET application.

Posted on 2016-09-22
Last Modified: 2016-09-24
I have filled an array(,) with data that I need to access in an another module.  It appears dimensioning as "public array(,)" does not work.  How is this done? Perhaps dimensioning array(,) as object could work but I don't know how to do that either.
Question by:Gene Lenning
  • 4
  • 2
  • 2
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
ID: 41811888
what data to be filled into this dimensional array?

are you using datareader, dataset, etc to load your data?

do you have existing codes can share with us?

you may also use list or linq to do that instead of a dimensional array

Author Comment

by:Gene Lenning
ID: 41811918
This is a personal stock tracking application.  I had it poorly coded but running for several functions in VB 6.  Now I have to move it to VB.Net and I am adding more functions.  I also am trying to drift toward reusable code and code modules.  Thus I need to know how to communicate data among classes and modules.  

My program uses data downloaded to Excel spreadsheets from my accounts.  I read current price data online and perform analyses using current data to monitor stock movements and eventually will have algorithms that help me locate the stocks prime for buys and sells.  However VB.Net has hampered my progress because I don't understand the underlying aspects of applying object oriented concepts and rudimentary coding rationale; one of these concepts is simply passing array data from one module in my program to another module.  I.e. I am reading my excel data, loading it to an array and will use a DataSet to fill my Access database.  I can do all of the independent functions but I am having trouble gluing it together as an integrated program.  As I said earlier, passing data among the program modules is my current hurdle.  In my web routines I use a data reader to break out the downloaded price data and plan to use datasets and table adapters to display the data.  The types of data I am working with are stock transaction tables, account holdings, stock lists containing several items of information for each stock including my goals with the stock and warning levels of a downturn.  

So I have several functions to perform and each of these functions requires data.  Before I can perform the functions, I need to download a lot of data from historic stock transactions and have my accounts initialized to the current holdings revealing purchase prices and dates for various lots of stocks.  My database must have a means of keeping the data current or relevant. The final phase will be to add a display system to easily obtain the needed information.

This may be too much information.
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
ID: 41811939
so seems that you got a big scope for your project. well, it would need do it in phases to achieve what you want.

It appears dimensioning as "public array(,)" does not work
perhaps you can show us how you do this?
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 12

Accepted Solution

funwithdotnet earned 250 total points
ID: 41813266
In .NET, "module" generally refers to code that is accessible throughout an application. Methods (Functions/Sub) in a module are effectively added to any class in an application.

To address:
Thus I need to know how to communicate data among classes and modules.

you only need to pass the data to the method ...
Sub Main

Dim sampleStringArray() As String = {"a", "b", "c"}
Dim sampleIntegerArray() As Integer = {1, 2, 3}
Dim MyObject As SomeClass = SampleFunction(sampleStringArray, sampleIntegerArray)
Dim asdf As String
asdf = "finished" ' break here to see the output.

End Sub

Public Function SampleFunction(myStringArray() As String, myIntegerArray() As Integer) As SomeClass
    ' process input and prepare output ...
    Dim output As New SomeClass ' Object defined however you like in SomeClass.vb
	' you can pass any data to a class like this ...
	output.SomeStringArray = myStringArray '  populates the property after the "New" declaration (instantiation of a class into an Object)
	' or you can pass the input String array (myStringArray) to a New method of SomeClass that accepts input.
	' Dim output As New MyClass(myStringArray)  

	For Each stringValue As String In myStringArray
		' access each value in the array ...
		output.SomeStringProperty = stringValue  ' In this case, MyClass.SomeStringProperty  would have the last value in the array.
	output.SomeIntegerArray = myIntegerArray
	For Each integerValue As String In myIntegerArray
		' access each value in the array ...
		output.SomeIntegerProperty = integerValue  ' In this case, MyClass.SomeIntegerProperty would have the last value in the array.
	Return output
End Function

Public Class SomeClass
	Public Property SomeStringProperty As String
	Public Property SomeStringArray As String()
	Public Property SomeIntegerProperty As Integer
	Public Property SomeIntegerArray As Integer()
	Public Sub New()

	End Sub

	Public Sub New(stringArray() As String)
		SomeStringArray = stringArray
	End Sub

End Class

Open in new window

Hope that explains it for you.

Author Comment

by:Gene Lenning
ID: 41813311
Your response helps me understand this issue much better.  I had looked at a call to a module routine as a need to arrange for the data to be available to the module rather than considering the module code being an adjunct to my primary routine.  I will change my thinking on the topic.

I dimensioned my array as "Friend xlAry(,)" which makes it available to my subroutines.  Wouldn't it also be available to code addressed from a module without referencing it in my call to the module?

Thank you for your help.

Author Closing Comment

by:Gene Lenning
ID: 41813338
This exchange clears up a fundamental flaw in my thinking about coding in VB.Net .  This change in perspective will help me in other aspects of my programming efforts.
LVL 12

Expert Comment

ID: 41813462
A Friend declaration usually makes a method in a class accessible to other classes and modules in the same project,

Happy to be of assistance.  There are number of great experts here can can answer questions about all sorts of tasks, should you need it.

Good luck!

Author Comment

by:Gene Lenning
ID: 41814012
Thank you for your comments.  You are very perceptive of seeing my misconceptions on how the coding system works.  I am sure by factoring your comments into what I read will result in a better understanding of what the author is saying.  Thanks again.

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

16 Experts available now in Live!

Get 1:1 Help Now