Click here to Skip to main content
15,886,137 members
Articles / Programming Languages / ASP

The Code Project Discussion boards

,
Rate me:
Please Sign up or sign in to vote.
4.78/5 (39 votes)
25 Aug 2001CPOL 2.9M   15.2K   144  
The Discussion board ASP scripts as used in The Code Project. This is an open source project for the Code Project community.
option explicit

Const PATH = "../database/forum.mdb"

'db connection
dim m_conn
set m_conn = CreateObject("ADODB.Connection")
m_conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Persist Security Info=False;" &_
"Data Source=" & PATH



'--------------------------------------
'insert entry
function insert(position, indent, id)
	dim rs_insert
	set rs_insert = CreateObject("ADODB.Recordset")
	rs_insert.Open "SELECT * FROM Article WHERE ForumID = "& forum_id &"AND ID = "&id, m_conn, 2, 3
	rs_insert("Position")	= position
	rs_insert("Indent")		= indent
	rs_insert.Update
	rs_insert.Close
end function
'--------------------------------------

'find position-------------------------
sub countPosition
	position = Clng(position)-1
	while Len(position) < 6
		 position = "0" & position
	wend
end sub
'--------------------------------------

'insert childs-------------------------
function insertChild(parent_id, indent)
	dim x
	dim rs_child, sql_child
	sql_child= "SELECT * From Article WHERE ForumID = "& forum_id & " AND ParentID =" &parent_id & " ORDER BY Date ASC"
	set rs_child = m_Conn.Execute(sql_child)

	'gets the position of the parent entry
	dim rs_pos, sql_pos
	sql_pos= "SELECT * From Article WHERE ForumID = "& forum_id & " AND ID =" &parent_id & " ORDER BY Date DESC"
	set rs_pos = m_Conn.Execute(sql_pos)

	dim last
	'if there are no other childs
	if (rs_child.Bof and rs_child.Eof) then
		x = "000001"
		c_position = position & x
	'if there are other childs
	else
		while not rs_child.Eof
			x = CStr(CLng(x)+1)
			while Len(x) < 6
				 x = "0" & x
			wend
			c_position = rs_pos("position") & "." & x
			insert c_position, indent, rs_child("ID")
			insertChild rs_child("ID"), indent+1
			rs_child.MoveNext
		wend
	end if
	
	dim c_position

end function


'--------------------------------------
function convert(id)
	countPosition
	insert position, 0, id
	insertChild id, 1
end function
'----------------------------------

' get the forumID---------------------------------
dim rs_forum, sql_forum
sql_forum= "SELECT DISTINCT ForumID From Article"
set rs_forum = m_Conn.Execute(sql_forum)
'-------------------------------------------------

while not rs_forum.Eof
	dim position, forum_id
	' set "position" to the start
	position = "1000000"
	forum_id = rs_forum("ForumID")

	'get the parent entries of the forum
	dim rs, sql
	sql= "SELECT * From Article WHERE ForumID = "&forum_id&" AND ParentID = 0 ORDER BY Date ASC"
	set rs = m_Conn.Execute(sql)

	while not rs.Eof
		convert rs("ID")
		rs.MoveNext
	wend
	rs_forum.MoveNext
wend

'----------------------------------------
sub trace( text )
	WScript.Echo text & vbCrLf
end sub

trace "Database-Update was successful."

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder CodeProject
Canada Canada
Chris Maunder is the co-founder of CodeProject and ContentLab.com, and has been a prominent figure in the software development community for nearly 30 years. Hailing from Australia, Chris has a background in Mathematics, Astrophysics, Environmental Engineering and Defence Research. His programming endeavours span everything from FORTRAN on Super Computers, C++/MFC on Windows, through to to high-load .NET web applications and Python AI applications on everything from macOS to a Raspberry Pi. Chris is a full-stack developer who is as comfortable with SQL as he is with CSS.

In the late 1990s, he and his business partner David Cunningham recognized the need for a platform that would facilitate knowledge-sharing among developers, leading to the establishment of CodeProject.com in 1999. Chris's expertise in programming and his passion for fostering a collaborative environment have played a pivotal role in the success of CodeProject.com. Over the years, the website has grown into a vibrant community where programmers worldwide can connect, exchange ideas, and find solutions to coding challenges. Chris is a prolific contributor to the developer community through his articles and tutorials, and his latest passion project, CodeProject.AI.

In addition to his work with CodeProject.com, Chris co-founded ContentLab and DeveloperMedia, two projects focussed on helping companies make their Software Projects a success. Chris's roles included Product Development, Content Creation, Client Satisfaction and Systems Automation.

Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions