View Full Version : Works once in the function... doesn't work again..???

08-18-2005, 05:19 AM
Invalid procedure call or argument
/cvibe/folderFunctions.asp, line 506

505: function isFolderGrabbed(folderId)
506: isFolderGrabbed = fi.Exists(folderId)
507: end function

Function called from here:

254: response.write isFolderGrabbed(folderId)
It is supposed to return a bool. I made reference to it in a function... and anytime I try to make reference to it again in the same function I get that error.
The input is valid. I verified that

08-18-2005, 03:50 PM
What is fi?

Show us the complete code!

08-18-2005, 07:28 PM
Unless fi is defined globally, your function will not recognize what it is, thus invalid procedure call.

08-18-2005, 11:08 PM
Sorry for delay in response.... fi is a dictionay object and it is defined globally at the top of my script outside of any functions

08-18-2005, 11:23 PM
Could you post your code that is setting folderid and where fi gets created?

08-18-2005, 11:28 PM
The entire code is almost 1000 lines so i'll post snippets...

'Global Arrays...
Dim folders()

'Grab array...
Dim pleaseGrab 'any other can be used to send to the grabFolder function

'These dictionaries keep record of the index that a particular folder with id "fid"
'or type id with id "tid" has been stored in the folders and types array respectively
'The index WILL be different from the fid or the tid.. so the dictionary is used as a
'pointer in a sense. For example... each folderId has a key that is the index that
'of its position in the folders array. So we just have to lookup in the dictionary
'for a particular folder id to know which index it is stored in the "folders" array
Dim fi, ti, ai 'folder index, type index, article index
Set fi = Server.CreateObject("Scripting.Dictionary")
Set ti = Server.CreateObject("Scripting.Dictionary")
Set ai = Server.CreateObject("Scripting.Dictionary")

'Grab the function details and stores them in the "folders" array
function grabFolder(folderArray,mode)
'Takes as input... list of folder indices
Dim req 'Requested number of folders for grabbbing...
if not isArray(folderArray) AND isNumeric(folderArray) then
folderArray = Array(folderArray)
end if
req = ubound(folderArray)

Dim sqlWhere
if req = 0 then
sqlWhere = " folderId=" & folderArray(0)
else if req > 0 then
sqlWhere = " folderId IN (" & join(folderArray,",") & ")"
response.write "No folders specified for grab!"
Exit Function
end if
end if

Dim folderRows
folderRows = retrieveFolders(sqlWhere,mode)
Dim folderId, folderName, folderDescription

if not isArray(folderRows) then
response.write "No data found on folders... Grab failed!"
'Loop through the array... and store in folders array
Dim folderCount, i
folderCount = ubound(folderRows,2)

Dim alreadyGrabbed

'Now we need to determine where i should start...
Dim dictCount, newDictIndex, adjIndex
dictCount = UBound(fi.Items)
newDictIndex = dictCount + 1
'response.write " dictCount is: " & dictCount
'response.write " newDictIndex is: " & newDictIndex
'response.write "<br>"

for i = 0 to folderCount
adjIndex = (newDictIndex + i)
'response.write "adjIndex is: " & adjIndex & "<br>"
fi.Add folderRows(0,i), adjIndex
Redim Preserve folders(3,adjIndex)

folders(fFOLDERID,adjIndex) = folderRows(0,i)
folders(fFOLDERNAME,adjIndex) = folderRows(1,i)
folders(fTYPES,adjIndex) = ""
if mode = "full" then
folders(fFOLDERDESCRIPTION,adjIndex) = folderRows(2,i)
folders(fFOLDERDESCRIPTION,adjIndex)="Folder Description not retrieved!"
end if

end if

end function

function grabType(typeArray,mode)
if isArray(typeArray) then
'It is valid...
Dim req
req = ubound(typeArray)

