dbTalk Databases Forums  

help with InStrRev and Len

comp.databases.ms-access comp.databases.ms-access


Discuss help with InStrRev and Len in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bobh
 
Posts: n/a

Default help with InStrRev and Len - 01-23-2009 , 02:28 PM






Something is just not right and I can not figure it out, I need help

the below is a line from a Do Loop routine I have and I'm trying to
check how any characters there are after the decimal point. The CUnits
field is defined as DataType=Number, FieldSize=Double, Format=Fixed,
Decimals=2.
On the input form first record for CUnits I enter .01
on the second record for CUnits I enter .1

if I open the table I see that the entered .01 is stored as 0.01 and
the entered .1 is stored as 0.10

in Debug mode
for the first record
strLen = InStrRev(MyRec!CUnits, ".")

if I hold the cursor over CUnits it shows -> .01 and strLen=2

movenext, loop

if I hold the cursor over CUnits for the second record it shows -> 0.1
and strLen=2

which is what I don't understand,
first, why is the debug mode display different of the two records?
second, why is strLen 2 characters for this second record?
help, thanks
bobh.

Reply With Quote
  #2  
Old   
MGFoster
 
Posts: n/a

Default Re: help with InStrRev and Len - 01-23-2009 , 03:35 PM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Man, don't worry about it. You can display the number in any format
using the Format() function and, if in a Control, the Format property:

If number = .01 (actually stored as 0.01):

Format(number, "#.##") = 0.01
Format(number, ".##") = .01

Format property: ".##" will display as above.

If the number = .1 (actually stored as 0.10):

Format(number, "#.##") = 0.10
Format(number, ".#") = .1

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSXo4DYechKqOuFEgEQIH4ACePfCjPh83Hcs7B39YnmxIba NpLpEAn0Sv
dzXX+yl7/fLjtsLntBfvcB5M
=yUHk
-----END PGP SIGNATURE-----

bobh wrote:
Quote:
Something is just not right and I can not figure it out, I need help

the below is a line from a Do Loop routine I have and I'm trying to
check how any characters there are after the decimal point. The CUnits
field is defined as DataType=Number, FieldSize=Double, Format=Fixed,
Decimals=2.
On the input form first record for CUnits I enter .01
on the second record for CUnits I enter .1

if I open the table I see that the entered .01 is stored as 0.01 and
the entered .1 is stored as 0.10

in Debug mode
for the first record
strLen = InStrRev(MyRec!CUnits, ".")

if I hold the cursor over CUnits it shows -> .01 and strLen=2

movenext, loop

if I hold the cursor over CUnits for the second record it shows -> 0.1
and strLen=2

which is what I don't understand,
first, why is the debug mode display different of the two records?
second, why is strLen 2 characters for this second record?
help, thanks
bobh.

Reply With Quote
  #3  
Old   
bobh
 
Posts: n/a

Default Re: help with InStrRev and Len - 01-26-2009 , 11:53 AM



On Jan 23, 4:35*pm, MGFoster <m... (AT) privacy (DOT) com> wrote:
Quote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Man, don't worry about it. *You can display the number in any format
using the Format() function and, if in a Control, the Format property:

If number = .01 (actually stored as 0.01):

* *Format(number, "#.##") = 0.01
* *Format(number, ".##") *= *.01

* *Format property: *".##" *will display as above.

If the number = .1 (actually stored as 0.10):

* *Format(number, "#.##") = 0.10
* *Format(number, ".#") * = *.1

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. *I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSXo4DYechKqOuFEgEQIH4ACePfCjPh83Hcs7B39YnmxIba NpLpEAn0Sv
dzXX+yl7/fLjtsLntBfvcB5M
=yUHk
-----END PGP SIGNATURE-----



bobhwrote:
Something is just not right and I can not figure it out, I need help

the below is a line from a Do Loop routine I have and I'm trying to
check how any characters there are after the decimal point. The CUnits
field is defined as DataType=Number, FieldSize=Double, Format=Fixed,
Decimals=2.
On the input form first record for CUnits I enter .01
on the second record for CUnits I enter .1

if I open the table I see that the entered .01 is stored as 0.01 and
the entered .1 is stored as 0.10

in Debug mode
for the first record
strLen = InStrRev(MyRec!CUnits, ".")

