expected type mismatch error - vb6

I'm expecting a ByRef Argument Type Mismatch at compile time but I'm not getting it. It's compiling without errors and failing at runtime with error 13, "Type mismatch".
It's a fairly simple to reproduce.
dim c as Car
Set c = New Car
Sail c
...
Public Sub Sail(ByRef b As Boat)
...
End Sub
Car does not inherit from Boat
Is there a setting (or plugin perhaps) that will force VB into a strict compilation mode?
Edit: it looks like there's no compiler option for this. Does anyone know of an addon that analyses the source for these casting issues during a compile?

Is it possible to set Option Strict True in VB6?
Edit: Apparently it is not possible in VB6 (seems to have been introduced with VB 7.0)

Related

VB6.0 extension/reference bug, getting error "Method or data member not found"

Note: I'm not an experienced programmer
I've been handed some old VB6.0 programs for my work, which were compiling and running successfully in the past, but now when I try to compile, the error "Method or data member not found" is coming up on some ".Text" property calls.
I'm very confident that it's most likely not the code because it was working before it was assigned to me, so possibly the issue is extensions/references that are no longer accessible by the program. However, I'm sure some people will want to see the code so I've provided a few .Text calls, all of which are following a text field. For legal reasons, I can't copy the program but here are a few calls:
'Ex1: Line 312 frmMain
Print #gintAteDataFile, Tab; gstrDate; Tab; gstrtime; Tab; Tab; “Technician: “; frmTechId.mebTechId.Text
'Ex2: Line 4 frmSerialNumber
gstrSerialNumber = MaskEdBox1.Text
'Ex3: Line 34 frmComSetup
If IPControl1.IsBlank Or mebPortNumber.Text = vbNullString Then
I have been unable to locate an answer on Google. Does anyone know what references or extensions are necessary for VB6.0 for a property such as ".Text" to not be called correctly? Thank you

TypeScript cast (assertion) results in Syntax Error compiler warning?

I've got a TypeScript script that has to interact with a third-party vendor that uses global functions as callbacks (you can't pass in a callback). For instance, to "listen" for a result from their "API", you define the function SetElqContent. E.g.,
window.SetElqContent = function(){/* handle result */};
When the TypeScript compiler sees this line, it complains that The property 'SetElqContent' does not exist on value of type 'Window'.
I thought I could get around this by simply casting to type "any". Actually, this isn't type casting but type assertion, but I think of it as casting, although I understand it's not quite the same. So, I tried:
(<any>window).SetElqContent = function(){/* handle result */};;
To m y surprise, this results in Syntax error, and the line number and column points to the < character in the <any> cast. I tried a few other variants, and I get Syntax error on the initial < of the cast no matter what kind of cast I was doing:
var windowAny = <any>window;
var docElement = <HTMLElement>window.document;
What is it about my type assertions that is invalid syntax?
I'm using Visual Studio 2013 with Update 2, which has a "compile on save" feature for TypeScript files. That's how I'm compiling my .ts files, and it's from in Visual Studio where the Syntax error message is emitted.
UPDATE: Apparently this is related to Visual Studio. When I use the standalone tsc compiler to compile the same file, it emits no errors or warnings.
Apparently my syntax is correct but there is a bug in the Visual Studio tooling. I can't provide exact reproduce steps, and in fact, deleting everything in the .ts file, saving, then restoring the code (via ctrl-z) and resaving caused the "syntax error" warning to disappear.
If I can determine any more specifics about what causes this issue to manifest, I'll report back.
Best way is to create a type definitions file for it
If the library name is eloqua.js, you create a eloqua.d.ts file and refer to it in your .js file like
/// < reference path="../typings/eloqua.d.ts" />
There are many type definition files online available at definitelyTyped website.
https://github.com/borisyankov/DefinitelyTyped
You can contribute yours to there as well.
If you extend the Window interface definition, you'll remove the error:
interface Window {
SetElqContent: Function;
}
window.SetElqContent = function(){/* handle result */};
Here is how you can do the assertion properly:
function SetElqContent(){/* handle result */};
// FINE
(<any>window).SetElqContent = SetElqContent;
or
// FINE
(<any>window).SetElqContent = function SetElqContent(){/* handle result */};
However you should avoid asserting and just do what Steve Fenton recommends as it is more discoverable
Update
Demo in VS:

Getting error when trying to create vertices in cocos2d

I'm getting the error
Cannot Initialize a variable of type 'LineVertex*' (aka '_Line Vertex*) with an rvalue of type 'void*'
This is the line of code:
LineVertex *vertices = calloc(sizeof(LineVertex*), numberOfVertices);
This worked until I switched my class from .m to .mm and now it's throwing me that error and I don't know how to fix it. I am using Xcode 5 and the latest version of Cocos2D. I read that it might have something to do with casting but I honestly don't know how to do that, I couldn't get it to work correctly. Thank you so much in advance!
It should be like this.
LineVertex *vertices = static_cast<LineVertex *>(calloc(sizeof(LineVertex*), numberOfVertices));
For further information, please take a look at the FAQ.
Bjarne Stroustrup's C++ Style and Technique FAQ: Why must I use a cast to convert from void*?

VB6 random double overflow errors

does anyone know a cause for random overflow errors in vb6?
I have to customize a legacy application written in VB6 and lately overflow errors have started to occur all over the place. Sometimes in functions which have not been touched in years!
The error always happens when trying to assign something to a variable of type Double.
The reason for those errors is probably not the code that throws the error but something else. But I dont know what to look for. The most confusing example of a function failing with an overflow error was the following code:
Dim test As Double
test = 0#
How can that possibly throw an overflow error?
I tried enabling some compiler optimizations, like not checking for floating point calculation errors, and some more. This has "solved" some of the problems, but others remain.
VB6 will run things in such a way where if something external signals a floating-point error flag, it'll not be reported until the next floating-point operation is performed within your own code.
Under most circumstances, this is likely caused by some DLL that is performing floating-point operation. If you have any control over these external DLLs, then my suggestion is to put this line at the end of the functions called by your application:
_clearfp();
This function is documented here: http://msdn.microsoft.com/en-us/library/49bs2z07.aspx
If you do not have much control, you can get around this by making your own function called from a DLL that calls that function. Or a simple hack with only using VB6 is:
Public Sub ClearFP()
On Error Resume Next
Dim d as Double
d = 0#
End Sub
Which you can call after any DLL calls that you believe is the culprit.
A trick to isolating which function did it originally, is simply look at the calls before the error appears. Alternatively, a more complicated solution, is to compile your application and run it through a debugger that can break on floating-point exceptions.
In VB6 the hash (#) symbol can mean many things:
Used in file names
used with dates ususlly when applied to DBs
To treat Numbers as Doubles
To compile constants or sections of code if a condition is true
I'm sure there are more.
It may depend on the compiler.
My suggestion would be to try:
Dim test As Double
test = CDbl(0)
to see if that resolves the issue.

QTP/VBScript Syntax of constructor call

Not using QTP myself, but trying to answer this question, I desperately need to know, whether this valid VBScript:
Class C
Function init(x, y)
Set init = Me
End Function
End Class
Dim o : Set o = New C.init(0, 1)
will cause a syntax error in QTP - or more generally: Does QTP implement its own dialect of VBScript?
This is valid in QTP too.
QTP uses VBScript as the engine for running tests, there are some extensions on the language that allow using test objects but most of these just look like global functions and objects. As far as I know nothing is removed from VBScript.
The limitations QTP has regarding class types are regarding intellisense and such not execution of the test/script.

Resources