Hi all,
I'm looking to import a textfile by using a file dialogue box (similar to the one that the open and save methods use.
I have successfully written the code to open this but am now having trouble importing the selected text file into a prestructured table using commas as delimiters.
The code below is what I have used to call the file but has anyone any ideas on the code used to import the selected textfile?
method pushButton(var eventInfo Event)
var
fbiXfile FileBrowserInfo
loRetval Logical
strValue String
endvar
;initialise local vars
loRetval = TRUE
strValue = "IMPORT.TXT"
fbiXfile.Options = browseOptPathMustExit
fbiXfile.AllowableTypes = fbtext + fbfiles
fbiXfile.Alias = "artMan:"
fbiXfile.DefaultExt = "TXT"
loRetval = getFileName(strValue, fbiXfile)
if loRetval then
msginfo ("FYI", "You have chosen to import " + strvalue + "."
endif
I have found some code which performs the required import if you specify a particular filename and its location in the code and that is listed below, but I can't seem to join the two using the selected text file instead of the predefined file location/name!!
method run(var eventInfo Event)
var
dtHandle DataTransfer
lEditState Logical
tvTable TableView
endVar
;// Set notification for user
setMouseShape(MOUSEWAIT, TRUE)
dtHandle.setSource("C:\\PartMan\\PartReport.txt", dtASCIIVar)
dtHandle.setSourceCharSet(dtANSI)
;// Enable the key violation and problems tables
;//
dtHandle.setKeyViol(TRUE)
dtHandle.setProblems(TRUE)
;// The import does not start on line 1
dtHandle.setSourceStartRow(2)
;// Setup delimited import options
;//
dtHandle.setSourceSeparator(","
dtHandle.setSourceDelimiter("\""
dtHandle.setSourceDelimitedFields(dtDELIMALLFIELDS)
;// We are always appending in this script since we force the
;// destination table to always exist
;//
dtHandle.setDest("artManartReport.DB"
dtHandle.setAppend(TRUE)
;// Reset cursor for the user
;//
setMouseShape(MOUSEARROW, TRUE)
;// Confirm the import
;//
if msgQuestion("Importing Data",
"You are about to import new contract data. Are you sure?" = "Yes" then
setMouseShape(MOUSEWAIT, TRUE)
;// Perform the import
;//
dtHandle.transferData()
;// Display table
;//
tvTable.open("artManartReport.DB"
else
setMouseShape(MOUSEARROW, TRUE)
endif
endMethod
Thanks in advance for your help,
Woody.
I'm looking to import a textfile by using a file dialogue box (similar to the one that the open and save methods use.
I have successfully written the code to open this but am now having trouble importing the selected text file into a prestructured table using commas as delimiters.
The code below is what I have used to call the file but has anyone any ideas on the code used to import the selected textfile?
method pushButton(var eventInfo Event)
var
fbiXfile FileBrowserInfo
loRetval Logical
strValue String
endvar
;initialise local vars
loRetval = TRUE
strValue = "IMPORT.TXT"
fbiXfile.Options = browseOptPathMustExit
fbiXfile.AllowableTypes = fbtext + fbfiles
fbiXfile.Alias = "artMan:"
fbiXfile.DefaultExt = "TXT"
loRetval = getFileName(strValue, fbiXfile)
if loRetval then
msginfo ("FYI", "You have chosen to import " + strvalue + "."
endif
I have found some code which performs the required import if you specify a particular filename and its location in the code and that is listed below, but I can't seem to join the two using the selected text file instead of the predefined file location/name!!
method run(var eventInfo Event)
var
dtHandle DataTransfer
lEditState Logical
tvTable TableView
endVar
;// Set notification for user
setMouseShape(MOUSEWAIT, TRUE)
dtHandle.setSource("C:\\PartMan\\PartReport.txt", dtASCIIVar)
dtHandle.setSourceCharSet(dtANSI)
;// Enable the key violation and problems tables
;//
dtHandle.setKeyViol(TRUE)
dtHandle.setProblems(TRUE)
;// The import does not start on line 1
dtHandle.setSourceStartRow(2)
;// Setup delimited import options
;//
dtHandle.setSourceSeparator(","
dtHandle.setSourceDelimiter("\""
dtHandle.setSourceDelimitedFields(dtDELIMALLFIELDS)
;// We are always appending in this script since we force the
;// destination table to always exist
;//
dtHandle.setDest("artManartReport.DB"
dtHandle.setAppend(TRUE)
;// Reset cursor for the user
;//
setMouseShape(MOUSEARROW, TRUE)
;// Confirm the import
;//
if msgQuestion("Importing Data",
"You are about to import new contract data. Are you sure?" = "Yes" then
setMouseShape(MOUSEWAIT, TRUE)
;// Perform the import
;//
dtHandle.transferData()
;// Display table
;//
tvTable.open("artManartReport.DB"
else
setMouseShape(MOUSEARROW, TRUE)
endif
endMethod
Thanks in advance for your help,
Woody.