Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting all types to string
Message
 
 
To
04/05/2004 16:09:12
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00900921
Message ID:
00901071
Views:
16
Hi Renoir,

TRANSFORM of course is a simple solution already provided by Sergey, but just in case I have a special method:
********************************************************************
*  Description.......: btcc_Container.BTC_ValStr: method to convert value into literal string representation
*  Calling Samples...:
*  Parameter List....: value_arg, tlShowCrit
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 10/04/2001 02:03:31 PM
********************************************************************
* * Added this stub method for support of type-specific subclasses.
* This function returns a literal value suitable for inclusion in search criterion.
lparameters value_arg, tlShowCrit	&& takes 2 arguments (last one is optional argument)
* value_arg:  value of textbox control to be converted into a literal.
* tlShowCrit: optional argument for converting numeric into $ 
local lcRetVal, lcType
lcType= vartype(m.value_arg)
do case
case m.lcType ='C'
	if left(alltrim(m.value_arg),1)='"' && First character is already "
		lcRetVal= alltrim(m.value_arg)
	else
		lcRetVal= '"' + alltrim(m.value_arg) + '"'	&& default treats values as character strings
	endif

case m.lcType = "D"
	local dTosVal
* check for empty date special case - doesn't like strict date syntax
	if empty(m.value_arg)
		lcRetVal ='{}'					&& most concise notation for empty date
	else
* return value converted into a literal, using strict date format to avoid annoying errors
		dTosVal = dtos(m.value_arg)		&& character-string date in a yyyymmdd format
		lcRetVal = '{^' + substr(m.dTosVal, 1, 4) ;
			+ '-' + substr(m.dTosVal, 5, 2) ;
			+ '-' + substr(m.dTosVal, 7, 2) ;
			+ '}'	&& default treats values as character strings
	endif
otherwise
	if m.tlShowCrit && Price, Mortgage, etc.
		lcRetVal=alltrim(transform(m.value_arg,"@$ 999,999,999,999"))
	else
		lcRetVal=transform(m.value_arg)
	endif
endcase

return m.lcRetVal
>In the following the type of MyTableField is character. MyCursor.MyField could be character, an integer, a logical, etc. Without an involved IIF statement or CASE statements, is there a way to convert any type to a string without knowing what it is beforehand?
>
>
>
>LPARAMATERS MyCursor
>
>MyVar = ''
>
>SELECT MyCursor
>
>SCAN
>   MyVar = MyVar + ALLTRIM(MyField) + '|'
>ENDSCAN
>
>INSERT INTO MyTable (MyTableField) VALUES (MyVar)
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform