Results 1 to 14 of 14

Thread: [RESOLVED] Mysterious Compiler Error

  1. #1

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved [RESOLVED] Mysterious Compiler Error

    I've stumbled upon one of those mysterious coding bugs that drives all of us crazy. I was removing some code in Form A, adding some new code in Form B and Class A, and when I try to compile my project, I'm getting an error in a BAS file that I haven't touched in weeks. I use the following function to help me find information in the registry, and I don't see why any of my changes should've caused the compiler to blow up in an unrelated BAS module.
    VB Code:
    1. Private Function Query_ValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
    2.     On Error GoTo QueryValueExError
    3.    
    4.     Dim cch             As Long
    5.     Dim lrc             As Long
    6.     Dim lType           As Long
    7.     Dim lValue          As Long
    8.     Dim sValue          As String
    9.    
    10.     lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    11.     If lrc <> m_ERROR_NONE Then Error 5
    12.     Select Case lType
    13.         Case m_REG_SZ:
    14.         sValue = String(cch, 0)
    15.         lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
    16.         If lrc = m_ERROR_NONE Then
    17.             vValue = Left$(sValue, cch) '<--- ERROR HERE
    18.         Else
    19.             vValue = Empty
    20.         End If
    21.     Case m_REG_DWORD:
    22.         lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
    23.         If lrc = m_ERROR_NONE Then vValue = lValue
    24.     Case Else
    25.         lrc = -1
    26.     End Select
    27.    
    28. QueryValueExExit:
    29.     Query_ValueEx = lrc
    30.     Exit Function
    31.    
    32. QueryValueExError:
    33.     Resume QueryValueExExit
    34. End Function
    Compile Error: Type-declaration character does not match declared data type. Any ideas?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Mysterious Compiler Error

    it could be because:

    - vValue is declared As Variant
    - and Left$() returns String type
    - and/or cch is declared As Long and Left$() is "expecting" Integer...

    Try to use Left() instead or declare vValue as String at least.

    Normaly those shoudn't be a problem unless cch exceeds Integer boundaries...

  3. #3

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Mysterious Compiler Error

    Quote Originally Posted by RhinoBull
    Try to use Left() instead or declare vValue as String at least.
    Compile Error: Expected Array

  4. #4

  5. #5

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Mysterious Compiler Error

    Quote Originally Posted by RhinoBull
    Oh, common ... that's not even funny ... Left(...) is a function so simply type Left without the "()" or type arguments inside the "(text, length)"...
    Same error.

    I agree with you that it is so simple that it shouldn't be choking on it. I'm starting to think I've done something elsewhere in the code that is causing the compiler to have a brainfreeze and forget that Left() isn't complicated and is getting an array: sValue (a string)

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Mysterious Compiler Error

    Because vValue is a variant.... it's going to take on the datatype of what ever is passed in.... it should either be hard typed to a string, or it should be checked ahead of time to make sure it is a string.

    -tg

    RB - it was too funny.... *stifles a laugh*
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Mysterious Compiler Error

    Try:
    VB Code:
    1. sValue = String(cch, " ")
    or
    VB Code:
    1. sValue = Space(cch)

  8. #8

  9. #9

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Mysterious Compiler Error

    Quote Originally Posted by MartinLiss
    Close the project and reopen it. Do you still get the error?
    Yes, I still get the error.

  10. #10

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Mysterious Compiler Error

    Quote Originally Posted by schoolbusdriver
    Try:
    VB Code:
    1. sValue = String(cch, " ")
    or
    VB Code:
    1. sValue = Space(cch)
    Both of your suggestions worked using vValue or sValue.

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Mysterious Compiler Error

    VB Code:
    1. Dim vValue
    2. Dim cch             As Long
    3. Dim sValue          As String
    4. sValue = "this is a test"
    5. cch = 4
    6. vValue = Left$(sValue, cch)
    7. MsgBox vValue

    As you would expect the above works fine. Do you have a user-defines function called Left? In any case try using VBA.Left

  12. #12

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved Re: Mysterious Compiler Error

    Quote Originally Posted by MartinLiss
    As you would expect the above works fine. Do you have a user-defines function called Left? In any case try using VBA.Left
    We have a winner! Here is the culprit code that--when renamed--resolved my problem:
    VB Code:
    1. Public Enum ceVScrollType
    2.     Invisible = 0
    3.     Right = 1      ' Renamed to tRight:  Problem solved
    4.     Left = 2       ' Renamed to tLeft:  Problem solved
    5. End Enum
    Crazy.

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: [RESOLVED] Mysterious Compiler Error

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

  14. #14

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Mysterious Compiler Error

    Quote Originally Posted by MartinLiss
    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.
    It's already been done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width