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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting field value into 2 columns.

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
I import a textfile and use comma as my seperator. However, one of the fields contains inforamtion which I would also like to spli into seperate fields. This field currently holds both thickness and width of the part i.e. 300x30 (300 wide & 30 thk). I want to seperate the two values into seperate fields called WIDTH & THICKNESS.

Has anyone got any ideas? I know I can use the 'X' to break them but don't really know where to start with the coding.

Thanks,

Woody.
 
Okay Woody, the best way to do this is to add two additional fields to the table which will hold the resulting split data. So you have a table called mytable.db with the following 3 fields (for simplicity - Width and Thick are the new fields you added):

OldDims A 10
Width N
Thick N


Now this is the way I would script it.

Code:
var

tcDims   tCursor
arDims Array[] String
oldNums  string

endvar

if not tcDims.open(":myAlias:myTable.db")
   then   errorShow()
endif

tcDims.edit()

scan tcDims:

   oldNums = tcDims."oldDims"
   oldNums.breakApart(arDims,"X")
   tcDims."Width" = arDims[1]
   tcDims."Thick" = arDims[2]

endscan

tcDims.endEdit()
tcDims.close()



Hope this helps

Mac
:)
 
I would convert the value to upper case first or lower case to avoid potential problem down the road.

oldNums.breakApart(arDims,"X") will work for 300X30 not 300x30.

scan tcDims:

oldNums = tcDims."oldDims"

oldNums = Upper(oldNums)

oldNums.breakApart(arDims,"X")
tcDims."Width" = arDims[1]
tcDims."Thick" = arDims[2]

endscan

 
Thanks for the help but the following error comes up when running the code:-

The specified Array index is out of bounds. The index is 1, and the array limit is 0.

Any ideas why this is happening? I did get it to work but now all I get is the error!

Woody.
 
This is because you have data that is not conforming to the
nnnXnnn standard, probably blank.
Check the size or the array before trying to reference it
oldNums.breakApart(arDims,"X")
if arDims.size() = 2 then
tcDims."Width" = arDims[1]
tcDims."Thick" = arDims[2]
endif

HTH,
Richie

 
Woody'
BreakApart works fine, usually, but I've had it blow up so many times! You could write a script file to look for an x through each character in a record, starting at the first. When the x is found, make newrecord1= characters prior to it, and newrecord 2= characters after it. Use the instr() function. If you need the exact code, let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top