transfering data from vb to excel

I am currently writing a control program in vb, which reads values from an interface board and then runs a program in a loop (a continuous loop). However, for the purposes of documenting the inputs from the sensors I want to intermittently write the input valus to an excel (or a text file) for the purposes of producing graphs and performing futher analysis etc. I therefore was hoping someone could advise me about how to write the values, and the time (when the measurements were taken). Whether this could be done individually when the measurements were taken, or whether the values would have to be held in a temporary table before transfer would also be much appreciated...
P.S. as you may have realised I am new to programming...
bdprgrmrAsked:
Who is Participating?
 
85YbodyConnect With a Mentor Commented:
This should get you started on writing to a cell. Make references to Microsoft Excel Object Library.

Create a form with a text box and a command button, leave names as default names. Insert text into textbox and hit command1.


Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet


Private Sub Command1_Click()
On Error Resume Next

Set xlApp = GetObject("Excel.Application") 'if excel is open
If Error <> 0 Then
    Set xlApp = CreateObject("Excel.Application") 'if excel is not open
    Err.Clear
End If
xlApp.Visible = True 'shows excel

Set xlWB = xlApp.Workbooks.Open("D:\Temp\1234.XLS")
Set xlWS = xlWB.ActiveSheet

xlWS.Cells(1, 1).Value = Text1.Text 'populates cell A1 with text from your box

Set xlWS = Nothing
Set xlWB = Nothing
Set xlApp = Nothing


End Sub
0
 
TaconvinoConnect With a Mentor Commented:
That is the correct way of doing it, but there is another one. Try this:

Do while X    '<--- this is your loop sentence
     Open "c:\ListOfValues.xls" For Append As #1
     Print #1, VarHoldingValue & vbTab & Now
     Close #1
loop

This creates plain text file, with two columns of values separated by a "Tab" character.  Excel assumes this as a CSV file (comma separated values), and neatly places each column in the respective columns of the work sheet.

Hope this helps!

TCV
0
 
dmangConnect With a Mentor Commented:
depending on the amount of sampling output you are creating, you may want to capture the timestamp before the output loop to provide a consistent basis for later analysis of all samples generated during a particular cycle.

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.

 
TaconvinoCommented:
Solved your problem yet?
0
 
CleanupPingCommented:
bdprgrmr:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: 85Ybody and Taconvino and dmang

DanRollins -- EE database cleanup volunteer
0
All Courses

From novice to tech pro — start learning today.