Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Easy one - function with table and field
Message
 
 
À
26/09/2004 17:23:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00946132
Message ID:
00946135
Vues:
13
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform