Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to write this condtion in VB.net

Posted on 2011-02-20
10
Medium Priority
?
329 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:jtuttle99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 

Author Comment

by:jtuttle99
ID: 34939715
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
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34939736
Just count them
int count = 0;
if a
  count++;
if b
  count++;
if c
  count++;
if d
  count++;

if count == 1
{
  //code
}
else
{
  //code
}
0
 

Author Comment

by:jtuttle99
ID: 34939766
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
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:jtuttle99
ID: 34939772
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
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 34939786
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

0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 1200 total points
ID: 34939856
After you get the count just do
if a exists
set it up (MAX_WIDTH/count) or something

if b exists
set it up

No nested ifs needed. You could even make it a function.
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 800 total points
ID: 34939895
Yup. You probrably need a way to preserve the path information using an array or even creating a class to hold the information and adding logic into your predicate could help take care of alot of the if blocks.
For example you could create a class that has a method to handle resizing create and instance of the class add it to the array, the predicate will return you the classes that have an existing file than all you do is run the method. Hope that makes sense.

This is just a general idea you can make changes to suit your needs.
Public Class Form1

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

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


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

        If result.Length = 1 Then
            ' make the image width "460"
            result(0).Resize()
            Debug.Print("resize {0} ", result(0).FileName)
        Else
            'width stays 250 and change visibility accordingly.
            For Each obj As ImageFileStuff In result
                obj.PreserveSizeAndSetVisibility()
                Debug.Print("change visibilty {0}", obj.FileName)
            Next
        End If
    End Sub

    Private Function MoreThanOneExists(ByVal obj As ImageFileStuff) As Boolean
        ' Predicate
        Return System.IO.File.Exists(obj.FileName)
    End Function

    Private Class ImageFileStuff
        Private _filename As String = String.Empty
        Public Sub New(ByVal fileName As String)
            _filename = fileName
        End Sub
        Public Sub PreserveSizeAndSetVisibility()
            ' TODO: Add logic for visibility
        End Sub
        Public Sub Resize()
            ' TODO: Add logic for resize
        End Sub
        Public ReadOnly Property FileName As String
            Get
                Return _filename
            End Get
        End Property
    End Class

End Class

Open in new window

0
 

Author Comment

by:jtuttle99
ID: 34939961
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
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34940126
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.
0
 

Author Closing Comment

by:jtuttle99
ID: 34944483
It worked! Thank you so much for your help!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question