CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Project need help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
handsprince



Joined: 12 Mar 2006
Posts: 20

View user's profile Send private message

Project need help
PostPosted: Thu Mar 16, 2006 8:00 am     Reply with quote

i'm doing the project :- receive signal from LM35DZ sensor then store the temperature, time and date into MMC card,after that send the data to computer via rs232 interface with VB language. if can i want to display the temperature graph using microsoft excel. anyone can give me advice or example??? thank for your kindness

Last edited by handsprince on Thu Mar 16, 2006 9:04 pm; edited 1 time in total
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 16, 2006 1:47 pm     Reply with quote

You can't be serious, can you?

"teach me how to write the program", isn't that what your are supposed to be learning in class by doing your own homework?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
handsprince



Joined: 12 Mar 2006
Posts: 20

View user's profile Send private message

sorry!!!
PostPosted: Thu Mar 16, 2006 9:12 pm     Reply with quote

Can you give me an example???sorry for my last posted
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 16, 2006 10:05 pm     Reply with quote

This isn't a VB programming forum. But if you are trying to figure out how to create an excel spreadsheet from VB and populate some data then hear is an example. Study it all you want but don't ask questions about it in this forum. There are VB forums out there where you can find this kind of information.
Code:

Private Sub Export()

  Dim rstData As Recordset
  Dim rstTime As Recordset
  Dim mycriteria As String
  Dim rstChannel As Recordset
  Dim x As Integer
  Dim y As Integer
  Dim data() As Single
  Dim starttime As Date
  Dim i As Long
 
  pbImport.Value = 0
 
  'Make sure that the database is opened
  If db Is Nothing Then
    MsgBox "Database not opened.", vbExclamation, "No Database"
    pbImport.Visible = False
    Exit Sub
  End If
 
  'Setup an excel file
  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xlSheet As Excel.Worksheet
 
  'Create the excel file
  Set xlApp = CreateObject("Excel.Application")
  Set xlBook = xlApp.Workbooks.Add
  Set xlSheet = xlBook.Worksheets(1)
 
  'Create the title
  xlSheet.Cells(2, 2).Value = txtTitle
  xlSheet.Range("B2:K2").HorizontalAlignment = 7
 
  'Create a recordset for each distinct time sample
  mycriteria = "SELECT DISTINCT Time FROM [Test Data] ORDER BY Time"
  Set rstTime = db.OpenRecordset(mycriteria, dbOpenDynaset)
  With rstTime
    If Not (.EOF And .BOF) Then
      'Populate recordset
      .MoveLast
      .MoveFirst
    Else
      MsgBox "No data to work with.", vbExclamation, "No Data"
      pbImport.Visible = False
      Exit Sub
    End If
  End With
 
  'Setup some status info
  y = 1
  Label1 = "Creating Excel headings..."
  pbImport.Max = List.ListCount + 1
 
  'Add the time column heading
  xlSheet.Cells(3, y).Value = "Time, min."
   
  'Add the channel column headings
  For i = 0 To List.ListCount - 1
    If List.Selected(i) Then
      pbImport.Value = y
      y = y + 1
      xlSheet.Cells(3, y).Value = List.List(i)
    End If
    DoEvents
  Next i

  'Add the time data
  With rstTime
    '-- First we will export the "Float" value
    x = 4  'Start on the fourth row
    Label1 = "Creating Excel row " + Format(x - 4, "0") + " of " + _
             Format(.RecordCount, "0") + "..."
    y = 1  'Column one
    pbImport.Max = List.SelCount + 1
    ReDim data(List.SelCount + 1)
    data(y) = 0
   
    'Get the data base on the time
    mycriteria = "SELECT * FROM [Test Data] WHERE Time = #" + _
                 Format(.Fields("Time")) + "#ORDER BY Channel"
    Set rstData = db.OpenRecordset(mycriteria, dbOpenDynaset)
   
    'Store the data in an array
    For i = 0 To List.ListCount - 1
      If List.Selected(i) Then
        pbImport.Value = y
        y = y + 1
        mycriteria = "Channel = " + Format(List.ItemData(i), "0")
        rstData.FindFirst mycriteria
        If rstData.NoMatch Then
          data(y) = 0
        Else
          data(y) = rstData.Fields("Voltage")
        End If
      End If
      DoEvents
    Next i
   
    'Add the data to the spreadsheet
    xlSheet.Range(xlSheet.Cells(x, 1), xlSheet.Cells(x, y)).Value = data
    xlSheet.Cells(x, 1).Value = "Float"
   
    'Continue with the next time's data
    x = x + 1
    .MoveNext
   
    '-- This is the data - store the first time so that we can display delta t
    If Not .EOF Then
      starttime = .Fields("Time")
    End If
   
    'Do the rest of the data
    Do While Not .EOF
      'Tell the user what we are doing
      Label1 = "Creating Excel row " + Format(x - 4, "0") + " of " + _
               Format(.RecordCount, "0") + "..."
      y = 1
      pbImport.Max = List.SelCount + 1
     
      'Store the time as the first element
      ReDim data(List.SelCount + 1)
      data(y) = (.Fields("Time") - starttime) * 1440
     
      'Get the data for this time
      mycriteria = "SELECT * FROM [Test Data] WHERE Time = #" + _
                   Format(.Fields("Time")) + "#ORDER BY Channel"
      Set rstData = db.OpenRecordset(mycriteria, dbOpenDynaset)
           
      'Load the data into the array
      For i = 0 To List.ListCount - 1
        If List.Selected(i) Then
          pbImport.Value = y
          y = y + 1
          mycriteria = "Channel = " + Format(List.ItemData(i), "0")
          rstData.FindFirst mycriteria
          If rstData.NoMatch Then
            'No data
            data(y) = 0
          Else
            'Found data
            data(y) = rstData.Fields("Voltage")
          End If
        End If
        DoEvents
      Next i
     
      'Add the data to the spreadsheet
      xlSheet.Range(xlSheet.Cells(x, 1), xlSheet.Cells(x, y)).Value = data
      x = x + 1
      .MoveNext
    Loop
  End With
 
  'We are done
  pbImport.Visible = False
  Label1 = "Saving file..."
 
  'Now we need to save the file
