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!

Splitting strings in a table

Status
Not open for further replies.

youwannawhat

Programmer
Oct 3, 2001
43
0
0
US
I have a table with 4000+ records. One of the fields contains a measurement(500cc, 1ml, etc). The user wanted to limit the choices for entry type(ml,cc,etc), so I added another field to the table for measurement type, and dropped a combobox on the form with valid choices for the user. Hence, the user can now enter .05 in the old text box, and choose the appropriate unit of measure from the combobox. All future entries should be fine.

But, now I'm stuck with 4000+ previously entered records that I must programmatically split. If it says 500cc, I need to keep the 500, and push the 'CC' to the new field in the table.

The field is a char(10), and the entries can vary anywhere from .0025g to 500GTT, or maybe just '.1'.

Any suggestions?

Thanks,

PB
 
Well, here's a workhorse method:

SCAN
STORE '' TO tmpAmount
STORE '' TO tmpMeasure
STORE '' TO tmpChar
FOR nIndex = 1 TO LEN(MyTable.Field)
tmpChar = SUBSTR(MyTable.Field1, nIndex, 1)
IF tmpChar $ '1234567890.'
tmpAmount = tmpAmount + tmpChar
ELSE
tmpMeasure = tmpMeasure + tmpChar
ENDIF
NEXT
REPLACE MyTable.Field1 WITH tmpAmount
REPLACE MyTable.Field2 WITH tmpMeasure
ENDSCAN

Of course this code hasn't been tested, but you get the idea.
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top