---
title: "sub och loop"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/12259-sub-och-loop"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "aleborg"
published: "2001-10-23T21:44:00.000Z"
updated: "2001-10-23T22:20:00.000Z"
replies: 3
views: 157
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/12259-sub-och-loop"
---

# sub och loop

## #1 — aleborg, 2001-10-23T21:44Z

Jag har en image komponent som jag precis köpt men vet inte riktigt hur jag ska använda den här delen i en loop:

```
<%
Response.Contenttype="image/jpeg"
Set g=CreateObject("shotgraph.image")
'   This is the name of the file.
'   You can get it anyway as you want, for example using
'   Request.Form or Request.QueryString
file_name="d:\test.jpg"
'   The maximal dimensions for new image
x_new=100
y_new=100

Main()

Sub Main()
t=g.GetFileDimensions(file_name,x,y)
if x<=0 or y<=0 then Exit Sub
if x/x_new > y/y_new then
	xset=x_new
	yset=y*x_new\x
else
	yset=y_new
	xset=x*y_new\y
end if
if xset<=0 then xset=1
if yset<=0 then yset=1
g.CreateImage xset,yset,4
g.InitClipboard x,y
g.SelectClipboard True
g.ReadImage file_name,pal,0,0
g.Resize 0,0,xset,yset,0,0,x,y,3
g.SelectClipboard False
Response.BinaryWrite g.JpegImage(70,0,"")
End Sub
%>
```

Frågan gäller alltså hur använder man en sub i en loop? Går det?

Permalänk: https://www.webforum.nu/p/12259

## #2 — LarsG, 2001-10-23T21:50Z

Jo, du kan lägga in ett anrop till en sub i princip var som helst.

Vad är det du vill loopa över?

Permalänk: https://www.webforum.nu/p/292796

## #3 — aleborg, 2001-10-23T21:56Z

jag tar fram bilder och förminskar dom

```
<%
pSQL="Select * From Pictures"
Set pic=Conn.Execute(pSQL)
Do Until pic.EOF

bilden ska visas, bildens namn finns i pic("PicName") 

pic.MoveNext
Loop
pic.Close
Set pic=Nothing
```

Provade lägga in koden i slutet av ett dokument innan \</body\> med en specifierad bild väg och inte i loop men fick inte upp nått :(

Permalänk: https://www.webforum.nu/p/292797

## #4 — LarsG, 2001-10-23T22:20Z

Varför du inte får upp något kan jag inte svara på.

Själva lopandet kan se ut så här.

```
'öppna conn
pSQL="Select * From Pictures"
Set pic=Conn.Execute(pSQL)

Response.Contenttype="image/jpeg"
Set g=CreateObject("shotgraph.image")
' This is the name of the file.
' You can get it anyway as you want, for example using
' Request.Form or Request.QueryString

' The maximal dimensions for new image
x_new=100
y_new=100

Do Until pic.EOF
file_name = pic("picname")
main
pic.MoveNext
Loop
pic.Close
Set pic=Nothing

Sub Main()
t=g.GetFileDimensions(file_name,x,y)
if x<=0 or y<=0 then Exit Sub
if x/x_new > y/y_new then
xset=x_new
yset=y*x_new\x
else
yset=y_new
xset=x*y_new\y
end if
if xset<=0 then xset=1
if yset<=0 then yset=1
g.CreateImage xset,yset,4
g.InitClipboard x,y
g.SelectClipboard True
g.ReadImage file_name,pal,0,0
g.Resize 0,0,xset,yset,0,0,x,y,3
g.SelectClipboard False
Response.BinaryWrite g.JpegImage(70,0,"")
End Sub
```

Permalänk: https://www.webforum.nu/p/292798

---

Tråden på webben: https://www.webforum.nu/amne/asp/12259-sub-och-loop
