[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 115
  • Last Modified:

Data accessibility among modules in a VB.NET application.

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
Gene Lenning
Asked:
Gene Lenning
  • 4
  • 2
  • 2
3 Solutions
 
Ryan ChongCommented:
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
 
Gene LenningRetiredAuthor Commented:
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
 
Ryan ChongCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
funwithdotnetCommented:
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
 
Gene LenningRetiredAuthor Commented:
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
 
Gene LenningRetiredAuthor Commented:
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
 
funwithdotnetCommented:
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
 
Gene LenningRetiredAuthor Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now