Link to home
Start Free TrialLog in
Avatar of jtuttle99
jtuttle99

asked on

How to write this condtion in VB.net

I have very basic question.
What would be the best way to write this condition.
Here is my condtion

I have 4 images.
If ONLY one of the image file exists I would like to make the image width "460"
otherwise, width stays 250 and change visibility accordingly.

Here is what I have so far.

If System.IO.File.Exists(Server.MapPath(strFileName)) Then
            If System.IO.File.Exists(Server.MapPath(strFileName2)) Then
                If System.IO.File.Exists(Server.MapPath(strFileName3)) Then
                    If sketchimg2.Width.ToString < "245" Then
                        sketchimg2.Width = 245
                        sketchimg2.Visible = True
                    End If
                Else
                    sketchimg2.Visible = False
                End If
                If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    If cadimg2.Width.ToString < "245" Then
                        cadimg2.Width = 245
                        cadimg2.Visible = True
                    End If
                Else
                    cadimg2.Visible = False
                End If
                If sketchimg.Width.ToString < "245" Then
                    sketchimg.Width = 245
                    sketchimg.Visible = True
                End If
                If cadimg.Width.ToString < "245" Then
                    cadimg.Width = 245
                    cadimg.Visible = True
                End If
            Else
                If sketchimg.Height.ToString < "460" Then
                    sketchimg.Height = 460
                    sketchimg.Visible = True
                End If
            End If
        Else
            sketchimg.Visible = False
        End If\


what would be the best way to achieve this?

Thank you
Avatar of jtuttle99
jtuttle99

ASKER

I guess I can do this way but is this the only way?

 If a = True Then
            If b = True Then
                If c = True Then
                    If d = True Then

                    Else
                    End If
                Else

                End If
            Else
                If c = True Then
                    If d = True Then

                    Else
                    End If
                Else
                    If d = True Then

                    Else
                        a = 460
                    End If
                End If
            End If
        Else
            If b = True Then
                If c = True Then
                    If d = True Then
                    Else
                    End If
                Else
                    If d = True Then
                    Else
                        b = 460
                    End If
                End If
            Else
                If c = True Then
                    If d = True Then
                    Else
                        c = 460
                    End If
                Else
                    If d = True Then
                        d = 460
                    Else
                    End If
                End If
            End If
        End If
Avatar of TommySzalapski
Just count them
int count = 0;
if a
  count++;
if b
  count++;
if c
  count++;
if d
  count++;

if count == 1
{
  //code
}
else
{
  //code
}
TommySzalapski:

Thank you for your reply
If I count them, How could I know which one should be the large size?

if count =1  
// code - I should make one of the image large (size 460)

Thank you
somthing like this... it's going to be long...

sketchimg.ImageUrl = strFileName
        cadimg.ImageUrl = strFileName2
        sketchimg2.ImageUrl = strFileName3
        cadimg2.ImageUrl = strFileName4
        sketchimg3.ImageUrl = strFileName5

 If System.IO.File.Exists(Server.MapPath(strFileName))  Then
            If System.IO.File.Exists(Server.MapPath(strFileName2)) Then
                If System.IO.File.Exists(Server.MapPath(strFileName3)) Then
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                              'all exists
                                    If sketchimg.Width.ToString < "245" Then
                                    sketchimg.Width = 245
                                    sketchimg.Visible = True
                                    End If
                                    If sketchimg2.Width.ToString < "245" Then
                                    sketchimg2.Width = 245
                                    sketchimg2.Visible = True
                                    End If
                                    If cadimg.Width.ToString < "245" Then
                                    cadimg.Width = 245
                                    cadimg.Visible = True
                                    End If
                                     If cadimg2.Width.ToString < "245" Then
                        cadimg2.Width = 245
                        cadimg2.Visible = True
                        End If
                    Else
                              '1,2,3
                                    If sketchimg.Width.ToString < "245" Then
                                    sketchimg.Width = 245
                                    sketchimg.Visible = True
                                    End If
                                    If sketchimg2.Width.ToString < "245" Then
                                    sketchimg2.Width = 245
                                    sketchimg2.Visible = True
                                    End If
                                    If cadimg.Width.ToString < "245" Then
                                    cadimg.Width = 245
                                    cadimg.Visible = True
                                    End If
                    End If
                Else
                               If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                              '1,2,4
                                    If sketchimg.Width.ToString < "245" Then
                                    sketchimg.Width = 245
                                    sketchimg.Visible = True
                                    End If
                                    If cadimg.Width.ToString < "245" Then
                                    cadimg.Width = 245
                                    cadimg.Visible = True
                                    End If
                                     If cadimg2.Width.ToString < "245" Then
                        cadimg2.Width = 245
                        cadimg2.Visible = True
                        End If
                    Else
                              '1,2
                                    If sketchimg.Width.ToString < "245" Then
                                    sketchimg.Width = 245
                                    sketchimg.Visible = True
                                    End If
                                    If sketchimg2.Width.ToString < "245" Then
                                    sketchimg2.Width = 245
                                    sketchimg2.Visible = True
                                    End If      
                    End If
                End If
            Else
                If System.IO.File.Exists(Server.MapPath(strFileName3)) Then
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    Else
                    End If
                Else
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    Else
                        a = 460
                    End If
                End If
            End If
        Else
            If System.IO.File.Exists(Server.MapPath(strFileName2)) Then
                If System.IO.File.Exists(Server.MapPath(strFileName3)) Then
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    Else
                    End If
                Else
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    Else
                        b = 460
                    End If
                End If
            Else
                If System.IO.File.Exists(Server.MapPath(strFileName3)) Then
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                    Else
                        c = 460
                    End If
                Else
                    If System.IO.File.Exists(Server.MapPath(strFileName4)) Then
                        d = 460
                    Else
                    End If
                End If
            End If
        End If
You could do something like this
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim imageFiles() As String = {"c:\windows\system32\calc.exe", _
                                      "f:\windows\system32\notepad.exe", _
                                      "f:\bogus.exe"}

        Dim result() As String = Array.FindAll(imageFiles, AddressOf MoreThanOneExists)

        If result.Length = 1 Then
            ' make the image width "460"
            Debug.Print(result(0))
        Else
            'width stays 250 and change visibility accordingly.
        End If
    End Sub

    Private Function MoreThanOneExists(ByVal path As String) As Boolean
        Return System.IO.File.Exists(path)
    End Function

End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TommySzalapski:
Ahh, Now I get it. I will try the code tomorrow.

egl1044:
Your way is a little bit over my head but I would like to understand your way.
I will also try and let you know.

Thank you so much
The reason I like the way I set it up is that you easily use more than two sizes. I've used something like that before to tile windows (actually web page frames). Now it's more built in.
It worked! Thank you so much for your help!