Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Displaying an Image's Dimensions

Explorer ,
Dec 21, 2010 Dec 21, 2010

I have a page that lists a table of slides pulled from an Access database displayed in a table on an ASP VBScripted page and want to determine the various image's widths and heights.  I have a VBscript that works for a single image but does not work in a "Repeat Region". 

The code to read the width & height is:

<%
dim iwidth, iHeight
sub ImgDimension(img)
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img)  then exit sub
set myImg = loadpicture(img)
iwidth = round(myImg.width / 26.4583)
iHeight = round(myImg.height / 26.4583)
set myImg = nothing
end sub

ImgDimension(Server.MapPath("/images/techtraining/" & rs_TSR.Fields.Item("tsr_Img").Value))
%>

The code I am using to display the width is:

<%= iwidth %>

Any suggestions on how to either rework this code or other code that I can use?

Thanks!

Andy

TOPICS
Server side applications
764
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2010 Dec 21, 2010

Why doesn't this work in a repeating region?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2010 Dec 22, 2010

I wish I knew.

If I place just the <%= iwidth %> variable inside the repeat region under the image, it displays the width for the first image

for every subsequent record's image.  As soon as I move all the code in to the repeat region, it kills the page.  It's driving me nuts but I am sure I must be overlooking something obvious.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2010 Dec 22, 2010

I tried the code on a different page on our Intranet and was able to get the following error message:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/ObsoleteStock.asp, line 176

sub ImgDimension(img)
^

Again, the code executes outside the repeat region but gives the error message when placed inside the repeat region.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 22, 2010 Dec 22, 2010

Are you declaring those variables (dim iwidth, iHeight ) each time through the loop? You can only declare a variable once.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2010 Dec 22, 2010
LATEST

Thanks for the replies as I really appreciate the help but I modified the code and stumbled on the solution and posted it just moments ago if you care to take a look at what I did.

Thanks again and happy holidays!!

Andy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2010 Dec 22, 2010

    Just thought I would share the solution I pulled my hair out hacking away to. While I am self-taught and have been able to do more than I ever thought I could ever accomplish with code, instances like this can be frustrating at times but I am also a bit stubborn when something gets in my way and usually find if I keep hacking away, I'll get it eventually!

   Researching into the syntax error, I figured it was the blocking point.  I can't explain the why's of why the original code wouldn't work or how I finally got the code to work but here it is!

I modified the original code of:

<%
dim iwidth, iHeight
sub ImgDimension(img)
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img)  then exit sub
set myImg = loadpicture(img)
iwidth = round(myImg.width / 26.4583)
iHeight = round(myImg.height / 26.4583)
set myImg = nothing
end sub

ImgDimension(Server.MapPath("/images/techtraining/" & rs_TSR.Fields.Item("tsr_Img").Value))
%>

I removed these lines from the original code:

sub ImgDimension(img)

ImgDimension(Server.MapPath("/images/techtraining/" & rs_TSR.Fields.Item("tsr_Img").Value))

Removed all instances of "sub" that appeared in the original code

And modified the line from:

set myImg = loadpicture(img)

To:

set myImg = loadpicture(Server.MapPath("/images/techtraining/" & rs_TSR.Fields.Item("tsr_Img").Value))

And finally got this code to work inside my Repeat Region:

<%
dim iwidth, iHeight
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img) then
set myImg = loadpicture(Server.MapPath("/images/techtraining/" & rs_TSR.Fields.Item("tsr_Img").Value))
iwidth = round(myImg.width / 26.4583)
iHeight = round(myImg.height / 26.4583)
set myImg = nothing
end If

%>

Then displayed the width dimension using:

<%= iwidth %>

To display the height use:

<%= iHeight %>

Merry Christmas and Happy New Year all!!

Andy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines