Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Number length


Message #1 by "Andrew Payne" <andrewpayne.plastics@b...> on Mon, 20 May 2002 10:35:22
I have a list of numbers as part of a combo box, the numbers can have 
either 4 or 5 digits before the decimal point and none or 1 after eg

   5601
   5601.1
   5601.2
   20235
   20235.1
   20235.2

I need to find out the leght of the number before the decimal point.
Does anyone know how i can do this.

Thanks Andrew
Message #2 by joe.dunn@c... on Mon, 20 May 2002 10:49:09 +0000
Try this:

Function FindIntLength(pValue as Double) as Integer
' finds length of integer part of a value
' by deriving the integer of the value and returning length of the Integer
Dim strInt As String

  strInt = CStr(Int(pValue))    ' converts the integer of the value passed
to a string
  FindIntLength = Len(Trim(strInt))   ' finds the length and returns it to
the calling function

End Function

you can call the function in a query or through other VBA code

to reduce the code to a minimum, just do:

Len(Trim(CStr(Int([pValue])))

However, it is clearer if you create a function and call it!



*************************************************************************

This e-mail may contain confidential information or be privileged. It is intended to be read and used only by the named
recipient(s). If you are not the intended recipient(s) please notify us immediately so that we can make arrangements for its return:
you should not disclose the contents of this e-mail to any other person, or take any copies. Unless stated otherwise by an
authorised individual, nothing contained in this e-mail is intended to create binding legal obligations between us and opinions
expressed are those of the individual author.

The CIS marketing group, which is regulated for Investment Business by the Financial Services Authority, includes:
Co-operative Insurance Society Limited Registered in England number 3615R - for life assurance and pensions
CIS Unit Managers Limited Registered in England and Wales number 2369965  - for unit trusts and PEPs
CIS Policyholder Services Limited Registered in England and Wales number 3390839 - for ISAs and investment products bearing the CIS
name
Registered offices: Miller Street, Manchester M60 0AL   Telephone  0161-832-8686   Internet  http://www.cis.co.uk   E-mail
cis@c...

CIS Deposit and Instant Access Savings Accounts are held with The Co-operative Bank p.l.c., registered in England and Wales number
990937, P.O. Box 101, 1 Balloon Street, Manchester M60 4EP, and administered by CIS Policyholder Services Limited as agent of the
Bank.

CIS is a member of the General Insurance Standards Council

CIS & the CIS logo (R) Co-operative Insurance Society Limited

********************************************************************************
Message #3 by "Amy Wyatt" <amyw@c...> on Mon, 20 May 2002 14:17:03
You can also use the Instr function for this:
     Dim intLenNum as Integer
     Dim sngNum as Single

     sngNum=your number
     intLenNum=Instr(1,str(sngNum),".")
     If intLenNum=0 Then  'Means no decimal in number
          intLenNum=Len(Str(sngNum))
     Else
          intLenNum=intLenNum-1
     End If

Amy

> I have a list of numbers as part of a combo box, the numbers can have 
e> ither 4 or 5 digits before the decimal point and none or 1 after eg

>    5601
 >   5601.1
 >   5601.2
 >   20235
 >   20235.1
 >   20235.2

> I need to find out the leght of the number before the decimal point.
D> oes anyone know how i can do this.

> Thanks Andrew
Message #4 by Barry Dancis <bdancis@c...> on Mon, 20 May 2002 10:07:32 -0400
I like Joe's solution of creating a function but the trim function is only
needed if you use the Str function (see Amy's solution) which adds a leading
space.

Separately, you didn't say if numbers such as 0.54 are allowed and if they
are, whether they count as 0 or 1 digits.

If it counts as 1 digit, then Joe's code works just fine because vb adds a
leading zero

Otherwise you will have to test for 0 to return the correct value. The test
can be done in the function or by the caller of the funtion. Since how a
leading zero is counted will depend on the needs of the caller of the
function, I would add the test there:

If Your_Number < 1 then
  intLenNum = 0
else
  intLenNum = FindIntLength(Your_Number)
end if

Barry


----- Original Message -----
From: <joe.dunn@c...>
To: "Access" <access@p...>
Sent: Monday, May 20, 2002 6:49 AM
Subject: [access] Re: Number length


>
> Try this:
>
> Function FindIntLength(pValue as Double) as Integer
> ' finds length of integer part of a value
> ' by deriving the integer of the value and returning length of the Integer
> Dim strInt As String
>
>   strInt = CStr(Int(pValue))    ' converts the integer of the value passed
> to a string
>   FindIntLength = Len(Trim(strInt))   ' finds the length and returns it to
> the calling function
>
> End Function
>
> you can call the function in a query or through other VBA code
>
> to reduce the code to a minimum, just do:
>
> Len(Trim(CStr(Int([pValue])))
>
> However, it is clearer if you create a function and call it!
>
>
>
> *************************************************************************
>
> This e-mail may contain confidential information or be privileged. It is
intended to be read and used only by the named recipient(s). If you are not
the intended recipient(s) please notify us immediately so that we can make
arrangements for its return: you should not disclose the contents of this
e-mail to any other person, or take any copies. Unless stated otherwise by
an authorised individual, nothing contained in this e-mail is intended to
create binding legal obligations between us and opinions expressed are those
of the individual author.
>
> The CIS marketing group, which is regulated for Investment Business by the
Financial Services Authority, includes:
> Co-operative Insurance Society Limited Registered in England number
3615R - for life assurance and pensions
> CIS Unit Managers Limited Registered in England and Wales number
369965  - for unit trusts and PEPs
> CIS Policyholder Services Limited Registered in England and Wales number
3390839 - for ISAs and investment products bearing the CIS name
> Registered offices: Miller Street, Manchester M60 0AL   Telephone
0161-832-8686   Internet  http://www.cis.co.uk   E-mail cis@c...
>
> CIS Deposit and Instant Access Savings Accounts are held with The
Co-operative Bank p.l.c., registered in England and Wales number 990937,
P.O. Box 101, 1 Balloon Street, Manchester M60 4EP, and administered by CIS
Policyholder Services Limited as agent of the Bank.
>
> CIS is a member of the General Insurance Standards Council
>
> CIS & the CIS logo (R) Co-operative Insurance Society Limited
>
>
****************************************************************************
****
>
>

Message #5 by "Gerald, Rand" <RGerald@u...> on Mon, 20 May 2002 09:50:23 -0500
Andrew,

The following formula will give the order of magnitude of a number:

Int(Log(Number) / Log(10))

And adding 1 will give the number of digits before the decimal:

Int(Log(Number) / Log(10)) + 1

Rand E Gerald
Database Specialist
Information Services / Operations
Bah=E1'=ED National Office
1233 Central St.
Evanston IL 60201
(xxx) xxx-xxxx

-----Original Message-----
From: Andrew Payne [mailto:andrewpayne.plastics@b...]
Sent: Monday, May 20, 2002 5:35 AM
To: Access
Subject: [access] Number length

I have a list of numbers as part of a combo box, the numbers can have
either 4 or 5 digits before the decimal point and none or 1 after eg

   5601
   5601.1
   5601.2
   20235
   20235.1
   20235.2

I need to find out the leght of the number before the decimal point.
Does anyone know how i can do this.

Thanks Andrew
Message #6 by "Ian Ashton" <ian@c...> on Tue, 21 May 2002 08:02:27 +0100
Andrew,

The following will give you what you want. 
It returns 1 for numbers such as 0.1234. 
You could use: If Int(0.1234) = 0 then ... to test for this.

	len(format$(12345.789,"#"))

Ian Ashton

-----Original Message-----
From: Andrew Payne [mailto:andrewpayne.plastics@b...]
Sent: Monday, May 20, 2002 10:35 AM
To: Access
Subject: [access] Number length


I have a list of numbers as part of a combo box, the numbers can have 
either 4 or 5 digits before the decimal point and none or 1 after eg

   5601
   5601.1
   5601.2
   20235
   20235.1
   20235.2

I need to find out the leght of the number before the decimal point.
Does anyone know how i can do this.

Thanks Andrew

  Return to Index