Discussion Locked

VB--Converting Excel to sequential

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Using a Visual Basic pgm., I need to convert an Excel file to a sequential file which can be read by a microfocus COBOL pgm. Values for a specific column must have the same length (ex: expenses in dollars). Need the code and the window type (Standard EXE,ActiveX EXE, etc).

5 replies

by lo

Hi - I am not sure about the specifics on this but ...

If you have Excell on the PC, you should be able to launch it and either pass commands (there is a VB function/method that will let VB be the keyboard for another window, forget name. Once the application is runing with a file open, you should be able to File, Save As, and specify value to get a flat file.

If you don't have Excell, can you have the user that created the sheet do the File, Save As? You can save as .CSV, .PRN, .TXT, etc. - lo

by hwgill

This has to be run in a semi-batch mode. From a VB screen, they will enter a file name, Then hit the command button to start the process. The users are not sophisticated, so we have to do the work "behind the scenes". Thanks for your help anyway.

by tranman

1. Set up a system ODBC data source, using the EXCEL driver, and point the data source at any .xls file that will always be on your system (does not need to be the one you're going to process, but the first column name needs to be the same).

2.Create a VB program with a form that contains 2 textboxes, a command button, and an ADODC (Active-x Data Object Data control.

3. ADODC Properties: ConnectionString: Select "Use ODBC data source name" and select the data source created above. In other words, DSN=whateveryounamedit
RecordSource: A SQL statement like this: SELECT * FROM [sheet1$] IN "c:\GAD" "EXCEL 5.0;" WHERE 1 = 1;

4. Textbox1 Properties:
Datasource = the ADODC above
Datafield = any fieldname that is in the sheet you're working with (you can use F1, F2; etc.)
Visible = false

Textbox2 Properties: Doesn't matter

5. To process the Worksheet you want, just have the operator enter the name of the file they want toprocess and use that to build an appropriate select statement like the one above.

6. Set the recordsource to the sql statement (ADODC1.recordsource = "sql statement")

7. Refresh the recordset: ADODC1.recordset.refresh.

8. Process the resulting recordset just like any other:
With ADODC1.recordset
.movefirst
fixed length stringname = .fields (1)
fixed length stringname = .fields (2)
.movenext
etc.
etc.

9. Then just put yourstrings together into a record and write it out to a file.

10. This is the rock bottom absolute most simple way I know to accomplish this. In reality, you should use object variables
and declare a new ADO object, a recordset object, a query object; etc.

11. I could send you some sample code of that if you want. paulm@ksdot.org

This discussion is closed to new replies.