Solved

Loop Statment.

Posted on 2004-10-02
5
160 Views
Last Modified: 2010-05-02

The evaluation of SixSix will be to a thousand. How can the expression be writen with less code.
 Can live with (If TePCom1Lenght > 0 And TePCom1Lenght < 6 Then
            SixSix = 6)


 Function SixSix(TePCom1Lenght As Currency)
         If TePCom1Lenght < 0 Then
            Exit Function
            Else
         If TePCom1Lenght > 0 And TePCom1Lenght < 5.5 Then
            SixSix = 6
            Else
         If TePCom1Lenght > 5.5 And TePCom1Lenght <= 11.5 Then
            SixSix = 12
            Else
         If TePCom1Lenght > 11.5 And TePCom1Lenght <=17.5  Then
            SixSix = 18
            Else
         If TePCom1Lenght > 17.5 And TePCom1Lenght <= 23.5 Then
            SixSix = 24
            Else
         If TePCom1Lenght > 23.5 And TePCom1Lenght <= 29.5 Then
            SixSix = 30
          Exit Function
          End If
         End If
        End If
       End If
      End If
     End If

Thanks Lynn
0
Comment
Question by:newt25
5 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12210492
Hi newt25,

This is not exact, as if it was 11.5, it would also go to 12, but it's close. Do you need it exact?

TePCom1Lenght = Ceil(Round(TePCom1Lenght)%6)

Regards,
Zyloch
0
 
LVL 14

Expert Comment

by:Matti
ID: 12210734
Hi!
Thinking that a select case structure might work best in here:

Function SixSix6(TePCom1Lenght As Currency)
If TePCom1Lenght < 0 Then Exit Function
Select Case TePCom1Lenght
Case 0 To 5.5
SixSix = 6
Case 5.5 To 11.5
SixSix = 12
Case 11.5 To 17.5
SixSix = 18
Case 17.5 To 23.5
SixSix = 24
Case 23.5 To 29.5
SixSix = 25
End Select
End Function

Matti
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12211255
SixSix = (int((TePCom1Lenght +0.4)/6) * 6) + 6
0
 
LVL 18

Expert Comment

by:JR2003
ID: 12211268
Basically you want to round up to the nearest interger divisable by six if the input is over zero.
This function will do the trick.
JR

Function SixSix(TePCom1Lenght As Currency) As Currency

        If TePCom1Lenght > 0 Then
            SixSix = (TePCom1Lenght \ 6 + 1) * 6
        End If
End Function
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 125 total points
ID: 12211306
This does exactly what your function does:
JR

Function SixSix(TePCom1Lenght As Currency) As Currency

        If TePCom1Lenght > 0 Then
            SixSix = Fix(((TePCom1Lenght + 0.49) / 6) + 1) * 6
        End If

End Function

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question