Link to home
Create AccountLog in
Avatar of Rias
RiasFlag 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
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Why not just NumberOFPictures / 47? Take the answer, make it an Integer and just add 1. Will that not work?
When is the slide number = 1?
Avatar of Rias

ASKER

Thanks, The slide 1 is the title one so it starts with 2 .
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Rias

ASKER

Thanks, will try and be right back
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....
Avatar of Rias

ASKER

Any suggestion then Andy
Avatar of Rgonzo1971
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
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
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Rias

ASKER

Thanks Andy! Will try and brb
Avatar of Rias

ASKER

Thanks!