Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic Field Names in a Replace Cmd
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00810786
Message ID:
00810789
Views:
8
This message has been marked as the solution to the initial question of the thread.
Ken,

STR() creates spaces in the field names and FoxPro doesn't like it. Change STR() to TRANSFORM().
fldname = "field_" + TRANSFORM(fld)
>I have a gui to turn a delimited dat file into a database and I wanted to shorten the code. So I made dynamic field names but it doesn't work. Here is the code. Help is greatly appreciated.
>
>
>
>local fld, fldname
>set delete on
>set defa to 'c:\rmiweb'
>gcCsvName = getfile('DAT', 'Open Csv:')
>if empty(gcCsvName)
>	return 0
>else
>	create cursor temp ;
>		(field_1 C(254), field_2 C(100), 
field_3 C(100), field_4 C(100), field_5 C(100), field_6 C(100),;
>		field_7 C(100), field_8 C(100), field_9 C(100))
>	append from (gcCsvName) delimited
>	scan
>		for i = 1 to 9
>			do case
>			case i = 1
>				fld = i+1
>                                    *This is where im setting my dynamic fld Name
>				fldname = "field_" + str(fld)
>				a = at('|',field_1,1)
>				a1 = alltrim(substr(field_1,1,a-1))
>                                    *This is where I'm using it
>				replace (fldname) with a1
>			case i > 1 and i < 9
>				fld = i+1
>				fldname = "field_" + str(fld)
>				z = at('|',field_1,i-1)
>				b = at('|',field_1,2)
>				b1 = alltrim(substr(field_1,z+1,(b-1) - z))
>				replace (fldname) with b1
>			case i = 9
>				fld = i+1
>				fldname = "field_" + str(fld)
>				z = at('|',field_1,i-1)
>				h = at('|',field_1,8)
>				h1 = alltrim(substr(field_1,z+1,(h-1) - z))
>				replace (fldname) with h1
>		endcase
>	endfor
>endscan
>browse
>endif
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform