Polymorphic incrementor/decrementor
Author Message
Polymorphic incrementor/decrementor

I have a requirement to increment or decrement a field correctly,
regardless of it's data type.

I'm not quite sure how involved this task would be (can I just add 1,
or do I have to test each data type and have some special algorithm
for non numeric fields.

I'd appreciate some guidance.

Thanks.

Tue, 07 Sep 2004 05:37:47 GMT
Polymorphic incrementor/decrementor

Big words, but they don't impress us!

Suppose you have a "field" that contains the text "I am a daft field". How
do you incremnent or decrement that? You're going to have to be a bit more
specific!

Mike

Quote:
> I have a requirement to increment or decrement a field correctly,
> regardless of it's data type.

> I'm not quite sure how involved this task would be (can I just add 1,
> or do I have to test each data type and have some special algorithm
> for non numeric fields.

> I'd appreciate some guidance.

> Thanks.

Tue, 07 Sep 2004 10:38:32 GMT
Polymorphic incrementor/decrementor
Quote:

> Big words, but they don't impress us!

> Suppose you have a "field" that contains the text "I am a daft field". How
> do you incremnent or decrement that? You're going to have to be a bit more
> specific!

> Mike

In that case I want to generate 2 values x and y  such  that  x > "I
am a daft field" and y < "I am a daft field".

It doesn't matter what the values are as long as they are from
character set a-z, 1-9.  In the specific case the values x= "J" and
y="H", would suffice.

Obviously this is not applicable to data types of object which don't
have  a concept of greater or less than.

Tue, 07 Sep 2004 14:15:48 GMT
Polymorphic incrementor/decrementor
Seems like a strange request, but what-the-hell. This **may** do what you are looking for.
Assign your field's value to a Variant variable and try using the VarType to filter it.
For example, to increment the value...

Dim FieldsValue As Variant
FieldsValue = {{assign value here}}
Select Case VarType(FieldsValue)
Case 0 - 7, 14, 17
FieldsValue = FieldsValue + 1
Case 8
FieldsValue = Chr\$(Asc(FieldsValue) + 1)
End Select

The above is untested, but I think it does what you want. To decrement, change the two
occurrences of +1 to -1. Note, you may want to put some limit checks in here. For example,
the Byte values may give you some trouble at 255 if you try and increment it. Same problem
for Strings whose lead character become the one with ASCII 255. And, of course, Bytes and
Strings may also give you a problem as 0 and ASCII 0 respectively.

Rick

Quote:
> > Big words, but they don't impress us!

> > Suppose you have a "field" that contains the text "I am a daft field". How
> > do you incremnent or decrement that? You're going to have to be a bit more
> > specific!

> > Mike

> In that case I want to generate 2 values x and y  such  that  x > "I
> am a daft field" and y < "I am a daft field".

> It doesn't matter what the values are as long as they are from
> character set a-z, 1-9.  In the specific case the values x= "J" and
> y="H", would suffice.

> Obviously this is not applicable to data types of object which don't
> have  a concept of greater or less than.

Tue, 07 Sep 2004 16:20:38 GMT
Polymorphic incrementor/decrementor
If you are truly using VBScript, remark out the
'As Variant

in the first line of Rick's code.  In VBScript, everything is a variant.

Note that this will help and hinder you - you may want to "coerce" the values into a particular data type before you do the comparison, though.

Do you want comparisons to be binary or textual? (e.g., are "i am a daft field" and "I am a daft field" equal?)

: Seems like a strange request, but what-the-hell. This **may** do what you are looking for.
: Assign your field's value to a Variant variable and try using the VarType to filter it.
: For example, to increment the value...
:
: Dim FieldsValue As Variant
: FieldsValue = {{assign value here}}
: Select Case VarType(FieldsValue)
:     Case 0 - 7, 14, 17
:         FieldsValue = FieldsValue + 1
:     Case 8
:         FieldsValue = Chr\$(Asc(FieldsValue) + 1)
: End Select
:
: The above is untested, but I think it does what you want. To decrement, change the two
: occurrences of +1 to -1. Note, you may want to put some limit checks in here. For example,
: the Byte values may give you some trouble at 255 if you try and increment it. Same problem
: for Strings whose lead character become the one with ASCII 255. And, of course, Bytes and
: Strings may also give you a problem as 0 and ASCII 0 respectively.
:
: Rick
:
:

: > > Big words, but they don't impress us!
: > >
: > > Suppose you have a "field" that contains the text "I am a daft field". How
: > > do you incremnent or decrement that? You're going to have to be a bit more
: > > specific!
: > >
: > > Mike
: > >
: > In that case I want to generate 2 values x and y  such  that  x > "I
: > am a daft field" and y < "I am a daft field".
: >
: > It doesn't matter what the values are as long as they are from
: > character set a-z, 1-9.  In the specific case the values x= "J" and
: > y="H", would suffice.
: >
: > Obviously this is not applicable to data types of object which don't
: > have  a concept of greater or less than.
: >
:

Tue, 07 Sep 2004 16:31:21 GMT
Polymorphic incrementor/decrementor
Why do you want to do this ?

Perhaps that will give us a clue about what you are asking.

Quote:

>> Big words, but they don't impress us!

>> Suppose you have a "field" that contains the text "I am a daft field". How
>> do you incremnent or decrement that? You're going to have to be a bit more
>> specific!

>> Mike

>In that case I want to generate 2 values x and y  such  that  x > "I
>am a daft field" and y < "I am a daft field".

>It doesn't matter what the values are as long as they are from
>character set a-z, 1-9.  In the specific case the values x= "J" and
>y="H", would suffice.

