Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Missing something...

Status
Not open for further replies.

PogoWolf

Programmer
Mar 2, 2001
351
US
hello all!
ok, I've GOT to be missing something.. I have some code here (see below) that supposed to do 1 of 3 things..

1) CHeck the lenght of input to a SSN file..
if it's less then 9.. then go on..
2) IF it's blank or equals zero then create a random
9 digit number
3) if non of the above give an error code...

I think the logic is good... but VFP can't seem to figure this on out.. am I doing something wrong?!

thank you in advance....
The PogoWolf



IF LEN(alltrim(thisform.SSN.value)) < 9 THEN
IF ISBLANK(alltrim(thisform.SSN.value)) OR alltrim(thisform.SSN.value) = &quot;0&quot; THEN
x = 10000000001
DO WHILE x > 999999999
x = INT((999999999-1+1)*RAND()+1)*SECONDS()
ENDDO

IF LEN(STR(x)) < 9 then
FOR y = 0 to 9 - LEN(STR(x))
ToAdd = ToAdd + &quot;0&quot;
ENDFOR
thisform.SSN.value = ToAdd + upper(STR(x))
ELSE
thisform.SSN.value = upper(STR(x))
ENDIF
ELSE
&& ok, it's not Blank and doesn't = 0 then it's an Error
IF iOk <> 0 AND iOk < 9 then
ELSE
iOk = 9 &&Error Code
ENDIF
ENDIF
ENDIF ******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
STR by default creates a string that is 10 characters long, padded by blanks on the left if needed.

Try testing for len(alltrim(str(ssn))).


 
Well, that's something worth knowing.. LOL
I'm still a bit of newbie with FoxPro

but that was the issue. Thank you! =)

******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
I am just cut/copy/paste your code and added my comments:
********************************************************
** 1) CHeck the lenght of input to a SSN file..
** if it's less then 9.. then go on..
IF LEN(alltrim(thisform.SSN.value)) < 9 THEN

** 2) IF it's blank or equals zero then create a random
** 9 digit number
IF ISBLANK(alltrim(thisform.SSN.value)) ;
OR alltrim (thisform.SSN.value) = &quot;0&quot; THEN
x = 10000000001
DO WHILE x > 999999999
x = INT((999999999-1+1)*RAND()+1)*SECONDS()
ENDDO

IF LEN(STR(x)) < 9 then
FOR y = 0 to 9 - LEN(STR(x))
ToAdd = ToAdd + &quot;0&quot;
ENDFOR
thisform.SSN.value = ToAdd + upper(STR(x))
ELSE
thisform.SSN.value = upper(STR(x))
ENDIF

** tHIS IS WHERE IT WENT WRONG.. i FEEL >>>>
ELSE
&& ok, it's not Blank and # 0 then it's an Error
IF iOk <> 0 AND iOk < 9 then
ELSE
iOk = 9 &&Error Code
ENDIF
** tHIS IS WHERE IT WENT WRONG <<<<<
**
ENDIF

** Instead of all the above code for step2,
** i would suggest the following code
IF ISBLANK(alltrim(thisform.SSN.value)) ;
OR alltrim (thisform.SSN.value) = &quot;0&quot; THEN
thisform.SSN.value = SUBSTR(SYS(2015),3,10)
ENDIF
ELSE

** 3) if non of the above give an error code...
** I do not understand if iOk is properly initialised
** I have added the following line
iOk = 9 &&Error Code
ENDIF
*************************************************

In simple ... the whole thing can be coded ...

IF ALLTRIM(thisform.SSN.value) = &quot;0&quot; .OR. ;
EMPTY(thisform.SSN.value)
thisform.SSN.value = SUBSTR(SYS(2015),3,10)
ENDIF
IF ! BETWEEN(LEN(alltrim(thisform.SSN.value)),1,8)
&&& MAKE YOUR ERROR CODE ....
iOk = 9 &&Error Code
ENDIF

ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
WOW!!! talk about shrinking code.. LOL I wish I knew FoxPro like that... but I'm running Version 3.0.. and looks like all those commands will work..
but I'm not sure about the .OR. I'm not seeing that in the help file...

will that work with 3.0.. and if so.. what does it do? =)
******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
OR command will work with VFP3.
IF (... .AND. .... ) .AND. ( ... .or. ... ) .OR.
ENDIF
similar constructions are valid in all VFP versions
:) ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
cool! I didn't know the or needed to have periods around it.. no wonder my multi-cases like that where not working correctly.. LOL

Thank you again!!!!
******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
you do not need periods around and or or statments. That syntax has not been required for about 6 versions. In fact the only thing you need periods around in version 3 is .NULL. that was fixed in version 5.

BTW why are you running version 3 it was horribly buggy. The only reason that I know if is if you still need to run (or walk) on a Win 3.1 machine or a Mac.

 
About shrinking code, you do not need to put the THEN clause after an IF.

Example
LOCAL llCondition

llCondition = .T.

IF llCondition THEN
*- Piece of code
ENDIF

Is the same as

IF llCondition
*- Piece of code
ENDIF

HTH,
Weedz (Wietze Veld)
veld4663@exact.nl
The Netherlands

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Playing the part of Devils Advocate, Most people like to put the &quot;-&quot; in the SSAN.
Does your input format account for that in the form.

if not
lcSSAN = strtran(alltrim(thisform.SSN.value), &quot;-&quot; , &quot;&quot;)
do case
case lcSSAN = &quot;0&quot; .or. Empty(lcSSAN)
thisform.SSN.value = SUBSTR(SYS(2015),3,10)
case val(lcSSAN) < 100000000 .or. LEN(lcSSAN) < 9
&&& MAKE YOUR ERROR CODE ....
iOk = 9 &&Error Code
endcase

If you use this val(lcSSAN) < 100000000
I do not know why you need
lcSSAN = &quot;0&quot; .or. Empty(lcSSAN) .or. LEN(lcSSAN) < 9

so smaller code would be

If val(strtran(alltrim(thisform.SSN.value), &quot;-&quot; , &quot;&quot;)) < 100000000
thisform.SSN.value = SUBSTR(SYS(2015),3,10)
else
&&& MAKE YOUR ERROR CODE ....
iOk = 9 &&Error Code
endif David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
WOW! Thank for all the input guys! (and gals if there are any)

but to Answer 'fluteplr' question about running 3.0.. because this is what the company told me to do.. that should answer all the questions..LOL
******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
One more thought to help add to the confusion. Speaking as an Ex-CPA turned programmer, are you sure that you want to insert what may appear to be valid numbers into an empty SSN field? How will you know who has supplied numbers and who still needs to provide them? In one application I wrote a few years back I used '000000000' to indicate that the number was not available (i.e. they hadn't given it to us yet) and '999999999' to indicate that the number was not applicable (i.e. a foreign citizen who doesn't/can't have a SSN).

Steve
 
Great suggestion! I'll need to work that into my VB version of this project.. (which I'll start on hopefully VERY soon..heeheh)

BTW, I do have another question I just posted.. if you would be so kind as to check that one also?! =)


And a big thanks again for all the suggestions.. it really does make the life of a newbie SO much easier.. =)
******
Darkness... Bleakness...
and Plastic forks...
--The PogoWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top