?
Solved

Loop Statment.

Posted on 2004-10-02
5
Medium Priority
?
168 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
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

Hire Technology Freelancers with Gigs

Work with 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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

755 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