Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Modding for 3.4 version
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 27 September 2002 :  03:50:12  Show Profile
I am just now adding my mods to the 3.4 version and ran into a few problems.

Most of the sql queries use GetRows to store the records in an array. Then they are stored in variables according to thier positions in the array.

When I add a new column to retrieve in the sql query, I also have to modify the variables that point to each record in the array, to accomodate the new field. That means, updating each position for each field in the array.

Example:
...
fT_STATUS = 8
fT_VIEW_COUNT = 9
fTOPIC_ID = 10
fIS_POLL = 11 '<-- New field
fT_SUBJECT = 11 +1
fT_AUTHOR = 12 +1
fT_REPLIES = 13 +1
fT_UREPLIES = 14 +1
...
This would be easy enough when only one mod is modifying the sql query. But when more than one mod adds thier own field, finding the position of each record in the array could get confusing. Even for me.

Is this the only way to add a new column to an sql query using GetRows?

Support Snitz Forums

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 27 September 2002 :  06:13:06  Show Profile  Visit HuwR's Homepage
yep
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 27 September 2002 :  07:55:27  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
Just add them to the end whenever possible. The only place this won't work well is post.asp and topic.asp which pulls back the message (ie the text/memo) fields which need to be last in the query to work well.

Dave Maxwell
Barbershop Harmony Freak
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 27 September 2002 :  08:05:32  Show Profile
Try the following function:

Function GetFieldPos(prs,pstrField)
	GetFieldPos = -1
	For intC = 0 to prs.Fields.Count - 1
		if ucase(prs.Fields(intC).Name) = ucase(pstrField) then
			GetFieldPos = intC
			exit for
		end if
	Next
End Function


e.g

fT_VIEW_COUNT = GetFieldPos(rs,"T_VIEW_COUNT")
fTOPIC_ID = GetFieldPos(rs,"TOPIC_ID")
fT_SUBJECT = GetFieldPos(rs,"T_SUBJECT")
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 27 September 2002 :  10:38:30  Show Profile
Similar Approach as posted by pweighill. Store the field names in an array and then call the function FieldPos to get the field position in the array.
Following is an example with code abstarcts from topic.asp

Add the statements in red below before calling the GetRows method


dim intIndex, FieldsArray()
Redim FieldsArray(rsReplies.Fields.Count-1)
intIndex = 0
For each fld in rsReplies.Fields
 FieldsArray(intIndex)= fld.Name
 intIndex = intIndex + 1
next
arrReplyData = rsReplies.GetRows(strPageSize)


rM_NAME = FieldPos("M_NAME")
rM_RECEIVE_EMAIL = FieldPos("M_RECEIVE_EMAIL")
rM_AIM = FieldPos("M_AIM")
rM_ICQ = FieldPos("M_ICQ")
rM_MSN = FieldPos("M_MSN")
rM_YAHOO = FieldPos("M_YAHOO")
rM_TITLE = FieldPos("M_TITLE")
rMEMBER_ID = FieldPos("MEMBER_ID")
rM_HOMEPAGE = FieldPos("M_HOMEPAGE")
rM_LEVEL = FieldPos("M_LEVEL")
rM_POSTS = FieldPos("M_POSTS")
rM_COUNTRY = FieldPos("M_COUNTRY")
rMOD_FIELD = FieldPos("MOD_FIELD")
rREPLY_ID = FieldPos("REPLY_ID")
rFORUM_ID = FieldPos("FORUM_ID")
rR_AUTHOR = FieldPos("R_AUTHOR")
rTOPIC_ID = FieldPos("TOPIC_ID")
rR_MESSAGE = FieldPos("R_MESSAGE")
rR_LAST_EDIT = FieldPos("R_LAST_EDIT")
rR_LAST_EDITBY = FieldPos("R_LAST_EDITBY")
rR_SIG = FieldPos("R_SIG")
rR_STATUS = FieldPos("R_STATUS")
rR_DATE = FieldPos("R_DATE")
if CanShowSignature = 1 then
 rM_SIG = FieldPos("M_SIG")
end if


for iForum = 0 to iReplyCount
 Reply_MemberName = arrReplyData(rM_NAME, iForum)
 ...
 ...
next

Alternatively, it can also be done as below:
for iForum = 0 to iReplyCount
 Reply_MemberName = arrReplyData(FieldPos("M_NAME"), iForum)
 ...
 ...
next



function FieldPos(strFieldname)
    dim index
    for index = lbound(FieldsArray) to ubound(FieldsArray)
     if Ucase(FieldsArray(index)) = Ucase(strFieldName) then FieldPos = index : exit for
    next
end function
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 27 September 2002 :  14:20:58  Show Profile
pweighill and GauravBhabu, I am not kidding but you guys must live and breath this code. I thought I have seen the worst when persons dream about the code but you guys past that. How many posts I have seen you guys dish out new subroutines and functions like it was a piece of pie? You guys amaze me.

Anyways, the code you guys provide looks good. But wouldn't that have to be something in the base code to do that? I mean, I am sure many other mods need to make the same change. I can't toally re-do that piece of code in the files for my mods. Users will get confused when it comes to adding other mods to it.

Or maybe we could manage to get it into the base code?

But I guess I would have to do it the original way for now. Thanks GB and pweighill.

Support Snitz Forums
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 28 September 2002 :  12:20:11  Show Profile
quote:
Or maybe we could manage to get it into the base code?


You should see if something similar to the code about could be added into v4
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000 Version 3.4.07