Solved

How can I feed data in an array between forms?

Posted on 2001-06-16
5
145 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:alouka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
PeteD earned 100 total points
ID: 6197994
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
 
LVL 3

Expert Comment

by:RodStephens
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.
0
 

Author Comment

by:alouka
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.
0
 

Author Comment

by:alouka
ID: 6200376
Please see my comment posted earlier!
0
 
LVL 1

Expert Comment

by:NickLo
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
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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