Results 1 to 2 of 2

Thread: Factors

  1. #1

    Thread Starter
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    Question

    Are they any pre-established Factoring functions? If not then what is the most efficient way to go about it? All I need to be able to get integers out of it. I mean simple lil numbers such as 32, 24, 10, 12, 2...etc etc. And not even completely factored, just the first two factors. Any formulas, ideas or code greatly appreciated! Thanks!
    Cbomb
    Techie

  2. #2
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    I have no way to test this, but wouldn't this work?
    Code:
    ' this function takes a long and returns an array of its factors
    Private Sub GetFactors(lngNumber As Long) As Long()
        dim lngCounter As Long
        dim intElements As Integer
    
        For lngCounter = 1 to lngNumber
            If Mod(lngNumber, lngCounter) = 0 Then
                intElements = intElements + 1
                Redim Preserve GetFactors(intElements)
                GetFactors(intElements) = lngCounter
            End If
        Next ' lngCounter
    End Sub
    Hope that helps!
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width