Solved

Loop Statment.

Posted on 2004-10-02
5
159 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now