Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with an Array function 1

Status
Not open for further replies.

timcadieux

Programmer
May 25, 2005
129
BE
I'm using the below Function to build an Array of information to which I later Refer.

The Headline(x) array works perfectly fine, however, the Category array always gives me a Type Mismatch, even though, as you can see in the Function, I use response.write and it shows me all the categories no problem.

i'm thoroguhly confused as to why one works and not the other?

Code:
Function Testit(ByVal Lang)


If Not RS.EOF Then
		
		i = 2 'Number of articles to store. Remember, "0" counts as one, therefore 2 equals 3.
		x = 0
		
		If RS.RecordCount < 3 Then i = 1
		
		ReDim aHeadlines(i), aCategory(i)
		
		For x = 0 to i

			With RS.Fields

				sID = .Item("ID").Value
				sHeadline = .Item("Headline").Value
				sCategory = .Item("Specific").Value

			End With


			aHeadlines(x) = sHeadline
			aCategory(x)=sCategory
			response.write(aCategory(x))
			RS.MoveNext
			
		Next

	End If
	
End Function

Here's how i display the info.

Code:
<%
Call Testit(L)
%>
<%= aHeadlines(0)%>
<%= aCategory(0)>
 
Is it possible that one of the values in your recordset is Null?

If so you might be able to fix it like this:
[tt]sCategory = .Item("Specific").Value & ""[/tt]
 
i'll try that, howevevr, my response.write displays this

army transformation CLS Column, exercise, urban operations training centre
 

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'aCategory'


Code:
<%
Call Testit(L)
%>
<%= aHeadlines(0)%>
<%= aCategory(0)>    <-----this line
[\code]
 
OK, so either aCategory is not an array or aCategory(0) is a non-printable value...

Try splitting your Redim into two lines:
ReDim aHeadlines(i)
ReDim aCategory(i)

Also you might test aCategory with IsArray()


 
ok, i did this and it comes out no!

Code:
if isArray (aCategory) THEN
	response.Write("yes!")
ELSE 
	response.Write("no!")
END IF
[\code]
 
Is the array declared outside of the function?

Maybe it is going out of scope?
 
You've seen my code in it's entirety....have i forgotten to do something?
 
Um, test aHeadlines with IsArray() just to make sure we are not barking up the wrong tree...
 
OK, lets see all the code as you have it now?

I know we havent seen all of it since so far we don't know how your recordset gets populated.
 
Code:
Function CreateRS(oRS,SQL_Query,ConnStr)
	' Creates a Record Set
	Set oRS = Server.CreateObject("ADODB.Recordset")
	oRS.ActiveConnection = ConnStr
	oRS.Source = SQL_Query
	oRS.CursorType = 1  
	oRS.CursorLocation = 2
	oRS.LockType = 1
	oRS.Open()
	RS_numRows = 0
End Function

Function Testit(ByVal Lang)


If Not RS.EOF Then
		
		i = 2 'Number of articles to store. Remember, "0" counts as one, therefore 2 equals 3.
		x = 0
		
		'If RS.RecordCount < 3 Then i = 1
		
		'ReDim aPhotos(i), aHeadlines(i), aTeasers(i), aVideos(i), aAudios(i), aID(i), aCategory(i)
		ReDim aHeadlines(i)
		ReDim aCategory(i)
		For x = 0 to i

			With RS.Fields

				sID = .Item("ID").Value
				sHeadline = .Item("Headline").Value
				sCategory = .Item("Specific").Value & ""

			End With


			aHeadlines(x) = sHeadline
			aCategory(x)=sCategory
			if x =1 then 
				response.write aCategory(1)
			end if
			RS.MoveNext
			
		Next

End If
	
End Function






		Str = "SELECT  TOP 3 * FROM Articles_e Where '" & myDate & "' >= Publish_Date "
		Str=Str & " AND VISIBLE = 1 ORDER BY Article_DATE DESC, RANK;"
		
		Call CreateRS(RS,Str,Application("Connection1_ConnectionString")) 'See Custom_Functions.asp

		Call Testit(L)
		
if isArray (aHeadlines) THEN
	response.Write("yes!")
ELSE 
	response.Write("no!")
END IF
%>
[\code]
 
Oh my god, you're a genius!! hehe...

i did a search of the entire site and whoever wrote this had the Variable Declarations in another include file alltogether..

Thank you very very much, i've spent hours on this before posting!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top