Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem in Importing text files
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00482384
Message ID:
00482515
Views:
10
>Hi every body
>
>I have one text file containing 55,000 records. All the fields are in fixed spaces. When I check in DOS the spaces are ok. But when I use import wizard (VFP 6), it gives the text in improper spaces, looks like some spaces are missing and the remaining fields are loosing their width. It is not possible to use commas to separate the fields. Is there any way to use this text file that all the spaces should be the same as it looks in DOS (edit text file).
>

My guess is that you're displaying the file with a proportional font, so the columns don't align well (try changing the font to Courier New), or that there are embedded tabs in place of some spaces; you need to convert the tabs to spaces (a tab may expand to 1-8 spaces, depending on the character position, and you'd have to preprocess the file to do this conversion to make things fixed width.

Hopefully, changing the display font to a monospaced font will solve the problem, otherwise, you need to write code to scan the text file line-by-line and write code to expand spaces into a fixed number of space characters. It must be processed line-by-line, first character to last, since each time you replace a tab with spaces, you change the position of all the characters that follow it.
FUNCTION ConvertTabsToSpaces(tcInputFile,tnNumSpacesPerTab)
LOCAL cInputString, aStringLines(1), cThisLine, nPosn, nCtr, nLines, nSpaces, cTab, cCRLF
IF TYPE('tnNumSpacesPerTab')#'N'
   tnNumSpacesPerTab = 8
ENDIF
cTab = CHR(8)
cCRLF = CHR(13) + CHR(10)
cInputString = FILETOSTR(tcInputFile)
nLines=ALINES(aStringLines,cInputString)
cInputString = ''
FOR nCtr = 1 TO nLines
   cThisLine = aStringLines[nCtr]
   nPosn = AT(cTab,cThisLine)
   DO WHILE nPosn # 0
      nSpaces = tnNumSpacesPerTab - MOD(nPosn-1,tnNumSpacesPerTab)
      cThisLine = STUFF(cThisLine,nPosn,1,SPACE(nSpaces))
      nPosn = AT(cTab,cThisLine)
   ENDDO
   cInputString = cInputString + cThisLine + cCRLF
ENDFOR
=STRTOFILE(cInputString,tcInputFile)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform