Results 1 to 3 of 3

Thread: How to save data in vb6

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    15

    How to save data in vb6

    Hi every one

    i have a question about saving some data i have in a list box

    what i have done is i cane save the data to a text file with this code.

    VB Code:
    1. Public Sub mnuSaveOutput_Click()
    2. Dim filename As String
    3. Dim i As Integer
    4.  
    5. cdiaSaveOutput.Filter = "Text files (*.txt)|*.txt"
    6. cdiaSaveOutput.FilterIndex = 1
    7. cdiaSaveOutput.ShowSave
    8. filename = cdiaSaveOutput.filename
    9. '
    10. If (Len(filename) > 0) Then
    11.  Open filename For Output As #1
    12.  For i = 0 To lstOutput.ListCount - 1
    13.   Print #1, lstOutput.List(i)
    14.  Next i
    15.  Close #1
    16. End If
    17. End Sub

    what i want to know is how to save it to an excel file.

    the data that im saving is like this.

    NATURAL LIGHT TABLES FOR THE SUN AND MOON

    Location: YQK KENORA ONT

    Latitude : 49 Deg 47 Min N
    Longitude: 094 Deg 22 Min W

    Date : Jul, 2006

    ALL TIMES ARE UTC (ZULU)

    Date Morning Twilight Evening Twilight Sun Moon % Moon
    Astro Naut Civil Civil Naut Astro Rise Set Total Rise Set Illum
    ------ ----------------- ----------------- ----------------- ----------- ------
    SAT 1 99:99 08:29 09:31 03:11 04:14 99:99 10:15 02:28 16:13 16:29 05:16 25
    SUN 2 99:99 08:30 09:32 03:11 04:13 99:99 10:15 02:27 16:12 17:37 05:28 34
    MON 3 99:99 08:31 09:33 03:10 04:12 99:99 10:16 02:27 16:11 18:44 05:39 43
    TUE 4 99:99 08:32 09:34 03:10 04:12 99:99 10:17 02:27 16:09 19:54 05:51 52
    WED 5 99:99 08:34 09:35 03:09 04:11 99:99 10:18 02:26 16:08 21:07 06:05 62
    THU 6 99:99 08:35 09:36 03:09 04:10 99:99 10:18 02:26 16:07 22:23 06:22 71

    hope some one can help me

    thanks ed

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to save data in vb6

    Working with an Excel file is very different to working with a text file, so the code is more complicated. It is still understandable tho!

    If you have Excel installed on the computer the program will be running on, the easiest method for what you want will probably be using automation - see the Excel Tutorial link in my signature for explanations and examples (post here if you have problems getting it working).

  3. #3
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: How to save data in vb6

    VB Code:
    1. Dim xBook as string
    2. Dim xApp As Object
    3. Set xApp = CreateObject("Excel.Application")
    4.  
    5. 'xBook holds the name of the new Excel book created.
    6. xBook = xApp.Workbooks.Add.Name
    7.  
    8. 'References cell D5 in the workbook and puts it equal to the first line of the list box.
    9. xApp.Workbooks(xBook).Sheets("Sheet1").Cells(5, 4) = lstOutput.List(0)

    That is just the basic syntax. If you are not familiar with VBA, just record a macro in excel to help you out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width