Solved

Data accessibility among modules in a VB.NET application.

Posted on 2016-09-22
8
47 Views
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.
0
Comment
Question by:Gene Lenning
  • 4
  • 2
  • 2
8 Comments
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
Comment Utility
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
0
 

Author Comment

by:Gene Lenning
Comment Utility
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.
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
Comment Utility
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?
0
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 250 total points
Comment Utility
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.
	Next
	
	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.
	Next
	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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Gene Lenning
Comment Utility
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.
0
 

Author Closing Comment

by:Gene Lenning
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:funwithdotnet
Comment Utility
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!
0
 

Author Comment

by:Gene Lenning
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

12 Experts available now in Live!

Get 1:1 Help Now