Link to home
Start Free TrialLog in
Avatar of htillberg
htillberg

asked on

Displaying an image in ASP

Hi:

I am trying to find the right syntax to insert an image into a Select...Case statement...?

I want an image to be displayed only during one of those cases...

Any suggestions?
Avatar of AerosSaga
AerosSaga

Do you have a specific reason to use select case?  will there be many cases?

Dim FilePath As String
       FilePath = Server.MapPath("") & "\Image\MyImageFile.jpg"
       If File.Exists(FilePath) then
            lblPic.text = "<img src='" & "products/" & filename & "' width='200' height='200'>"
       else
            lblPic.text = "No Picture Available"
       end if
if you are using asp.net web image control then you need to set imageurl

like this

If Image1.ImageUrl = "" Then
            Image1.ImageUrl = "file:///C:\\My Documents\My Pictures\google5.bmp"
End If

hamood
Avatar of htillberg

ASKER

I think I should have explained better. The reason for Select Case etc is because there are a few cases ...and it is to explain whether it is Open to the Public and with these words, I wanted to display an icon. The icon will be the same for every time the case is "Open to Public" basically. I am not using ASP.NET however...it is old school ASP as far as I know. The reason for this is that I am working on improving an old website.

So I am not sure which of these suggestions is more appropriate given this new clarification. I'm guessing creating a variable like in the first suggestion without the else statement...so that's what I will try...

i wonder if the variable should be declared in the case statement? That's what I will try anyway...
You have only public or private icons to show right? What you can do is set a variable type to default to public and then in the case statement change it when appropriate:

Dim appAccessLevel = "public"
Dim UserAccessLevel = "ANYTHING DEPENDING ON YOUR LOGIC"

SELECT UserAccessLevel
 Case 1
   appAccessLevel = "public"
 Case 2
 appAccessLevel = "private"

End Select

if appAccessLevel = "public" then
  MyImg.src = "public.gif"
elseif appAccessLevel = "private" then
  MyImg.src = "private.gif"
end if

Best, Nauman
OK of these, i couldn't get anything to work so far. I tried AeroSaga's suggestion, but ASP version that I am using doesn't seem to recognize AS String, or anything else I've tried.

With other things, what I am missing is not just how to set what the image should be, but how to tell with ASP/VBScript to display that filesource, filepath, whatever.

Any other suggestions? I really don't need a complicated statement, I just need to set a variable of a filepath, imagesource and then call that statement in the Case

For example

Select Case rsSiteDetail.Fields.Item("OpenToPublic").Value
                                            Case 0
                                            Response.Write "Not Open to Public"
                                            Case 1
                                           --> (Here is where I want to display image)
                                            Response.Write "Open to the Public"
                                            Case 2
                                            Response.Write "Viewable from Street"
                                            Case 4
                                            Response.Write "Open to Public By Appointment"
                                            Case Else
                                            Response.Write " "
                                            End Select
Try this:

Dim imgPath = "images/public.gif"
Select Case rsSiteDetail.Fields.Item("OpenToPublic").Value
                                     Case 0
                                     MyImage.src=""
                                     Response.Write "Not Open to Public"
                                     Case 1
                                    MyImage.src=imgPath
                                     Response.Write "Open to the Public"
                                     Case 2
                                     MyImage.src=""
                                     Response.Write "Viewable from Street"
                                     Case 4
                                     MyImage.src=""
                                     Response.Write "Open to Public By Appointment"
                                     Case Else
                                     MyImage.src=""
                                     Response.Write " "
                                     End Select
Best. Nauman
why is this torturing me in this manner?

I like nauman's suggestion...I think it logically makes the most sense for what I want to do....But it is not liking the imgpath syntax (which I actually changed to:

                                                                 Dim imgPath
                                            Set imgPath = ("images/open.gif")
                                            Select Case rsSiteDetail.Fields.Item("OpenToPublic").Value
                                            Case 0
                                            MyImg.src = ""
                                            Response.Write "Not Open to Public"
                                            Case 1
                                            MyImg.src = "open.gif"
                                            Response.Write "Open to the Public"
                                            Case 2
                                            MyImg.src = ""
                                            Response.Write "Viewable from Street"
                                            Case 4
                                            MyImg.src = ""
                                            Response.Write "Open to Public By Appointment"
                                            Case Else
                                            Response.Write " "
                                            End Select
                                            %>
Declaring the variable and then setting it seems to work better with what I'm doing:
But I get this error:

Microsoft VBScript runtime error '800a01a8'

Object required: '[string: "images/open.gif"]'

Any suggestions. Just to remind, I'm using ASP, not ASP.NET. I have tried every combination i can think of to make it recognize the file...
SOLUTION
Avatar of nauman_ahmed
nauman_ahmed
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
and remember you dont need to set the image path at all :)

Cheers, nauman
ASKER CERTIFIED 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
I'm going to try this but first a question---is there a just plain ASP forum? I understand the criticism (not just from jnhorst...but on another question another user). I just am trying to post a question in the *most* appropriate place and there doesn't appear to be a forum that just deals with ASP. I post here out of the hope that someone who uses ASP.NET either has experience with ASP or that the solution can be tweaked slightly with this and the stack of reference books I have to work. So again I apologize, but I try to assign the maximum points to most questions because of this and also, often the logic is what I need as much help with as the syntax, though admittedly in this case it's syntax...so again, I'm sorry about asking about ASP instead of ASP.NET and if there is an ASP forum...please direct me where it is---i have looked through all the menus :)

So I'm off to work on this again...

Thanks again, HT
wow. that worked. Awesome :)