Solved

How can I feed data in an array between forms?

Posted on 2001-06-16
5
141 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
5 Comments
 
LVL 2

Accepted Solution

by:
PeteD earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Please see my comment posted earlier!
0
 
LVL 1

Expert Comment

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

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

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

10 Experts available now in Live!

Get 1:1 Help Now