[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Data accessibility among modules in a VB.NET application.

Posted on 2016-09-22
Medium Priority
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 54

Assisted Solution

by:Ryan Chong
Ryan Chong earned 1000 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 54

Assisted Solution

by:Ryan Chong
Ryan Chong earned 1000 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?
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.

LVL 12

Accepted Solution

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 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