ULong Variable not working!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

ULong Variable not working!

Postby sysprofessional » Sat Jan 11, 2020 10:12 pm

Hi everyone,

I'm using FC 6.1.4 with 16f887, facing issue with Ultra Long variable ,it should handle value between (0 to 4294967295) .
But its acting like Long variable ,(-2147483648 to 2147483647), Can someone please resolve this for me ?
any help will be appreciated,

Thanks in advance

kersing
Valued Contributor
Valued Contributor
Posts: 1877
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 533 times
Been thanked: 1043 times
Contact:

Re: ULong Variable not working!

Postby kersing » Sat Jan 11, 2020 10:36 pm

Could you provide some context? May-be even a flowchart demonstrating the issue?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

Re: ULong Variable not working!

Postby sysprofessional » Sat Jan 11, 2020 11:03 pm

kersing wrote:Could you provide some context? May-be even a flowchart demonstrating the issue?


Hi Kersing,
Simple test Just put a calculation icon in flowchart and calculate the value " test = 2+2147483647 " result overflowing like -2147483647,test variable already added as ULong.
Flowchart image attached.
Untitled-1.jpg
Untitled-1.jpg (97.15 KiB) Viewed 112 times

mnf
Valued Contributor
Valued Contributor
Posts: 587
Joined: Wed May 31, 2017 11:57 am
Has thanked: 56 times
Been thanked: 326 times
Contact:

Re: ULong Variable not working!

Postby mnf » Sun Jan 12, 2020 12:02 am

It could well be that the display routine in FC expects a signed long rather than an unsigned long. The value is probably correct - but is displayed incorrectly...

Martin

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

Re: ULong Variable not working!

Postby sysprofessional » Sun Jan 12, 2020 12:05 am

ok i try to simulate.

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

Re: ULong Variable not working!

Postby sysprofessional » Sun Jan 12, 2020 12:45 am

Unfortunately same result in simulation,i'm wondering because i have write many programs using ULong,may be one year ago,but this time idk why strange behavior from ULong.I have recently uninstalled FC 6.1.4 and install old version 6.1.0,but no luck ,can it be windows issue?
here is the simulation result ULong incremented by 1 , every second
ULongTest.jpg
ULongTest.jpg (217.79 KiB) Viewed 103 times

mnf
Valued Contributor
Valued Contributor
Posts: 587
Joined: Wed May 31, 2017 11:57 am
Has thanked: 56 times
Been thanked: 326 times
Contact:

Re: ULong Variable not working!

Postby mnf » Sun Jan 12, 2020 2:56 am

Same result - as soon as bit 31 is set - the display routine assumes that it is a negative number. Try converting the number to a hex string then output that....

Martin

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

Re: ULong Variable not working!

Postby sysprofessional » Sun Jan 12, 2020 4:32 pm

I have tested its working fine on hardware, just FC simulating it wrongly,
tested in this way.
1. receiving 32bit string at Comport ,
2. converted it to ULong.
3. splitting into 4 bytes ,
4. stored into EEprom.
5. extract back to 4 bytes, byte0,byte1,.....and so on
i have checked here all 4 values in the EEprom perfect.
6. combining these 4 values to a ULong.

its working fine till here but when i try to convert it to string at step 7 ,again resulting in Long (-2147483648 to 2147483647)

7. String = ToString$(ULong);

any suggestions .....?
how can i convert 32bit Ultra Long to String.
These users thanked the author sysprofessional for the post:
Benj (Mon Jan 13, 2020 11:11 am)
Rating: 5.26%
 

mnf
Valued Contributor
Valued Contributor
Posts: 587
Joined: Wed May 31, 2017 11:57 am
Has thanked: 56 times
Been thanked: 326 times
Contact:

Re: ULong Variable not working!

Postby mnf » Sun Jan 12, 2020 5:01 pm

You can use NumberToHex$(x) - which returns a string. This works correctly (ie it takes an unsigned long and returns a string)

If you need the value in decimal that is also fairly easy - attached is a very simple demo - that first converts (-1 - so maximum 32 bit number (2^32 - 1)) to a hex number and then converts it to a decimal string....

test.fcfx
(7.72 KiB) Downloaded 2 times


Martin
These users thanked the author mnf for the post (total 3):
Benj (Mon Jan 13, 2020 11:11 am) • medelec35 (Tue Jan 14, 2020 2:29 pm) • sysprofessional (Fri Jan 17, 2020 1:50 am)
Rating: 15.79%
 

User avatar
sysprofessional
Posts: 52
Joined: Sat Oct 26, 2013 7:16 pm
Has thanked: 26 times
Been thanked: 3 times
Contact:

Re: ULong Variable not working!

Postby sysprofessional » Tue Jan 14, 2020 12:44 pm

I have already done using that method. btw thanks for your co-operation .

Best of luck all of you guys.

User avatar
Steve
Matrix Staff
Posts: 3080
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 391 times
Contact:

Re: ULong Variable not working!

Postby Steve » Thu Jan 16, 2020 11:09 am

For info, I checked v8 and it seems to work fine. I assume this bug was fixed a while ago in v7 or v8.

ulong.png
ulong.png (18.41 KiB) Viewed 16 times
These users thanked the author Steve for the post:
sysprofessional (Fri Jan 17, 2020 1:50 am)
Rating: 5.26%