Home > DeveloperSection > Forums > vbs type mismatch: [string]
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    June-20-2013 1:47 AM

 VB Script VB Script 
Ratings:


 1 Reply(s)
 1023  View(s)
Rate this:
Hi,

I have the following code giving me an error and I can't understand why.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder(strOrigDir)
Set colFiles = objDir.Files

For Each strFile in colFiles
Select Case Right(strFile,3)
    Case "rar"
        strTarFile = strFile
        intIsRar = 1
        Exit For
    Case "avi" or "mkv" or "mp4"
        strTarFile = strFile
        Exit For
    Case Else
        WScript.Quit
End Select
Next

I receive the message Type mismatch: '[string:"avi"]' on the Select Case line and I can't understand why. I have checked the value of strFile using VarType to make sure I'm not going crazy and trying to compare a string to something I shouldn't be (VarType returns 8). Any ideas why this is incorrect?

Thanks in advance for any recommendations or solutions.



Vijay Shukla

Total Post:100

Points:700
Posted on    June-20-2013 5:20 AM

Hi,

The problem is in the syntax of the Select Case statement. If you want multiple cases, you need to use a comma-delimited list:

Select Case Right(strFile,3)
    Case "rar"
        strTarFile = strFile
        intIsRar = 1
        Exit For
    Case "avi", "mkv", "mp4"
        strTarFile = strFile
        Exit For
    Case Else
        WScript.Quit
End Select

The "type mismatch" is probably happening because it is trying to evaluate "avi" or "mkv" or "mp4" as a Boolean statement.


Don't want to miss updates? Please click the below button!

Follow MindStick