Solved

Displaying an image in ASP

Posted on 2004-08-17
12
179 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.Net Session State alternatives 3 57
Tool Box 2 34
Runtime Error 2 28
Error in JQuery 5 38
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now