if I hold the cursor over CUnits it shows -> .01 and strLen=2

movenext, loop

if I hold the cursor over CUnits for the second record it shows -> 0.1
and strLen=2

which is what I don't understand,
first, why is the debug mode display different of the two records?
second, why is strLen 2 characters for this second record?
help, thanks
bobh.- Hide quoted text -

- Show quoted text -

I wish I didn't have to worry about it but I do because this line is
not evaluating correctly or as how I think it should.

if I enter .1 as a value this line in my code will evaluate to a
"2" in the strLen and it should be "1" so the if statement does not
evaluate correctly
strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".")

I need to know how many characters after the decimal point because if
I were to add a whole number to the decimal part I need it to work out
correctly.
example: a whole number say - 60 + InStrRev(MyRec!CUnits, ".") would
equal 61 and I need it to equal 70 since .1 equals 10 so, in the
above case if the InStrRev would calculate correctly then I could

strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".") & 0
then tmp1 would have 10 and adding that to a value of 60 would equal
70
bobh.


Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: help with InStrRev and Len - 01-26-2009 , 12:10 PM



bobh wrote:

Quote:
On Jan 23, 4:35 pm, MGFoster <m... (AT) privacy (DOT) com> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Man, don't worry about it. You can display the number in any format
using the Format() function and, if in a Control, the Format property:

If number = .01 (actually stored as 0.01):

Format(number, "#.##") = 0.01
Format(number, ".##") = .01

Format property: ".##" will display as above.

If the number = .1 (actually stored as 0.10):

Format(number, "#.##") = 0.10
Format(number, ".#") = .1

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSXo4DYechKqOuFEgEQIH4ACePfCjPh83Hcs7B39YnmxIba NpLpEAn0Sv
dzXX+yl7/fLjtsLntBfvcB5M
=yUHk
-----END PGP SIGNATURE-----



bobhwrote:

Something is just not right and I can not figure it out, I need help

the below is a line from a Do Loop routine I have and I'm trying to
check how any characters there are after the decimal point. The CUnits
field is defined as DataType=Number, FieldSize=Double, Format=Fixed,
Decimals=2.
On the input form first record for CUnits I enter .01
on the second record for CUnits I enter .1

if I open the table I see that the entered .01 is stored as 0.01 and
the entered .1 is stored as 0.10

in Debug mode
for the first record
strLen = InStrRev(MyRec!CUnits, ".")

if I hold the cursor over CUnits it shows -> .01 and strLen=2

movenext, loop

if I hold the cursor over CUnits for the second record it shows -> 0.1
and strLen=2

which is what I don't understand,
first, why is the debug mode display different of the two records?
second, why is strLen 2 characters for this second record?
help, thanks
bobh.- Hide quoted text -

- Show quoted text -



I wish I didn't have to worry about it but I do because this line is
not evaluating correctly or as how I think it should.

if I enter .1 as a value this line in my code will evaluate to a
"2" in the strLen and it should be "1" so the if statement does not
evaluate correctly
strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".")

I need to know how many characters after the decimal point because if
I were to add a whole number to the decimal part I need it to work out
correctly.
example: a whole number say - 60 + InStrRev(MyRec!CUnits, ".") would
equal 61 and I need it to equal 70 since .1 equals 10 so, in the
above case if the InStrRev would calculate correctly then I could

strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".") & 0
then tmp1 would have 10 and adding that to a value of 60 would equal
70
bobh.
Could you use Cstr()
Num = 123.4567
? Num
123.4567
Num = 12.34
? Instr(cstr(num),".")
3
Num = 1
? Instr(cstr(num),".")
0


Expanding this
Num = 123.4567
? num
123.4567
? len(Cstr(num)) -Instr(cstr(num),".")
4
Num = 12.345
? len(Cstr(num)) -Instr(cstr(num),".")
3


What if the number is an integer
Num = 1
? len(Cstr(num)) -Instr(cstr(num),".")
1
? len(Cstr(num)) - IIF(Instr(cstr(num),".") > 0 , Instr(cstr(num),"."),
Len(cstr(num)))
0

Would this help?


Reply With Quote
  #5  
Old   
bobh
 
Posts: n/a

Default Re: help with InStrRev and Len - 01-26-2009 , 03:50 PM



