How can I feed data in an array between forms?

Posted on 2001-06-16
Last Modified: 2010-05-02

I'm having trouble feeding the results of a calculation from one form, into another form, where the data will be plotted in a graph.  At the moment, the user must save the data in a data file, then load it again into the graph-plotting programme.  This event is very slow.  The user is required to specify the number of columns of data in the file - but the number of columns is not fixed and changes frequently.  I would like to offer the user a menu-option to "Plot graph", whereupon the calculated data in columns will be fed directly into the the graph plotting programme.  I've found this to be a challenge!  

Can anyone help me to do this?

Also, how does one define the "Select All" command in the Edit menu?

Many thanks,

Question by:alouka

Accepted Solution

PeteD earned 100 total points
ID: 6197994
Whatever the format of your data, devlare the variable as public in a module,


Public Mydata(1 to 10) as Long

then you can access the data from any form in the same project.

Also to select all try:

Private Sub mnuSelectAll_Click()
    If TypeOf Me.ActiveControl Is TextBox Then
        Me.ActiveControl.SelStart = 0
        Me.ActiveControl.SelLength = Len(Me.ActiveControl)
    End If
End Sub

Expert Comment

ID: 6198068
It sounds like the data plotting program is one you didn't write. True?

If so, transferring the data may be hard. You can find the other application and use SendKeys to send it data, though it's non-trivial. How hard it is depends on the other application. Look into OLE in case the application has an OLE interface. If you are writing it, you can use OLE, too.

A Select All command depends on how you define your application and its data. When the user selects a Copy command, you need to put the data on the clipboard in a format that some other application might understand. For example, you might try separating the items with commas and the rows with semi-colons. Or tabs between items and vbCrLf between rows. There's no guarantee another application will know how to paste the data, though.

Author Comment

ID: 6200206
I wrote all the programs myself but unfortunately I am not familiar with the OLE interface.  I started learning Visual Basic about 4 months ago.  My programs are intended for electrical and control engineers. I can plot linear and log./linear graphs with or without a full grid.  The calculated results using equations for example are stored in an array and then saved in a data file. This process is fairly fast. When opening the file however, the process is very slow so I am hoping that there is a way of transferring the data stored in an array when using one form to an array in the graph plotting program which is part of the same project.
Thank you very much RodStephens and PeterG for your replies. The Select All Sub from PeterG works fine-thank you. The declaration Public A(1001,10) As Single was rejected by the program.

Thanks again.

Author Comment

ID: 6200376
Please see my comment posted earlier!

Expert Comment

ID: 6221571
The following method of transferring numeric data stored in an array from one Form to another Form actually works but it is not a direct method. Perhaps someone else knows a more direct method.

Add a TextBox on Form1(Form), name it say txtRxd, and set its properties Multiline to False and Visible to False.  Add also a command button or a menu option for listing the numeric values in the Main TextBox - Say Name: cmdList and Caption &List.
Declare the variables
eg Dim I1, Rows, Column As Integer
   Dim A(501,12) As Single ' Dimention according to the requirement.

On Form1(Code) enter the following:-

Private Sub Form_Load()
I1 = 0: Rows = 0
End Sub

Sub MatValues()
A(Row, I1) = txtRxd.Text
txtRxd.Text = ""
I1 = I1 + 1
If I1 > Column -1 Then
I1 = 0
Row = Row + 1
End If
End Sub

Sub MatValues1()
Column = CInt(txtRxd.Text)
txtRxd.Text = ""
End Sub
Public Sub cmdList_Click()
txtMain.Text = ""
For J1 = 0 To Row - 1
For I1 = 0 To Column -1
txtMain.Text = txtMain.Text & "        " & Format(A(J1, I1), "###0.0000")
Next I1
txtMain.Text = txtMain.Text & vbCrLf
Next J1
End Sub

On the second Form2(Form), add a command button and name it cmdTxd. On the Form2(Code) from which the numeric data is to be transferred, Declare the variables I1,J1,Row,Column As Integer and the array A(501,12) As Single or what ever other array used.

Private Sub cmdTxd_Click()
Form1.txtRxd.Text = Columns
For J1 = 0 To Row - 1
For I1 = 0 To Column - 1
Form1.txtRxd.Text = Format(A(J1, I1), "#0.0###")
Next I1
Next J1
End Sub

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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