>Obviously this is not applicable to data types of object which don't
>have  a concept of greater or less than.

Tue, 07 Sep 2004 17:03:23 GMT
Polymorphic incrementor/decrementor
Sounds like homework to me...

Quote:
> Why do you want to do this ?

Tue, 07 Sep 2004 23:59:11 GMT
Polymorphic incrementor/decrementor
Quote:

> Seems like a strange request, but what-the-hell. This **may** do what you are looking for.
> Assign your field's value to a Variant variable and try using the VarType to filter it.
> For example, to increment the value...

> Dim FieldsValue As Variant
> FieldsValue = {{assign value here}}
> Select Case VarType(FieldsValue)
>     Case 0 - 7, 14, 17
>         FieldsValue = FieldsValue + 1
>     Case 8
>         FieldsValue = Chr\$(Asc(FieldsValue) + 1)
> End Select

> The above is untested, but I think it does what you want. To decrement, change the two
> occurrences of +1 to -1. Note, you may want to put some limit checks in here. For example,
> the Byte values may give you some trouble at 255 if you try and increment it. Same problem
> for Strings whose lead character become the one with ASCII 255. And, of course, Bytes and
> Strings may also give you a problem as 0 and ASCII 0 respectively.

> Rick

Looks like a good place to start. Thank you.

Wed, 08 Sep 2004 14:35:58 GMT
Polymorphic incrementor/decrementor

Quote:

.snip...
> Looks like a good place to start. Thank you.

I think most are stilll at least somewhat curious as to what purpose
this plays????

Wed, 08 Sep 2004 23:28:48 GMT
Polymorphic incrementor/decrementor

Quote:

> .snip...
> > Looks like a good place to start. Thank you.

> I think most are stilll at least somewhat curious as to what purpose
> this plays????

It's probably just C-envy...

It's possible that nothing special will need to be done with object
references whose primary interfaces have a numeric default property.

--
Joe Foster <mailto:jlfoster%40znet.com>  Wanna buy a Bridge? <http://xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!

Thu, 09 Sep 2004 02:54:03 GMT
Polymorphic incrementor/decrementor

Quote:

>  .snip...
> > Looks like a good place to start. Thank you.

> I think most are stilll at least somewhat curious as to what purpose
> this plays????

Ahh the perils of cross-posting. See below.

Thu, 09 Sep 2004 03:55:09 GMT
Polymorphic incrementor/decrementor
I'm not impressed.  You don't have enough squiggles in that code.  VB is still  facing a devastating punctuation-mark gap when competing with C...

:
: > >
: > .snip...
: > > Looks like a good place to start. Thank you.
: >
: > I think most are stilll at least somewhat curious as to what purpose
: > this plays????
:
: It's probably just C-envy...
:
:
: It's possible that nothing special will need to be done with object
: references whose primary interfaces have a numeric default property.
:
: --
: Joe Foster <mailto:jlfoster%40znet.com>  Wanna buy a Bridge? <http://xenu.net/>
: WARNING: I cannot be held responsible for the above        They're   coming  to
: because  my cats have  apparently  learned to type.        take me away, ha ha!
:
:

Thu, 09 Sep 2004 04:11:53 GMT
Polymorphic incrementor/decrementor

Quote:

> Big words, but they don't impress us!

No, sir, we are the common sort who don't put up with that lot, indeed
we hangs them from the lamp-posts as did Jack Cade.

Quote:

> Suppose you have a "field" that contains the text "I am a daft field". How
> do you incremnent or decrement that? You're going to have to be a bit more
> specific!

Of course, any string consists of a series of base 256 or, in Unicode,
base 16834 or even 32768, "digits" where each digit is the value of a
byte or a signed or unsigned 32 bit integer.  Therefore, "I am a daft
field" is indeed a very large number under this interpretation, which
is not original, but derived from the writings of that daft man, Kurt
Godel.  Its successor is obviously "I am a daft fiele", "I am a daft
fielf" ... "I am a daft fiel" & ChrW(255) (restricting characters to
ASCII) or "I am a daft fiel" & ChrW(32767) if we are to use Unicode.

Then, the successors of the number commence with "I am a daft fiem" &
ChrW(0) because the last "digit" overflows.

The question makes perfect sense.

Quote:

> Mike

> > I have a requirement to increment or decrement a field correctly,
> > regardless of it's data type.

> > I'm not quite sure how involved this task would be (can I just add 1,
> > or do I have to test each data type and have some special algorithm
> > for non numeric fields.

> > I'd appreciate some guidance.

> > Thanks.

Thu, 09 Sep 2004 07:57:32 GMT
Polymorphic incrementor/decrementor

Quote:

> > I think most are stilll at least somewhat curious as to what purpose
> > this plays????

> Ahh the perils of cross-posting. See below.

You're working with text strings?  Why didn't you say so in the first
place!  To "decrement" a string, pick any character greater than "a"
or "0" and decrement it.  If you can't find such a character, zap the
last character.  To "increment" a string, pick any character less than
"z" or "9" and increment that.  If you can't find one, append an "m".

--
Joe Foster <mailto:jlfoster%40znet.com>     Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!

Fri, 10 Sep 2004 06:23:21 GMT
Polymorphic incrementor/decrementor

Quote:

> You're working with text strings?  Why didn't you say so in the first
> place!  To "decrement" a string, pick any character greater than "a"
> or "0" and decrement it.  If you can't find such a character, zap the
> last character.  To "increment" a string, pick any character less than
> "z" or "9" and increment that.  If you can't find one, append an "m".

No it could truly be anything (except object). Most likely are the
usual suspects, numeric, alpha and date, but there are a few booleans
there (even i can figure those one myself).