Type Mismatch error when passing in string in VB
-
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!!
-
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!!
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
-
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
Try using a Variant. Hope this helps, Bill