How can I feed data in an array between forms?

Hi,

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,

Andrew
aloukaAsked:
Who is Participating?
 
PeteDConnect With a Mentor Commented:
Whatever the format of your data, devlare the variable as public in a module,

e.g.

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
0
 
RodStephensCommented:
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.
0
 
aloukaAuthor Commented:
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.
0
 
aloukaAuthor Commented:
Please see my comment posted earlier!
0
 
NickLoCommented:
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
Form1.MatValues1
For J1 = 0 To Row - 1
For I1 = 0 To Column - 1
Form1.txtRxd.Text = Format(A(J1, I1), "#0.0###")
Form1.MatValues
Next I1
Next J1
Form1.cmdList_Click
Form2.Hide
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.