---
title: "Subrutin prob!"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/10396-subrutin-prob"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "aleborg"
published: "2001-07-03T15:44:00.000Z"
updated: "2001-07-04T07:11:00.000Z"
replies: 15
views: 248
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/10396-subrutin-prob"
---

# Subrutin prob!

## #1 — aleborg, 2001-07-03T15:44Z

Jag har fått fram en fungerande kod som ser ut så här för att plocka fram alla kategorier och subkategorier:

```
<%
Sub WriteCatSubstans(catName,catId)

	Dim tac
	Dim sql2

	SQL2="Select * From Categ Where CatBel='"& catid &"'"
	Set tac = Conn.Execute(SQL2)

	Do until tac.Eof
		Response.Write("<option value="""& tac("CatID") &""">" & CatName & "/" & tac("CatName") & "</option>")
			Call WriteCatSubstans(CatName & "/" & tac("CatName"), tac("catID"))
		tac.MoveNext
	Loop

	tac.Close
	Set tac = Nothing

End sub

SQL = "Select * From Categ Where CatBel='none'"
Set ca = Conn.Execute(SQL)

	Do Until ca.EOF
		Response.Write("<option value=""" & ca("CatID") & """>" & ca("CatName")& "</option>")
			Call WriteCatSubstans(ca("catName"),ca("CatId"))
	ca.MoveNext
	loop

ca.close
Set ca = Nothing
%>
```

Den fungerar perfekt utan problem i ett formulär för att skapa nya kategorier, saken är när man skickar formuläret så ska kategorin man valt att skapa ny i visas, hela kedjan t ex:
kat1 - sub1 - sub2 - nysub

Hur ska jag göra, förmodar att jag får använda ovanstående sätt att göra det på! Suttit och provat mig fram men inte fått nått fungerande :(

Så här ser den nuvarande koden ut, men den visar inte hela kedjan:

```
<%
If Session("CatBel")="none" Then
Response.Write ""& Session("CatName") &""
Else

SQL="Select * From Categ Where CatID='"& Session("Catbel") &"'"
Set ca=Conn.Execute(SQL)
If len(ca("Catbel"))="none" Then
Response.Write ""& ca("CatName") &" - <u>"& Session("CatName") &"</u>"
ca.Close
Set ca=Nothing
Else
SQL2="Select * From Categ Where CatID='"& ca("Catbel") &"'"
Set ac=Conn.Execute(SQL2)
Do Until ac.EOF
Response.Write ""& ac("CatName") &" - "
ac.MoveNext
Loop
ac.Close
Set ac=Nothing
Response.Write ""& ca("CatName") &" - <u>"& Session("CatName") &"</u>"
ca.Close
Set ca=Nothing
End If
End If
%>
```

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

## #2 — emission, 2001-07-03T17:40Z

Testa lite med detta...

```
<%

response.write mid(ShowCats(0,true),3)

Sub ShowCats(CatID,Current)
	dim m_buffer
	if Current then
		m_buffer=" - <u>"& Session("CatName") &"</u>"
		nextcat=Session("CatBel")
	else
		SQL="Select * From Categ Where CatID='"& CatID &"'"
		Set ca=Conn.Execute(SQL)
		m_buffer=" - " & ca("CatName")
		nextcat=ca("CatBel")
	end if
	if nextcat<>"none" then
		ShowCats=ShowCats(nextcat,false) & m_buffer
	else
		ShowCats=m_buffer
	end if
End Sub
%>
```

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

## #3 — aleborg, 2001-07-03T17:53Z

:(
Type mismatch: 'ShowCats'

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

## #4 — emission, 2001-07-03T18:04Z

Labba lite med den. Jag skrev rätt från hjärtat....och har ingen aning om hur sessions och så ser ut hos dig... :)

\[r\]Ja, och så är det ju bra om man gör en function och inte en sub....\[/r\]

\[Redigerat av emission den 03 jul 2001\]

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

## #5 — tdaugaard, 2001-07-03T18:12Z

Sorry to write in English, but I'm Danish and does not understand nor know how to write in Sweedish :-(

emission, you cannot assign a value to a SUB routine, only a Function. That is why aleborg gets an error.

I'll get back to you with your problem .. just wanted to say this now ..

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

## #6 — @nders, 2001-07-03T18:14Z

\*LOL\* emission gjorde fel! ;)

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

## #7 — tdaugaard, 2001-07-03T18:26Z

\*smile\* and emission never makes errors or ?

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

## #8 — @nders, 2001-07-03T18:29Z

nope, but there's a first for everything... :e

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

## #9 — aleborg, 2001-07-03T19:17Z

nån?

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

## #10 — @nders, 2001-07-03T19:18Z

har du skrivit om det till en funktion istället för en sub?

hur ser din kod ut i detta nu?

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

## #11 — aleborg, 2001-07-03T19:25Z

Jag gick tillbaka till den ursprungliga, är fortfarande inte riktigt haj på functions o subbar

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

## #12 — Vide, 2001-07-03T19:28Z

Funkctions och subbar: <http://www.webeye.nu/default2.asp?que=asp/default.asp&exec=asp/artiklar/asp_14.asp#function>

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

## #13 — aleborg, 2001-07-03T19:53Z

Ett utmärkt sätt att lära sig functions på!

```
Function ShowCat(catbel)
SQL2="Select * From Categ Where CatID="&catbel
Set ac=Conn.Execute(SQL2)
Do Until ac.EOF
Response.Write ""& ac("CatName") &" - "
ac.MoveNext
Loop
ac.Close
Set ac=Nothing
End Function
```

Nu måste ju catbel ha ett värde också?

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

## #14 — emission, 2001-07-03T20:44Z

Nu förstår jag faktiskt inte vad du är ute efter.

Som function fungerar mitt exempel.

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

## #15 — aleborg, 2001-07-03T20:50Z

Det gjorde det :) 
Du e en klippa mannen :)

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

## #16 — emission, 2001-07-04T07:11Z

Vad kul! :)

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/10396-subrutin-prob
