Results 1 to 20 of 25

Thread: Please Help Bulid VBA Code/Application

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #22
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,675
    Location
    After some more research I finally found a way to calculate Location with a math function, instead of using 47 Select Case steps

    Below are the 2 procedures that allow me to correctly calculate the location based on any number provided. It also returns the value as a String (since leading zeros are required by Astra for this txt file).

    [vba]Function Ceiling(Number As Double) As Long
    Ceiling = -Int(-Number)
    End Function

    Sub LocationCount(XStart As Integer, Section As String)
    Dim i As Integer
    i = XStart
    If Ceiling((i - 1) / 3) = ((i - 1) / 3) Then
    If Len(CStr(i)) = 1 Then
    Section = "00" & i
    ElseIf Len(CStr(i)) = 2 Then
    Section = "0" & i
    End If
    ElseIf Ceiling((i - 2) / 3) = ((i - 2) / 3) Then
    If Len(CStr(i)) = 1 Then
    Section = "00" & i-1
    ElseIf Len(CStr(i)) = 2 Then
    Section = "0" & i-1
    End If
    Else
    If Len(CStr(i)) = 1 Then
    Section = "00" & i-2
    ElseIf Len(CStr(i)) = 2 Then
    Section = "0" & i-2
    End If
    End If

    End Sub[/vba]

    Astra, I've attached a new version of the RackForms database that incorporates this new procedure into the Location setup. What this means is that you can calculate the number of any Location you want, no matter what X-coor you use. This also means that you won't have to write more Select Case steps if you want to calculate Locations above X-coor 139.
    Last edited by CreganTur; 06-20-2008 at 08:56 AM.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

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