Dim sqlWhere
if req = 0 then
sqlWhere = " typeId=" & typeArray(0)
else if req > 0 then
sqlWhere = " typeId IN (" & join(typeArray,",") & ")"
response.write "No types specified for grab!"
Exit Function
end if
end if

Dim typeRows

typeRows = retrieveTypes(sqlWhere,mode)

if isArray(typeRows) then
Dim typeId, folderId, typeName, typeDescription, typeIcon
Dim types, typeCount
Dim j
typeCount = ubound(typeRows,2)
for j = 0 to typeCount
'First we have to get the type array from the respective folder
typeId = typeRows(0,j) 'type id
folderId = typeRows(1,j) 'folder id
typeName = typeRows(2,j) 'typeName
typeIcon = typeRows(3,j) 'type icon
Select Case mode
Case "compact"
typeDescription = "Type description NOT retrieved"
Case "full"
typeDescription = typeRows(4,j)
End Select

if not isFolderGrabbed(folderId) then
'call grabFolder(folderId,"compact")
response.write "The folder for type " & typeId & " was not grabbed! Grab folder " & folderId & "<br>"
call grabFolder(folderId,"compact")

Exit Function

end if

types = getFolderField(folderId,fTYPES)

Dim newIndex
newIndex = 0
if isArray(types) then
newIndex = ubound(types,2) + 1
Redim Preserve types(5,newIndex)
'response.write "Redim Preserve types(5,newIndex)<br>"
'response.write "Redim types(5,0)<Br>"
Redim types(5,0)
end if

'Add the type id and index position in array to the ti dict
ti.Add typeId, newIndex
tf.Add typeId, folderId

types(tTYPEID,newIndex) = typeId
types(tFOLDERID,newIndex) = folderId
types(tTYPENAME,newIndex) = typeName
types(tTYPEICON,newIndex) = typeIcon
types(tTYPEDESCRIPTION,newIndex) = typeDescription
types(tARTICLES,newIndex) = ""

'Set it BACK the types array to the folders...
folders(fTYPES,getFolderIndex(folderId)) = types
response.write "No types found for grab ids specified!"
end if
else if isNumeric(typeArray) then
'If I just entered one number... make it an array...
'Then call the function again... :D
typeArray = Array(typeArray)
call grabType(typeArray,mode)
response.write "Invalid input for type array!"
end if
end if
end function



'gets the index that the a folder with folderId is stored in the folders array
function getFolderIndex(folderId)
if isFolderGrabbed(folderId) then
getFolderIndex = fi.Item(folderId)
response.write "Non-existent fid"
end if
end function

function tellMeFid(typeId)
if isTypeGrabbed(typeId) then
tellMeFid = tf.Item(typeId)
tellMeFid = "Type id was not grabbed!"
end if
end function

'gets the index that the a type with typeId is stored in the types array
function getTypeIndex(typeId)
if isTypeGrabbed(typeId) then
getTypeIndex = ti.Item(typeId)
response.write "Non-existent tid"
end if
end function

'gets a folder field based on folder id and index
function getFolderField(folderId,fieldIndex)
if countDims(folders) = 2 then
if ubound(folders,1) >= fieldIndex then
getFolderField = folders(fieldIndex,getFolderIndex(folderId))
getFolderField = "Field out of range!"
end if
getFolderField = "No folders grabbed. Cannot get folder fields!"
end if
end function

'gets a type field based on type id and index
function getTypeField(folderId,typeId,fieldIndex)
if isFolderGrabbed(folderId) then
if isTypeGrabbed(typeId) then
Dim types
types = folders(2,getFolderIndex(folderId))
if not isArray(types) then
getTypeField = "Type information NOT found in folders array!"
if ubound(types,1) >= fieldIndex then
getTypeField = types(fieldIndex,getTypeIndex(typeId))
getTypeField = "Field too great!"
end if
end if

isTypeGrabbed = "Type not grabbed!"
end if
getTypeField = "Folder for this type not grabbed!"
end if
end function