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
> >
> >
>
>