By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

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

P: 7
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,TRANSDATE,TRANSTIME,ORIGINS,DESTINATION,CA LL_TYPE,OUTROUTE,INROUTE,CALLS,ACTUAL_MINS,COST
0498373386,006623322001,20070216,16:33:35,SRO,THB,IDD,IBEF7O,,1,0.766666666666667,-0.014413
0498373386,006623322001,20070223,12:59:40,SRO,THB, IDD,0241,,1,0.8,-0.01264
0498373521,0096265522113,20070207,11:22:59,SRO,JO, IDD,0241,,1,0.433333333333333,-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!
Apr 19 '07 #1
Share this Question
Share on Google+
7 Replies


100+
P: 267
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,TRANSDATE,TRANSTIME,ORIGINS,DESTINATION,CA LL_TYPE,OUTROUTE,INROUTE,CALLS,ACTUAL_MINS,COST
0498373386,006623322001,20070216,16:33:35,SRO,THB,IDD,IBEF7O,,1,0.766666666666667,-0.014413
0498373386,006623322001,20070223,12:59:40,SRO,THB, IDD,0241,,1,0.8,-0.01264
0498373521,0096265522113,20070207,11:22:59,SRO,JO, IDD,0241,,1,0.433333333333333,-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,",",value2,",", 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'
Apr 19 '07 #2

P: 7
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,",",value2,",", 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!
Apr 20 '07 #3

P: 7
guys..pls help me..im begging you..
Apr 23 '07 #4

Expert 5K+
P: 8,434
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.
Apr 23 '07 #5

P: 7
here are my codes:

in the main form..

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbrowse_Click()
  2.     'wrap$ = Chr$(13) + Chr$(10)
  3.     CommonDialog1.Filter = "Text Files (*.TXT)|*.TXT"
  4.     CommonDialog1.ShowOpen
  5.     If CommonDialog1.FileName <> "" Then
  6.         'formmain.MousePointer = 11
  7.         'Open CommonDialog1.FileName For Input As #1
  8.         txtfile.Text = CommonDialog1.FileName
  9.         End If
  10. End Sub
  11. Private Sub cmdextract_Click()
  12. Dim infile As Integer
  13.     infile = FreeFile
  14.     Open txtfile.Text For Input As #infile
  15.     if not
  16.     'If txtfile = Null Then
  17.         'MsgBox "error"
  18.     'Else
  19.         frmextracting.Show
  20.     'End If
  21. End Sub
  22.  
  23.  
  24. in the 2nd form which will execute the program..
  25.  
  26. Private Sub Form_Load()
  27. 'Dim file As Data
  28. 'file = frmmain.txtfile.Text
  29. 'Dim objExcel As Excel.Application
  30. 'Set objExcel = New Excel.Application
  31.     'objExcel.Workbooks.Add                  'Creates a New Excel File
  32.     'objExcel.ActiveWorkbook.Sheets(1).Activate
  33.     'Dim RowNum As Integer
  34.     'RowNum = 1
  35.     'Dim ColNum As Integer
  36.     'ColNum = 1
  37.     'For X = 1 To 10
  38.             'objExcel.Cells(RowNum, ColNum) = X
  39.             'ColNum = ColNum + 1
  40.     'Next                  'This will put the Numbers 1..10 in the Excel Cells A1...A10.
  41. End Sub
  42.  
  43. Private Sub Timer1_Timer()
  44.     On Error Resume Next
  45.         If ProgressBar1.Value < ProgressBar1.Max Then
  46.             ProgressBar1.Value = ProgressBar1.Value + 1
  47.         ElseIf ProgressBar1.Value = ProgressBar1.Max Then
  48.             Timer1.Enabled = False
  49.             MsgBox " Done"
  50.             frmextracting.Hide
  51.             frmmain.Show
  52.         End If
  53. End Sub
but its not working..i dont what are the wrong codes in it and what will be the missing codes..
Apr 26 '07 #6

P: 7
i forgot to remove the single quotation marks in the program..sorry..i put it because they are not working.
Apr 26 '07 #7

Expert 5K+
P: 8,434
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.
Apr 26 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.