Jump to content


Click the link below to see the new game I'm developing!


Photo
- - - - -

CONV function


14 replies to this topic

#1 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 05 January 2006 - 06:43 PM

I am trying to write a custom validation logic to test if a field is a numeric or alphanumeric. I am trying to use the CONV function to do this:

IF CONV(CONV($INPUT)) = '' THEN EXIT;

It seems that this should be true if there are any alphabetic characters in the string. But it apears that the CONV function just does not run if there is a mix of letters and numbers in the string so this statement is never true. Is there a better way to differentiate between 'purely' numeric input and mixed alphanumeric input?

#2 Rick Young

Rick Young

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 266 posts
  • Gender:Male
  • Location:Guelph, Canada

Posted 05 January 2006 - 07:10 PM

If you just tested for IF CONV($INPUT) = 0.......

this of course would not work for you if someone entered 0 (zero).

I've also read about the verb NUMERIC in the logic guide, but never used it - this may be it's intended use.

HTH
Rick

#3 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 05 January 2006 - 07:57 PM

I actually tried IF CONV($INPUT) = 0 first and had no luck. It seems that if either CONV or NUMERIC (I tried this after your sugestion) see mixed alpha and numeric characters in the string they simply do not run at all. This is despite the logic guide saying that numeric returns a zero :)

I am wondering if I will have to type out the entire alphabet and do an INDEX...

#4 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,652 posts
  • Gender:Male
  • Location:Spain

Posted 05 January 2006 - 08:16 PM

Hi,

Firstly, you have to be aware of a bug in ProIV.

If any command in GenChk logic 'fails', then it acts like issuing a MSG statement, in that the cursor returns to the current field.

CONV is one of those commands, and if you put the following in a GenChk logic point, you can never get off the field...

#X = CONV("ABC")

That might explain why its not working correctly for you.

I take that as a bug, but ProIV Support didn’t agree, and it’s never been fixed......


Also, the CONV statement converts numeric Expressions. In ProIV a numeric expression could be something like 1E4, which CONV will equate to 10000.

Decimal points, positive and negative signs also equate.

So CONV or the NUMERIC special check will not validate 'pure' numeric values.

If you wish to check for 'pure' numeric characters, try this....

    #NUMERIC = 1

     FOR #X = 1 TO LEN($INPUT)
       IF NOT $INPUT(#X,#X) IN-RANGE "0","9" THEN
         #NUMERIC = 0
         LOOPEXIT
       ENDIF
     ENDFOR

     IF #NUMERIC THEN
       UMSG("REALLY A NUMERIC",-1)
     ENDIF

HTHs,

Rob D.

#5 Rick Young

Rick Young

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 266 posts
  • Gender:Male
  • Location:Guelph, Canada

Posted 05 January 2006 - 08:18 PM

another thing that I've tried only once (and can't find the function in question...) is inserting CHECK-INPUT at line 1 of the gen chk logic. Really hazy on it's use...

Another thought, which in theory ought not make a difference - create a GLOGIC to use instead of GEN CHK.

If all else fails - lgc aft and bounce around fields.

May be a version issue too - I threw this into a screen function and it worked in GENCHK:
IF CONV($INPUT) = 0
UMSG('ALPHANUM',-1) UMSG("")
ELSE
UMSG('NUM',-1) UMSG("")
ENDIF


However, now I've seen Rob's post - go with his idea :) I forgot about the 1E4 type examples....

Edited by Rick Young, 05 January 2006 - 08:21 PM.


#6 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 05 January 2006 - 08:33 PM

If any command in GenChk logic 'fails', then it acts like issuing a MSG statement, in that the cursor returns to the current field.

CONV is one of those commands, and if you put the following in a GenChk logic point, you can never get off the field...




I think this might be exactly the problem I am having.

Thanks for your help, I will try out that code.

#7 GBabula

GBabula

    Member

  • Validating
  • PipPip
  • 38 posts
  • Gender:Male
  • Location:New Jersey, USA

Posted 05 January 2006 - 09:24 PM

As Rick suggested, we use a Global Logic that checks whether each character in the input string is within the range of 0 to 9 using code similar to that posed by Rob. If each character in the input string is within 0-9 it returns "Y", otherwise "N".

We named the Global Logic "NUMBER", so in Gen Chk logic we simply do somthing like,

IF NUMBER($INPUT) = "Y"
process input
ELSE
handle error
ENDIF

The advantage with a Global Logic is reusability, plus I think it produces easier to understand code compared to IF CONV(CONV($INPUT)) = '' - I had never seen this technique before and had think about it for a moment!

#8 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 06 January 2006 - 07:56 PM

I am sorry if I am making some silly mistake here I feal like I am banging my head on the monitor for the last day. Here is the code:

