OK, I can't seem to figure out this Type Mismatch error I keep getting. I
have a ASP VBScript going here:
------------
Function IsPicture(objFile)
Dim arrFileParts(2),fileName
arrFileParts = Split(objFile.Name,".")
If arrFileParts(1) = "jpg" Or arrFileParts(1) = "jpeg" Then
IsPicture = true
ElseIf arrFileParts(1) = "bmp" Or arrFileParts(1) = "gif" Then
IsPicture = true
ElseIf arrFileParts(1) = "png" Then
IsPicture = true
End If
IsPicture = false
End Function
------------
And the following lines proceeding the above script:
------------
Dim fsoObj,objFolder,objFile,intCount,num
Const strPath = "images/"

Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
------------

I've been sitting here for a solid hour and a half tinkering with it and I
have turned up nothing, I am a rookie by the way, go easy on me, haha. Your
help is much appreciated.

~Les Peabody

Re: Type mismatch problem by Ray

Ray
Sat Jan 17 02:12:33 CST 2004

The simple fix would be to dim arrFileParts like this instead:

Dim arrFileParts


What I suggest you do instead though is use the GetExtensionName method of
the FSO and use one IF. Also, if you use a separate function, just pass a
string to it instead of an object. Try:

Dim fsoObj,objFolder,objFile,intCount,num
Const strPath = "images/"

Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
'''is there code that you're using to get a file?
Response.Write IsPicture(fsoObj.GetExtensionName(YourPathToTheFile))



Function IsPicture(fileext)
Dim sValidExtensions
IsPicture = False
sValidExtensions = "|jpg|jpeg|bmp|gif|png|"
IsPicture = (Instr(sValidExtensions, "|" & fileext & "|") > 0)
End Function


The things to note:
If, ElseIf, ElseIf, ElseIf can get kinda messy. Select Case is often used
in place of all those ifs. In your particular example, you only really
needed one IF statement anyway.

The reason that we can stick all those extensions together with | separating
them and on either end is that as | is not an allowable character in a file
or directory name, it is a safe delimiter and makes things a little cleaner
than:

If sExt = "jpg" or sExt = "jpeg" or sExt = "bmp" or sExt = "gif............


Also, I'm guess that you don't know that arrays are zero-based in VBScript.
That means that if an array has two elements, you'd dim it like:

dim var(1)

Value 1 is index 0 and value 2 is index 1. Most filenames only have one .
in them, which is what makes me thing you were thinking of a base 1 array by
dimming it with (2).

Ray at home







"Les Peabody" <les.peabody@geo-sync.com> wrote in message
news:OqZU1xM3DHA.484@TK2MSFTNGP10.phx.gbl...
> OK, I can't seem to figure out this Type Mismatch error I keep getting. I
> have a ASP VBScript going here:
> ------------
> Function IsPicture(objFile)
> Dim arrFileParts(2),fileName
> arrFileParts = Split(objFile.Name,".")
> If arrFileParts(1) = "jpg" Or arrFileParts(1) = "jpeg" Then
> IsPicture = true
> ElseIf arrFileParts(1) = "bmp" Or arrFileParts(1) = "gif" Then
> IsPicture = true
> ElseIf arrFileParts(1) = "png" Then
> IsPicture = true
> End If
> IsPicture = false
> End Function
> ------------
> And the following lines proceeding the above script:
> ------------
> Dim fsoObj,objFolder,objFile,intCount,num
> Const strPath = "images/"
>
> Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
> ------------
>
> I've been sitting here for a solid hour and a half tinkering with it and I
> have turned up nothing, I am a rookie by the way, go easy on me, haha.
Your
> help is much appreciated.
>
> ~Les Peabody
>
>



Re: Type mismatch problem by john

john
Sat Jan 17 07:46:30 CST 2004

"Les Peabody" <les.peabody@geo-sync.com> wrote in message news:<OqZU1xM3DHA.484@TK2MSFTNGP10.phx.gbl>...
> OK, I can't seem to figure out this Type Mismatch error I keep getting. I
> have a ASP VBScript going here:
> ------------
> Function IsPicture(objFile)
> Dim arrFileParts(2),fileName
> arrFileParts = Split(objFile.Name,".")
> If arrFileParts(1) = "jpg" Or arrFileParts(1) = "jpeg" Then
> IsPicture = true
> ElseIf arrFileParts(1) = "bmp" Or arrFileParts(1) = "gif" Then
> IsPicture = true
> ElseIf arrFileParts(1) = "png" Then
> IsPicture = true
> End If
> IsPicture = false
> End Function
> ------------
> And the following lines proceeding the above script:
> ------------
> Dim fsoObj,objFolder,objFile,intCount,num
> Const strPath = "images/"
>
> Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
> ------------
>
> I've been sitting here for a solid hour and a half tinkering with it and I
> have turned up nothing, I am a rookie by the way, go easy on me, haha. Your
> help is much appreciated.
>
> ~Les Peabody

Im not sure about the type mismatch but with IsPicture = false outside
your "If - End If" the function will always return False. Won't it?

Re: Type mismatch problem by Les

Les
Sat Jan 17 11:18:22 CST 2004

I was assuming that when you set the function equal to a value it would
automatically exit the function returning the value it was set equal to, I'm
used to C++...lol, I also wrote the code at 2:30 in the morning roughly,
thought process was kept at a minimum :) Thanks guys, I appreciate the
help.

~Les Peabody

"John" <john@johnmidge.freeserve.co.uk> wrote in message
news:1a6a05e5.0401170546.7be5a735@posting.google.com...
> "Les Peabody" <les.peabody@geo-sync.com> wrote in message
news:<OqZU1xM3DHA.484@TK2MSFTNGP10.phx.gbl>...
> > OK, I can't seem to figure out this Type Mismatch error I keep getting.
I
> > have a ASP VBScript going here:
> > ------------
> > Function IsPicture(objFile)
> > Dim arrFileParts(2),fileName
> > arrFileParts = Split(objFile.Name,".")
> > If arrFileParts(1) = "jpg" Or arrFileParts(1) = "jpeg" Then
> > IsPicture = true
> > ElseIf arrFileParts(1) = "bmp" Or arrFileParts(1) = "gif" Then
> > IsPicture = true
> > ElseIf arrFileParts(1) = "png" Then
> > IsPicture = true
> > End If
> > IsPicture = false
> > End Function
> > ------------
> > And the following lines proceeding the above script:
> > ------------
> > Dim fsoObj,objFolder,objFile,intCount,num
> > Const strPath = "images/"
> >
> > Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
> > Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
> > ------------
> >
> > I've been sitting here for a solid hour and a half tinkering with it and
I
> > have turned up nothing, I am a rookie by the way, go easy on me, haha.
Your
> > help is much appreciated.
> >
> > ~Les Peabody
>
> Im not sure about the type mismatch but with IsPicture = false outside
> your "If - End If" the function will always return False. Won't it?



Re: Type mismatch problem by Les

Les
Sat Jan 17 11:46:01 CST 2004

Thanks for the help Ray, you showed me a couple methods I didn't know about
and they have been incredibly useful to me in this script.

Help much appreciated,
~Les Peabody

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:OR4EqGN3DHA.2680@tk2msftngp13.phx.gbl...
> The simple fix would be to dim arrFileParts like this instead:
>
> Dim arrFileParts
>
>
> What I suggest you do instead though is use the GetExtensionName method of
> the FSO and use one IF. Also, if you use a separate function, just pass a
> string to it instead of an object. Try:
>
> Dim fsoObj,objFolder,objFile,intCount,num
> Const strPath = "images/"
>
> Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
> '''is there code that you're using to get a file?
> Response.Write IsPicture(fsoObj.GetExtensionName(YourPathToTheFile))
>
>
>
> Function IsPicture(fileext)
> Dim sValidExtensions
> IsPicture = False
> sValidExtensions = "|jpg|jpeg|bmp|gif|png|"
> IsPicture = (Instr(sValidExtensions, "|" & fileext & "|") > 0)
> End Function
>
>
> The things to note:
> If, ElseIf, ElseIf, ElseIf can get kinda messy. Select Case is often used
> in place of all those ifs. In your particular example, you only really
> needed one IF statement anyway.
>
> The reason that we can stick all those extensions together with |
separating
> them and on either end is that as | is not an allowable character in a
file
> or directory name, it is a safe delimiter and makes things a little
cleaner
> than:
>
> If sExt = "jpg" or sExt = "jpeg" or sExt = "bmp" or sExt =
"gif............
>
>
> Also, I'm guess that you don't know that arrays are zero-based in
VBScript.
> That means that if an array has two elements, you'd dim it like:
>
> dim var(1)
>
> Value 1 is index 0 and value 2 is index 1. Most filenames only have one .
> in them, which is what makes me thing you were thinking of a base 1 array
by
> dimming it with (2).
>
> Ray at home
>
>
>
>
>
>
>
> "Les Peabody" <les.peabody@geo-sync.com> wrote in message
> news:OqZU1xM3DHA.484@TK2MSFTNGP10.phx.gbl...
> > OK, I can't seem to figure out this Type Mismatch error I keep getting.
I
> > have a ASP VBScript going here:
> > ------------
> > Function IsPicture(objFile)
> > Dim arrFileParts(2),fileName
> > arrFileParts = Split(objFile.Name,".")
> > If arrFileParts(1) = "jpg" Or arrFileParts(1) = "jpeg" Then
> > IsPicture = true
> > ElseIf arrFileParts(1) = "bmp" Or arrFileParts(1) = "gif" Then
> > IsPicture = true
> > ElseIf arrFileParts(1) = "png" Then
> > IsPicture = true
> > End If
> > IsPicture = false
> > End Function
> > ------------
> > And the following lines proceeding the above script:
> > ------------
> > Dim fsoObj,objFolder,objFile,intCount,num
> > Const strPath = "images/"
> >
> > Set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
> > Set objFolder = fsoObj.GetFolder(Server.MapPath(strPath))
> > ------------
> >
> > I've been sitting here for a solid hour and a half tinkering with it and
I
> > have turned up nothing, I am a rookie by the way, go easy on me, haha.
> Your
> > help is much appreciated.
> >
> > ~Les Peabody
> >
> >
>
>