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(Serv er.MapPath (strFileNa me)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me2)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me3)) 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(Serv er.MapPath (strFileNa me4)) 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
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(Serv
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
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(Serv
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
Just count them
int count = 0;
if a
count++;
if b
count++;
if c
count++;
if d
count++;
if count == 1
{
//code
}
else
{
//code
}
int count = 0;
if a
count++;
if b
count++;
if c
count++;
if d
count++;
if count == 1
{
//code
}
else
{
//code
}
ASKER
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
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
ASKER
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(Serv er.MapPath (strFileNa me)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me2)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me3)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) 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(Serv er.MapPath (strFileNa me4)) 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(Serv er.MapPath (strFileNa me3)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
Else
End If
Else
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
Else
a = 460
End If
End If
End If
Else
If System.IO.File.Exists(Serv er.MapPath (strFileNa me2)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me3)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
Else
End If
Else
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
Else
b = 460
End If
End If
Else
If System.IO.File.Exists(Serv er.MapPath (strFileNa me3)) Then
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
Else
c = 460
End If
Else
If System.IO.File.Exists(Serv er.MapPath (strFileNa me4)) Then
d = 460
Else
End If
End If
End If
End If
sketchimg.ImageUrl = strFileName
cadimg.ImageUrl = strFileName2
sketchimg2.ImageUrl = strFileName3
cadimg2.ImageUrl = strFileName4
sketchimg3.ImageUrl = strFileName5
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
'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(Serv
'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(Serv
If System.IO.File.Exists(Serv
Else
End If
Else
If System.IO.File.Exists(Serv
Else
a = 460
End If
End If
End If
Else
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
Else
End If
Else
If System.IO.File.Exists(Serv
Else
b = 460
End If
End If
Else
If System.IO.File.Exists(Serv
If System.IO.File.Exists(Serv
Else
c = 460
End If
Else
If System.IO.File.Exists(Serv
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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.
ASKER
It worked! Thank you so much for your help!
ASKER
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