IF NUMBER($INPUT) = 'Y' THEN UMSG("NUMERIC FROM",-1) ELSE EXIT;

No matter what I input I never get the message that it is numeric. I have the number global logic, and it seems to work the way I expect it to. So am I calling it incorrectly? Here is the NUMBER code if you think that might be the problem:

PARMS($STRING)
// chack that if there is any non numeric character, . not repeated and +
// or - if exists is at the begin or end
#LEN = LEN($STRING)
#START = 1
#END  = #LEN
IF $STRING(1,1) IN-ALPHA '+-' THEN
   #START = 2
ELSE
   IF $STRING(#LEN,#LEN) IN-ALPHA '+-' THEN
      #END  = #LEN - 1
   ENDIF
ENDIF
$DEC_FOUND = ''
FOR #I = #START TO #END
   $CHAR = $STRING(#I,#I)
   IF $CHAR IN-ALPHA '0123456789' THEN LOOPNEXT;
   IF $CHAR = '.' IF $DEC_FOUND = 'Y' THEN RETURN('')
         ELSE $DEC_FOUND = 'Y' LOOPNEXT;
   ENDIF
   RETURN('')
ENDFOR
RETURN('Y')

Thank you all for all the help you have given me so far.

#9 GBabula

GBabula

    Member

  • Validating
  • PipPip
  • 38 posts
  • Gender:Male
  • Location:New Jersey, USA

Posted 06 January 2006 - 08:11 PM

Interesting....our NUMBER global logic is exactly the same, including the mispelled word "chack" on line 2...this GL must be bundled into PRO-IV.

That being the case, I ran it in a test screen and it correctly recognized numeric and non-numeric input each time, including input with +/-, and decimals, so it's probably not a problem with the GL itself.

Silly question...you are using NUMBER() in GEN CHK logic, not LGC AFT, right?

#10 Joseph Bove

Joseph Bove

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 756 posts
  • Gender:Male
  • Location:Ramsey, United States

Posted 06 January 2006 - 08:41 PM

Tyleulen,

One other thing to check.

In line one of your global logic, in the step column, do you have an 'A'?

If you have a 'P' then I believe that nothing is returned.

I'm not sure what happens if you don't specify either.

hth,

Joseph

#11 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 06 January 2006 - 10:30 PM

My newbishness is showing here. I am still getting used to this VIP environment. I think the answer to both your questions is yes.

On the events tab, the logic I am building and referring to NUMBER in is in the General Check column, though the tooltip also refers to it as Custom Validation.

The global logic NUMBER is listed in the select tab as being type Alpha and not Numeric or Procedure, which I think is the step column you are referring to...

#12 GBabula

GBabula

    Member

  • Validating
  • PipPip
  • 38 posts
  • Gender:Male
  • Location:New Jersey, USA

Posted 06 January 2006 - 10:44 PM

It sounds like you've got it setup correctly, so now I'm perplexed. We're not using VIP yet (still using Native) so I'm wondering if the reason this is not working has something to do with the VIP environment. Perhaps one of our VIP gurus could see if this GL works for them.

#13 Joseph Bove

Joseph Bove

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 756 posts
  • Gender:Male
  • Location:Ramsey, United States

Posted 06 January 2006 - 11:03 PM

Tyleulen,

The global logic NUMBER is listed in the select tab as being type Alpha and not Numeric or Procedure, which I think is the step column you are referring to...


Yes, that's basically it.

Why don't you hardcode RETURN('Y') right before the FOR loop to make sure you are getting that far. If you still get nothing, then the problem is probably not with the global logic but something else.

hth,

Joseph

#14 Tyleulen

Tyleulen

    Advanced

  • Members
  • PipPipPip
  • 59 posts
  • Gender:Male

Posted 06 January 2006 - 11:48 PM

I think I have figured out my problem. It seems that the field is being padded out with spaces and these spaces are being interpreted by the NUMBER GL as alphanumeric characters. But luckily, there is also the TRIM GL. So, this snipet works:

IF NUMBER(TRIM($INPUT," ","A")) = 'Y' THEN UMSG('NUMERIC',-1) ELSE UMSG('NOT NUMERIC',-1);

Thank you all for your help, I was pulling my hair out there for a while.

#15 GBabula

GBabula

    Member

  • Validating
  • PipPip
  • 38 posts
  • Gender:Male
  • Location:New Jersey, USA

Posted 06 January 2006 - 11:54 PM

I was pulling my hair out there for a while.

Pro-IV makes one do that at times (at least that's the story I use when explaining where my hair went...)

Glad to hear you figured it out. Good luck in your Pro-IV newbie-ness!



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Click the link below to see the new game I'm developing!