Solved

Displaying an image in ASP

Posted on 2004-08-17
12
188 Views
Last Modified: 2010-04-07
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?
0
Comment
Question by:htillberg
[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
12 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11822813
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
0
 
LVL 4

Expert Comment

by:hamood
ID: 11822891
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
0
 

Author Comment

by:htillberg
ID: 11822991
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...
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11823151
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
0
 

Author Comment

by:htillberg
ID: 11824281
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
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11824703
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
0
 

Author Comment

by:htillberg
ID: 11825606
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...
0
 
LVL 25

Assisted Solution

by:nauman_ahmed
nauman_ahmed earned 100 total points
ID: 11825734
>>Dim imgPat
>>Set imgPath = ("images/open.gif")

What are you trying to do here? Usually to set the image path dynamically, I add a runat="server" attribute to image and give it an ID say ID="MyImage". Then it is accessable dynamically whenever I want it e.g.

MyImage.src = "images/open.gif"

What you are trying to do in Set imgPath = ("images/open.gif") will cause an error since imgPath is nothing. Its not a defined type.

Best, nauman
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11825740
and remember you dont need to set the image path at all :)

Cheers, nauman
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 400 total points
ID: 11825968
You're in the ASP.NET forum, not the old school ASP forum, but that's cool:

You cannot type variables in VBScript (i.e. as string, as boolean, etc...).  Everything is variant by default.  If you declare a variable and use it in your Select Case, just dim it.  Also you cannot assign the variable as part of the declaration (like you can in .NET).  I also noted that you used "Set variable = ..." when assigning a string literal (the image path) to the variable.  Can't do this...  you could use "Let variable = ..." but that's rarely done.  The Set statement is only for when you are going to use something like Server.CreateObject(...) to create an object (like a recordset,f or example: Set rsDetail = Server.CreateObject("ADODB.Recordset")).

The following should work:

Dim someValue
someValue = rsSomeRS.Fields("FieldName").Value

Select Case someValue
     Case 0
          Response.Write "{some text}"
     Case 1
          Response.Write "<img src='{relative path to your image}' border=0>"
     Case 2
          Response.Write "{some text}"
     {... and so on}
End Select

Good luck...
John
0
 

Author Comment

by:htillberg
ID: 11832349
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
0
 

Author Comment

by:htillberg
ID: 11832467
wow. that worked. Awesome :)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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