getting data from a text file and putting it in an excel file using visual basic 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jetaw03
    New Member
    • Apr 2007
    • 7

    getting data from a text file and putting it in an excel file using visual basic 6.0

    guys, can you help me to get data from a text file and putting it in an excel file? my programming language is visual basic 6.0

    here is a sample data from the text file:

    ANO,BNO,TRANSDA TE,TRANSTIME,OR IGINS,DESTINATI ON,CALL_TYPE,OU TROUTE,INROUTE, CALLS,ACTUAL_MI NS,COST
    0498373386,006623322001,20070216,16:33 :35,SRO,THB,IDD ,IBEF7O,,1,0.7666666666666 67,-0.014413
    0498373386,0066 23322001,200702 23,12:59:40,SRO ,THB,IDD,0241,, 1,0.8,-0.01264
    0498373521,0096 265522113,20070 207,11:22:59,SR O,JO,IDD,0241,, 1,0.43333333333 3333,-0.019717

    i wll get the underlined data, then i will put in an excel file..

    pls help me guys..its only a project but i really need your help.i am only an amatuer vb programmer and my knowledge in it is limited.pls help..tnx!
  • albertw
    Contributor
    • Oct 2006
    • 267

    #2
    Originally posted by jetaw03
    guys, can you help me to get data from a text file and putting it in an excel file? my programming language is visual basic 6.0

    here is a sample data from the text file:

    ANO,BNO,TRANSDA TE,TRANSTIME,OR IGINS,DESTINATI ON,CALL_TYPE,OU TROUTE,INROUTE, CALLS,ACTUAL_MI NS,COST
    0498373386,006623322001,20070216,16:33 :35,SRO,THB,IDD ,IBEF7O,,1,0.7666666666666 67,-0.014413
    0498373386,0066 23322001,200702 23,12:59:40,SRO ,THB,IDD,0241,, 1,0.8,-0.01264
    0498373521,0096 265522113,20070 207,11:22:59,SR O,JO,IDD,0241,, 1,0.43333333333 3333,-0.019717

    i wll get the underlined data, then i will put in an excel file..

    pls help me guys..its only a project but i really need your help.i am only an amatuer vb programmer and my knowledge in it is limited.pls help..tnx!
    hi
    need to be an .xls or can it be a .csv file?
    1st case is nasty, you need to create a new or access an existing exelfile.
    see vb sample 'Geofacts'
    2nd case is easy, as csv stands for 'comma separate value'

    open a file 'test.csv' for output ....
    print your data as: value1,",",valu e2,",", etc
    try commas and/of semicolons and see what it does.
    close the file and open it again using exel

    have fun
    albert

    write your data into a file named 'test.csv'

    Comment

    • jetaw03
      New Member
      • Apr 2007
      • 7

      #3
      Originally posted by albertw
      hi
      need to be an .xls or can it be a .csv file?
      1st case is nasty, you need to create a new or access an existing exelfile.
      see vb sample 'Geofacts'
      2nd case is easy, as csv stands for 'comma separate value'

      open a file 'test.csv' for output ....
      print your data as: value1,",",valu e2,",", etc
      try commas and/of semicolons and see what it does.
      close the file and open it again using exel

      have fun
      albert

      write your data into a file named 'test.csv'

      man,it shud be in an existing excel file.it shud be like a report format.and unfortunately,i don't hav any idea wat a csv file is.sori man,but i need u guys to help me out with this.tnx!

      Comment

      • jetaw03
        New Member
        • Apr 2007
        • 7

        #4
        guys..pls help me..im begging you..

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by jetaw03
          guys..pls help me..im begging you..
          How much of this have you managed to accomplish so far? Can we see your code?

          We're happy to help out with specific programming problems, but are generally reluctant to sit and write the program for you.

          Comment

          • jetaw03
            New Member
            • Apr 2007
            • 7

            #6
            here are my codes:

            in the main form..

            Code:
            Private Sub cmdbrowse_Click()
                'wrap$ = Chr$(13) + Chr$(10)
                CommonDialog1.Filter = "Text Files (*.TXT)|*.TXT"
                CommonDialog1.ShowOpen
                If CommonDialog1.FileName <> "" Then
                    'formmain.MousePointer = 11
                    'Open CommonDialog1.FileName For Input As #1
                    txtfile.Text = CommonDialog1.FileName
                    End If
            End Sub
            Private Sub cmdextract_Click()
            Dim infile As Integer
                infile = FreeFile
                Open txtfile.Text For Input As #infile
                if not
                'If txtfile = Null Then
                    'MsgBox "error"
                'Else
                    frmextracting.Show
                'End If
            End Sub
            
            
            in the 2nd form which will execute the program..
            
            Private Sub Form_Load()
            'Dim file As Data
            'file = frmmain.txtfile.Text
            'Dim objExcel As Excel.Application
            'Set objExcel = New Excel.Application
                'objExcel.Workbooks.Add                  'Creates a New Excel File
                'objExcel.ActiveWorkbook.Sheets(1).Activate
                'Dim RowNum As Integer
                'RowNum = 1
                'Dim ColNum As Integer
                'ColNum = 1
                'For X = 1 To 10
                        'objExcel.Cells(RowNum, ColNum) = X
                        'ColNum = ColNum + 1
                'Next                  'This will put the Numbers 1..10 in the Excel Cells A1...A10.
            End Sub
            
            Private Sub Timer1_Timer()
                On Error Resume Next
                    If ProgressBar1.Value < ProgressBar1.Max Then
                        ProgressBar1.Value = ProgressBar1.Value + 1
                    ElseIf ProgressBar1.Value = ProgressBar1.Max Then
                        Timer1.Enabled = False
                        MsgBox " Done"
                        frmextracting.Hide
                        frmmain.Show
                    End If
            End Sub
            but its not working..i dont what are the wrong codes in it and what will be the missing codes..

            Comment

            • jetaw03
              New Member
              • Apr 2007
              • 7

              #7
              i forgot to remove the single quotation marks in the program..sorry. .i put it because they are not working.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by jetaw03
                i forgot to remove the single quotation marks in the program..sorry. .i put it because they are not working.
                That's rather awkward, because now we don't know which lines were meant to be commented out, and which weren't. Perhaps you could post another copy without any code commented out?

                If so, please put [/CODE] at the end, and [CODE] at the beginning of your code, so it is formatted properly. (I've put them backwards here so the system wouldn't interpreted them).

                Also, can you give us a better idea of how it is "not working"?

                By the way, where you are creating wrap$ you can instead use the built-in constant vbCrLf.

                Comment

                Working...