none
Type Mismatch Run-Time Error 13 RRS feed

  • Question

  • Another question regarding code not working...Please examine the following code:

    Private Sub Find_Latest_Build(Src_Folder As String)

    Dim fso, fold, fl, NameFile
    Dim VerNo(3) As Integer, ChkNo As Integer
    Dim StartPos As Integer, i As Integer
    Dim ChkChar As String, ChkMrk As String, VerStr As String
    Dim strFileName As String, strFileExtension As String
    Dim Latest_File As Boolean

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fold = fso.GetFolder("C:\Users\johnb\Desktop\6.0") 'new location
    Set fl = fold.Files
    For i = 0 To 3
    VerNo(i) = 0
    Next
    For Each NameFile In fl
    Latest_File = False
    StartPos = 1
    i = 0
    strFileName = NameFile.Name
    strFileExtension = LCase(Right(strFileName, 3))
    If (strFileExtension = "zip") And (Not (InStr(1, strFileName, "Conversion Service"))) Then
    VerStr = Right(Left(strFileName, (InStr(1, strFileName, "_") - 1)), InStr(1, strFileName, " ") + 1)
    Do While (i <= 3) And Not (Latest_File)
    ChkMrk = InStr(StartPos, VerStr, ".")
    If ChkMrk = 0 Then
    ChkChar = Mid(VerStr, StartPos)
    Else
    ChkChar = Mid(VerStr, StartPos, ChkMrk - 1)
    End If
    ChkNo = CInt(ChkChar)
    If ChkNo > VerNo(i) Then
    VerNo(i) = ChkNo
    Latest_File = True
    End If
    StartPos = ChkMrk + 1
    i = i + 1
    Loop
    End If
    If Latest_File = True Then
    Src_Folder = strFileName
    End If
    Next

    End Sub

     

    The statement in bold generates a type mismatch error (13). What I need to do is convert a number from string format to integer. How do I do that?

    Please advise. Thanks again.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)
    Friday, January 27, 2012 1:49 AM

Answers

  • You're doing the conversion correctly - To see why it is failing, put this line just before the conversion:

    MsgBox "VerStr is """ & VerStr & """, and ChekChar is """ & ChkChar & """"

    and make sure that verstr and chkchar are all numeric. You may be grabbing the wrong part of the file name string.


    HTH, Bernie
    • Marked as answer by jbottiger2367 Friday, January 27, 2012 4:15 PM
    Friday, January 27, 2012 2:16 AM

  • That would be because ChkChar is not a text representaion of a number.
    You can't convert "a" to a number (at least not with CInt), but you can convert "1" to a number.

    In case it matters...
    Asc("a") = 97
    '---
    Jim Cone
    Portland, Oregon USA
    http://www.mediafire.com/PrimitiveSoftware
    (List Files XL add-in:  finds and lists files/folders with hyperlinks)

    • Marked as answer by jbottiger2367 Friday, January 27, 2012 4:15 PM
    Friday, January 27, 2012 2:18 AM

All replies

  • You're doing the conversion correctly - To see why it is failing, put this line just before the conversion:

    MsgBox "VerStr is """ & VerStr & """, and ChekChar is """ & ChkChar & """"

    and make sure that verstr and chkchar are all numeric. You may be grabbing the wrong part of the file name string.


    HTH, Bernie
    • Marked as answer by jbottiger2367 Friday, January 27, 2012 4:15 PM
    Friday, January 27, 2012 2:16 AM

  • That would be because ChkChar is not a text representaion of a number.
    You can't convert "a" to a number (at least not with CInt), but you can convert "1" to a number.

    In case it matters...
    Asc("a") = 97
    '---
    Jim Cone
    Portland, Oregon USA
    http://www.mediafire.com/PrimitiveSoftware
    (List Files XL add-in:  finds and lists files/folders with hyperlinks)

    • Marked as answer by jbottiger2367 Friday, January 27, 2012 4:15 PM
    Friday, January 27, 2012 2:18 AM
  • Thanks Bernie.

     

    It looks like I used the wrong string function (Right)...replaced with Mid, and it works.  Thanks.

     


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)
    Friday, January 27, 2012 3:30 PM