Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Easy one - function with table and field
Message
 
 
To
26/09/2004 17:23:59
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00946132
Message ID:
00946135
Views:
14
This message has been marked as a message which has helped to the initial question of the thread.
FUNCTION replacechar(tctable, cfield)
* The 'CLOSE ALL' command shouldn't be used casually.
*** CLOSE ALL
IF USED(tctable)
	SELECT (tctable)
ELSE
	SELECT 0
	USE (tctable)
ENDIF	
	
* Scan commnad w/o any clauses starts scan from the top sp 'GO TOP' isn't necessary
***GO TOP
SCAN
	* Get  old value 
	lcOldValue = EVALUATE(cField)
	lcNewValue = STRTRAN(lcOldValue, '(', '')
	lcNewValue = STRTRAN(lcNewValue, ')', '-')
	* Use name expression to put new value back into the field
	REPLACE (cField) WITH lcNewValue
ENDSCAN
>
>I think I have an easy one here for anyone willing to help. Unfortunately, I have spent a number of hours on this and I can't make it work.
>
>I have a function to replace two character portions of a field in a table (see below) with two parameters, one a table (tctable), and the other a field (cfield). Unfortunately, when I pass a field name to the function, it either doesn't work (the variable cfield is not valid) or it replaces the value in the field with the name passed to it, ie "cfield". I am not sure how to pass the field name to the function so that the changes are being made to the actual field values.
>
>any suggestions? thanks.
>
>FUNCTION replacechar(tctable, cfield)
>CLOSE ALL
>USE (tctable)
>GO top
>SCAN
>oldstring = 'cfield'
>newstring1 = STRTRAN(oldstring,'(', '')
>newstring2 = strTRAN(newstring1,') ','-')
>replace 'cfield' WITH newstring2
>ENDSCAN
>ENDfunc
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform