API2 Analysis Warnings - Converting from UInt32 to Int32


I am working on API 2 with Xojo 3.1, and have all Analysis Warnings turned on, just so that I can clearly understand API 2 code.

When I analyze the following code, I get the error:

Window1.PushButton1.Action, line 2 - Converting from UInt32 to Int32 causes the sign information to be lost, which can lead to unexpected results DevNum = DevNum + 1

Here is the code in the action event:

Sub Action() Handles Action Var DevNum as UInt32 DevNum = DevNum + 1 End Sub

Is this expected API2 behavour, or a bug? Thanks!

Edit: Is there another way that incrementing a variable is to be implemented in API2? Just asking…

What is wrong with

dim DevNum as integer = 1


[quote=486107:@Beatrix Willius]What is wrong with

dim DevNum as integer = 1

Hi Beatrix,

This was in a loop, and I had to increment a value for each part of the loop.

Edit: I just made a quick example to be able to see the error :slight_smile:

It looks like a really old bug <https://xojo.com/issue/4281>

Alas you can’t cast everything on the For loop as some things are added at compile time so this doesn’t work:

For n As UInt32 = UInt32(0) To UInt32(9) system.DebugLog(str(i)) Next n

You could do this instead, but its pretty ugly:

Dim i As UInt32 = 0 While i <= UInt32(9) system.DebugLog(str(i)) i = i + UInt32(1) Wend

or you could turn off the warning and live in ignorant bliss like the rest of us :wink:

Yes, that feedback report was from 2008.

As always Julian, thank you for your great help. I am surprised that Xojo has not hired you yet :slight_smile:

When I received my Ph.D., one request my mentor had was for me to report mistakes, errors, and in general let people know about problems so that they have the opportunity to be better and make better products. As tempting as bliss is, its not an option.

Warm regards.

Maybe this ?

Sub Action() Handles Action
  Const Inc as Uint32 = 1 
  Var DevNum as UInt32
  DevNum = DevNum + inc
End Sub

Typed constants are handy :slight_smile:

I just changed one line of code that had three Warnings and Errors concerns and the code went from looking like this:

If BitwiseAnd(IntegerValue, FlagToCheck) <> 0 then //Has warnings

to this:

If CType(BitwiseAnd(CType(IntegerValue,Variant), CType(FlagToCheck,Variant)),Variant) <> 0 then //No warnings

Code seems to look a little more complicated, but it doesn’t provide warnings.

Which is why I generally turn that warning off as it literally has nothing to do with API 1 or 2
Its the compiler

why would you convert them to variants though ?

[quote=486196:@Norman Palardy]Which is why I generally turn that warning off as it literally has nothing to do with API 1 or 2
Its the compiler[/quote]
I definitely see why turning off the warnings are wanted. This is making C++ code seem much less complicated - although Xojo should be easier to program.

I am just trying to make the code less complicated by using a variant, which doesn’t seem to be the case. Tracking each data type, converting, is becoming a large amount of work.

I’ll need to check if there is a performance speed price for all of the extra commands that are being used in Xojo.