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 51

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 51

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?
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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