Avatar of RIAS
RIAS
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
RIAS

8/22/2022 - Mon
Nitin Sontakke

Why not just NumberOFPictures / 47? Take the answer, make it an Integer and just add 1. Will that not work?
Nitin Sontakke

When is the slide number = 1?
RIAS

ASKER
Thanks, The slide 1 is the title one so it starts with 2 .
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
Thanks, will try and be right back
AndyAinscow

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....
RIAS

ASKER
Any suggestion then Andy
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rgonzo1971

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
AndyAinscow

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.
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
Thanks Andy! Will try and brb
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
RIAS

ASKER
Thanks!