Better way of writing this piece of code in vb.net

Hello,
i have code :

    If NumberOFPictures <= 47 Then
                            Slidenumber = 2
                        ElseIf NumberOFPictures > 47 And NumberOFPictures <= 94 Then
                            Slidenumber = 3
                        ElseIf NumberOFPictures > 94 And NumberOFPictures <= 141 Then
                            Slidenumber = 4
                        ElseIf NumberOFPictures > 141 And NumberOFPictures <= 188 Then
                            Slidenumber = 5
                        ElseIf NumberOFPictures > 188 And NumberOFPictures <= 235 Then
                            Slidenumber = 6

                        End If

Open in new window

Is there any better way of writing this as the NumberOFPictures can be  even 2000

Cheers
RIASAsked:
Who is Participating?
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
A more brute force approach would be something like this:
        slideno = 2
        While picno > 47
            slideno = slideno + 1
            picno = picno - 47
        End While

If you wanted something other than 47 pictures per page then just adjust accordingly
1
 
Nitin SontakkeDeveloperCommented:
Why not just NumberOFPictures / 47? Take the answer, make it an Integer and just add 1. Will that not work?
0
 
Nitin SontakkeDeveloperCommented:
When is the slide number = 1?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
RIASAuthor Commented:
Thanks, The slide 1 is the title one so it starts with 2 .
0
 
Rgonzo1971Connect With a Mentor Commented:
HI,

pls try
Slidenumber =2+(NumberOFPictures \ 48) 

Open in new window

0
 
RIASAuthor Commented:
Thanks, will try and be right back
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You can use the \ operator to perform integer division (take care with the / operator, they are not the same).
so 46\47 is zero, 47\47 is one, 94\47 is two....
1
 
RIASAuthor Commented:
Any suggestion then Andy
0
 
Rgonzo1971Commented:
I supposed you are counting from 0 but 48 units per page like in your previous example
I'm already  using the integer division '\' in my suggestion
1
 
AndyAinscowFreelance programmer / ConsultantCommented:
You want something like
slideno = 2 + (picno \ 47)
but I suspect your original code isn't correct.  You have more pictures on the first page than on subsequent pages.
0
 
RIASAuthor Commented:
Thanks Andy! Will try and brb
0
 
RIASAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.