On Jan 26, 1:10*pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
bobh wrote:
On Jan 23, 4:35 pm, MGFoster <m... (AT) privacy (DOT) com> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Man, don't worry about it. *You can display the number in any format
using the Format() function and, if in a Control, the Format property:

If number = .01 (actually stored as 0.01):

* Format(number, "#.##") = 0.01
* Format(number, ".##") *= *.01

* Format property: *".##" *will display as above.

If the number = .1 (actually stored as 0.10):

* Format(number, "#.##") = 0.10
* Format(number, ".#") * = *.1

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. *I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSXo4DYechKqOuFEgEQIH4ACePfCjPh83Hcs7B39YnmxIba NpLpEAn0Sv
dzXX+yl7/fLjtsLntBfvcB5M
=yUHk
-----END PGP SIGNATURE-----

bobhwrote:

Something is just not right and I can not figure it out, I need help

the below is a line from a Do Loop routine I have and I'm trying to
check how any characters there are after the decimal point. The CUnits
field is defined as DataType=Number, FieldSize=Double, Format=Fixed,
Decimals=2.
On the input form first record for CUnits I enter .01
on the second record for CUnits I enter .1

if I open the table I see that the entered .01 is stored as 0.01 and
the entered .1 is stored as 0.10

in Debug mode
for the first record
strLen = InStrRev(MyRec!CUnits, ".")

if I hold the cursor over CUnits it shows -> .01 and strLen=2

movenext, loop

if I hold the cursor over CUnits for the second record it shows -> 0.1
and strLen=2

which is what I don't understand,
first, why is the debug mode display different of the two records?
second, why is strLen 2 characters for this second record?
help, thanks
bobh.- Hide quoted text -

- Show quoted text -

I wish I didn't have to worry about it but I do because this line is
not evaluating correctly or as how I think it should.

if I enter * *.1 * as a value this line in my code will evaluate to a
"2" in the strLen and it should be "1" so the if statement does not
evaluate correctly
strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".")

I need to know how many characters after the decimal point because if
I were to add a whole number to the decimal part I need it to work out
correctly.
example: a whole number say - 60 + InStrRev(MyRec!CUnits, ".") would
equal 61 and I need it to equal 70 since .1 equals 10 *so, in the
above case if the InStrRev would calculate correctly then I could

strLen = InStrRev(MyRec!CUnits, ".")
if strLen = 1 then
tmp1 = InStrRev(MyRec!CUnits, ".") & 0
then tmp1 would have 10 and adding that to a value of 60 would equal
70
bobh.

Could you use Cstr()
Num = 123.4567
? Num
* 123.4567
Num = 12.34
? Instr(cstr(num),".")
* 3
Num = 1
? Instr(cstr(num),".")
* 0

Expanding this
Num = 123.4567
? num
* 123.4567
? len(Cstr(num)) -Instr(cstr(num),".")
* 4
Num = 12.345
? len(Cstr(num)) -Instr(cstr(num),".")
* 3

What if the number is an integer
Num = 1
? len(Cstr(num)) -Instr(cstr(num),".")
* 1
? len(Cstr(num)) - IIF(Instr(cstr(num),".") > 0 , Instr(cstr(num),"."),
Len(cstr(num)))
* 0

Would this help?- Hide quoted text -

- Show quoted text -
Hi,
As you can imagine I've been working on this for a few days know and I
think I have what I need below. In all my debug mode testing it seems
to be calculating the right values for each user entered value, as in
if CUnits is .1 or .10 or 1 or 3.7 or 4.01 etc....

Else
'calculate the whole hours number
tmp1 = Left(MyRec!CUnits, InStr(1, MyRec!CUnits, ".") - 1) *
60
'calculate the mins and then add the two numbers and update the
field
strLen = Len(Mid(MyRec!CUnits, InStr(1, MyRec!CUnits, ".") +
1))
If strLen = 1 Then
tmp2 = Mid(MyRec!CUnits, InStr(1, MyRec!CUnits, ".") + 1)
tmp2 = tmp2 & 0
ElseIf strLen = 2 Then
tmp2 = Right(MyRec!CUnits, InStrRev(MyRec!CUnits, "."))
End If
MyRec.Edit
MyRec!TotMins = tmp1 + tmp2
MyRec.Update
End If
MyRec.MoveNext
Loop

bobh.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.