BACK to MENU

There is lots of info about using asp arrays on the net, but I still have difficulty with them. Because of my stupidity and to save myself from having to find the same info all over again, I am posting a bit of useful array code below. Perhaps it will be useful to someone else.

 

<%
Dim strDuh 'declaring the variable, a good habit
strDuh = request.querystring("key") 'the string we want to compare to the items in the array

Dim sMyArray(4)'what we name our array and how many items in it
sMyArray(0) = "countertest.asp" 'in this example, these are records I don't want code testers to be able to delete
sMyArray(1) = "countertest.asp?test=YES"
sMyArray(2) = "index.asp"
sMyArray(3) = "overall"

For Each i In sMyArray  'i can be any designation for the items in the array like z or bugguts or whatever

'now we need to set up a Case with with to compare our querystring to the items in the array
Select Case MatchArray 'give your case a name for identification purposes

Case YES

if i = strDuh then
Cal = "YES"

end if
End select


Next

If Cal = "YES" then response.write"You are not allowed to delete this record."

If NOT Cal = "YES" then 'hereafter you can place the code to display so that other records can be deleted by users.



%>

 

None of the following is original. It is all code that I borrowed from elsewhere and adapted for my own use. I'm placing it here so I don't have to go looking for it again the next time I wipe out my bookmarks.

Compare string to items in array:

<%
Dim sMyArray(4)'what we name our array and how many items in it
sMyArray(0) = ".mpg" 'in this example, these are records I don't want code testers to be able to delete
sMyArray(1) = ".mpeg"
sMyArray(2) = ".asf"
sMyArray(3) = ".wmv"
sMyArray(4) = ".avi"

'For Each i In sMyArray 'i can be any designation for the items in the array
for i = 0 to 4
next
if i = strExt then
%>
<!--#include file="windows_media_player.htm"-->
<% end if %>


----
Select Case With Array:

Dim sMyArray(4)'what we name our array and how many items in it
sMyArray(0) = "jpg" 'in this example, these are records I don't want code testers to be able to delete
sMyArray(1) = "gif"
sMyArray(2) = "jpeg"
sMyArray(3) = "bmp"
sMyArray(4) = "png"

For Each i In sMyArray 'i can be any designation for the items in the array

'now we need to set up a Case with with to compare our querystring to the items in the array
Select Case MatchArray 'give your case a name for identification purposes

Case YES

if i = strExt then
Cal = "YES"

end if
End select


Next

If NOT Cal = "YES" then
response.write "Sorry, that filetype " & strExt & " is not allowed. Your file must have one of the following extensions: "
for each i in sMyArray
response.write i &"; "

next
response.write "<br>Image files only."
response.end
end if


If you're getting this error
Microsoft VBScript runtime error '800a000d' type mismatch
with your array, then try this code instead, based on example at 4 Guys From Rolla.

<%

dim strFtype
strFtype = x_FILETYPE 'this assigns variable name to field from recordset %>
<% If Not IsNull(x_GALLERY_PIC) Then 'this merely means that if another field is empty or not
On Error Resume Next 'just a little cheat to avoid errors
Dim sMyArray(2) 'declare the array and how many items in it
sMyArray(0) = "image/pjpeg" 'we are comparing our filetype string to allowed types in array
sMyArray(1) = "image/gif"
Dim iLoop, bolFound
bolFound = False

For iLoop = LBound(sMyArray) to UBound(sMyArray)
If CStr(sMyArray(iLoop)) = CStr(strFtype) then
bolFound = True
End If
Next


if bolFound = True then
%>

This is where you choose the action or display you want for a True comparison.

<img src="../../../cgi-bin/thumbs/Imager.dll?Image=D:\html\users\walktrotlopecom\html\home\adogsdream\files\<%=x_GALLERY_PIC %>&Width=100&Compression=80">


<% erase sMyArray 'I decided to do this but don't know if it is necessary
End If
end if%>