How to import comma delimited text file into datawindow (powerbuilder 11.5)

Hi, nice day, I am very new to powerbuilder and I am using PB 11.5

Does anyone know how to import a comma delimited text file into datawindow.

Text file example

"1234", "20141011", "Juan, Delacruz", "Usa", "001992345456" ...

"12345", "20141011", "Arc, Ino", "Newyork", "005765753256" ...

How to import the third column, which is the full name and the last column, which is the account number. I want to transfer the name and account number to the external data window. I tried using ImportString ( , all rows are passed in only one column ). I have three fields in my external data window. Name and account number.

Here is the code

ls_File = dw_2.Object.file_name[1] li_FileHandle = FileOpen(ls_File) li_FileRead = FileRead(li_FileHandle, ls_Text) DO WHILE li_FileRead > 0 li_Count ++ li_FileRead = FileRead(li_FileHandle, ls_Text) ll_row = dw_1.ImportString(ls_Text,1) Loop. 

Please help me with the code! Thank you.

+5
source share
2 answers

It looks like PB is expecting, by default, a separate delimited csv file (while the "c" from "csv" means "coma" ...).

Add csv! value csv! specified in the ImportString() arguments and it should fix that point (in my test field).

In addition, the columns defined in your data object must match the columns in the csv file (at least for the first columns of interest to you). If there are mode columns in the csv file, they will be ignored. But if you want to get the 1st (or 2nd) and 3rd columns, you need to define the first 3 columns. You can always hide # 1 or # 2 if you don't need it.

By the way, your code has some problems:

  • you should always check the return values ​​of function calls, such as FileOpen() , to stop processing in case of a nonexistent / unreadable file
  • You read the text file twice for the first line: once before while and the other inside the loop. Or perhaps it is supposed to ignore the first row with column headers?

FWIF, here is a working code based on yours:

 string ls_file = "c:\dev\powerbuilder\experiment\data.csv" string ls_text int li_FileHandle, li_fileread, li_count long ll_row li_FileHandle = FileOpen(ls_File) if li_FileHandle < 1 then return end if li_FileRead = FileRead(li_FileHandle, ls_Text) DO WHILE li_FileRead > 0 li_Count ++ ll_row = dw_1.ImportString(csv!,ls_Text,1) li_FileRead = FileRead(li_FileHandle, ls_Text)//read next line Loop fileclose(li_fileHandle) 
+1
source

use the datawindow_name.importfile(CSV!,file_path) method.

-1
source

All Articles