?
Solved

Loop Statment.

Posted on 2004-10-02
5
Medium Priority
?
165 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:Lynn Newey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

764 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