Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Type Mismatch error when passing in string in VB

Type Mismatch error when passing in string in VB

Scheduled Pinned Locked Moved Visual Basic
c++comhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Rymer
    wrote on last edited by
    #1

    Hey, I'm getting a "Type Mismatch error" in VB when I try and pass a string into an ActiveX method. The method parameter comes up and says "As String" when typing in to call the function, and we tried putting it in a variable & just typing the string out in it... I used VC++6.0 to make it, so if there is something i could have done wrong, let me know as to what i might try doing when i make the function when adding a method, etc in VC++ (i made a light control in VC) ~Tim SHABBA!!

    R 1 Reply Last reply
    0
    • T Tim Rymer

      Hey, I'm getting a "Type Mismatch error" in VB when I try and pass a string into an ActiveX method. The method parameter comes up and says "As String" when typing in to call the function, and we tried putting it in a variable & just typing the string out in it... I used VC++6.0 to make it, so if there is something i could have done wrong, let me know as to what i might try doing when i make the function when adding a method, etc in VC++ (i made a light control in VC) ~Tim SHABBA!!

      R Offline
      R Offline
      Roger Wright new
      wrote on last edited by
      #2

      One possible mismatch is the format used for strings in the two languages. VC++ supports two types, char[] which contains a string followed by a null character, and a CString class, which must be set by a call to it's constructor method. VB includes a basic string type, but any operations done on a string return a VARIANT type unless the function specifies a string type by appending $ to the function name (ie Ucase$ instead of Ucase). So there are many possible mismatches. The very first thing I'd try, though, is to pass by value instead of by reference (the default in VB). The form of this would be "ByVal sMyString as String". This type of call is used to pass a VB string to a C++ char[] variable. According to one reference, VB5 Developer's Handbook, you will never be able to use a VB string with a C++ module that wasn't written deliberately for use with VB. That's probably a bit pessimistic, but I'm no expert in either language - still pining for Turbo Pascal, alas... On A Never-Ending Quest For Enlightenment, and Another Beer

      B 1 Reply Last reply
      0
      • R Roger Wright new

        One possible mismatch is the format used for strings in the two languages. VC++ supports two types, char[] which contains a string followed by a null character, and a CString class, which must be set by a call to it's constructor method. VB includes a basic string type, but any operations done on a string return a VARIANT type unless the function specifies a string type by appending $ to the function name (ie Ucase$ instead of Ucase). So there are many possible mismatches. The very first thing I'd try, though, is to pass by value instead of by reference (the default in VB). The form of this would be "ByVal sMyString as String". This type of call is used to pass a VB string to a C++ char[] variable. According to one reference, VB5 Developer's Handbook, you will never be able to use a VB string with a C++ module that wasn't written deliberately for use with VB. That's probably a bit pessimistic, but I'm no expert in either language - still pining for Turbo Pascal, alas... On A Never-Ending Quest For Enlightenment, and Another Beer

        B Offline
        B Offline
        Bill Wilson
        wrote on last edited by
        #3

        Try using a Variant. Hope this helps, Bill

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups