Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a text file by selecting the file name. 1

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
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 = ":partMan:"
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(":partMan:partReport.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(":partMan:partReport.DB")

else

setMouseShape(MOUSEARROW, TRUE)

endif


endMethod


Thanks in advance for your help,

Woody.
 
Hi again,

I know this is tricky but there must be someone here who can help me out!!!

Woody.
 
Woody,

Um, have you tried something like this:

Code:
method run(var eventInfo Event)
var
    dtHandle        DataTransfer
    lEditState      Logical
    tvTable         TableView

    fbiXfile        FileBrowserInfo
    loRetval        Logical
    strImpFile      String
endVar

    ;initialise local vars
    loRetval = TRUE
    strImpFile = "PartReport.txt"

    fbiXfile.Options = browseOptPathMustExit
    fbiXfile.AllowableTypes = fbtext + fbfiles
    fbiXfile.Alias = ":PartMan:"
    fbiXfile.DefaultExt = "TXT"

    loRetval = getFileName( strImpFile, fbiXfile)
    if not loRetval then
       Message( "Import Cancelled..." )
       return
    endIf

    ;// Set notification for user
    setMouseShape(MOUSEWAIT, TRUE)

    dtHandle.setSource( strImpFile, dtASCIIVar)
    dtHandle.setSourceCharSet(dtANSI)
    
    ; *snip*
    ; rest of the script should be fine...

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top