Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using field values to format SQL output
Message
From
27/08/2008 11:57:50
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01342035
Message ID:
01342235
Views:
17
Good stuff, but much of the issue is that the value in the field for the example is "W9N", but it could just as easily be "ABC10AN" or something else. I'm trying to write something that will parse it apart not knowing exactly what it will be. There could be required alpha, then numeric (ABC10N), or there could be required numeric and alpha (12310A) or alpha and alphanumeric (ABC5AN). I can't see a way to handle it without knowing the values ahead of time.

I have control of these values, so if there is a way to enter them that would make it better, please tell me.

>Jay,
>
>From the top of my head - needs testing
>
>lcFormat = 'W9N'
>
>lcFieldLength = chrtran(chrtran(m.lcFormat,'1234567890',''),'1234567890','')
>
>if not m.lcFieldLength ==""
>   FieldLength = val(m.lcFieldLength)
>endif
>
>lnPos = at(m.lcFieldLength, m.lcFormat)
>
>if m.lnPos > 1 && We have a letter before number
>  lcStartLetters = left(m.lcFormat, m.lnPos - 1)
>endif
>
>Take also the rest of the formatting option
>
>
>Also I can not understand the code you posted. CHRTRAN() returns a character expression, but you treat it as numeric.
>
>
>>I have the code below to handle numeric. I have similar CASEs to handle other types. But now I have this to parse:
>>
>>W9N
>>
>>Which means that the output must have a "W" for the first character, followed by 9 numeric values. How can I handle these types of things?
>>
>>		CASE INLIST(FieldVal,'N')
>>			* Numeric
>>			FormatValue = 'N'
>>			FieldLength = CHRTRAN(FieldValue, FormatValue,'')
>>			FieldType = CHRTRAN(FieldValue, FieldLength,'')
>>			IF FieldLength = 0
>>				FieldLength = 100
>>			ENDIF
>>
>>
>>>I think we may have one function, say, FormatValue with these parameters
>>>
>>>FormatValue(FormatVal, FieldValue)
>>>
>>>FormatVal is something like '9N'
>>>and the FieldValue is the actual value of the field, e.g. SSN = "123456789"
>>>
>>>From 9N we get 9 and N so we know that we need to have 9 digits.
>>>
>>>Our case statements would only be for A, N, date formats and also for cases where we need to use particular first character, I guess.
>>>
>>>But I'm just thinking aloud, I'm not sure exactly if I'm thinking in the right direction or how easy it would be to implement.
>>>
>>>
>>>>So quick and such a seemingly simple answer. It must be harder than that.
>>>>
>>>>Well, I see it is much more involved, but maybe I'm wrong. I don't understand your example. Could you use my sample and explain that further?
>>>>
>>>>Also, I would think that there must be case statements, etc., to handle the different scenarios. Should I have a case statement based on the fields, CASE tFieldName = 'SSN', etc. for each field, then parse accordingly?
>>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform