Solved

Loop Statment.

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now