Save_Again:
  Do
    Err = 0
    On Error Resume Next
   
    'Get a file name
    CommonDialog.CancelError = True
    CommonDialog.DefaultExt = ".xls"
    CommonDialog.Filter = "Excel (*.xls)|*.xls"
    CommonDialog.filename = ""
    CommonDialog.Flags = cdlOFNCreatePrompt Or cdlOFNExplorer
    CommonDialog.ShowSave
   
    'Make sure that the user didn't cancel
    If Err = cdlCancel Then Exit Do
   
    'Make sure that the file does not exist
    If Dir(CommonDialog.filename) <> "" Then
      MsgBox "Please select a new file name.", vbExclamation, "Save As"
    End If
  Loop While Dir(CommonDialog.filename) <> ""
  If Err <> cdlCancel Then
    On Error GoTo Export_Error
   
    'Save the file
    xlSheet.SaveAs CommonDialog.filename
    ' Close Excel with the Quit method on the Application object
    xlApp.Quit
  End If
 
  Label1 = ""
 
  ' Release the object variables
  Set xlApp = Nothing
  Set xlBook = Nothing
  Set xlSheet = Nothing
   
  'Close up
  rstData.Close
  rstTime.Close
  MsgBox "File saved as " + CommonDialog.filename, vbInformation, "Success"
  Exit Sub

Export_Error:
  'Methodname method of classname class failed
  If Err = 1004 Then GoTo Save_Again
 
  'Another error occured
  MsgBox Error$(Err), vbExclamation
 
  ' Release the object variables
  Set xlApp = Nothing
  Set xlBook = Nothing
  Set xlSheet = Nothing
  pbImport.Visible = False
  Label1 = ""
  Exit Sub
 
End Sub
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group