Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Basic4ppc Wishlist > Bug Reports
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Bug Reports Post about errors or bugs encountered.

Conditional check failing for a Boolean type

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2008, 06:38 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default Conditional check failing for a Boolean type

Am I missing something obvious as this small program doesn't work as I expect? The conditional test fails and the msgbox isn't shown. It fails in the IDE and both compilers.

Code:
Sub Globals
  
'Declare the global variables here.
  Dim Checks(10As Boolean
  
Dim Flag
End Sub

Sub App_Start
  
For x = 0 To 9
    Checks(x) = 
false
  
Next
  
MsgBox(Checks(0))    
  Form1.Show
  Test
End Sub

Sub test
  
'If Not(Checks(0)) Then ' this works
  If Checks(0) = false Then ' this doesn't when Checks() are Boolean
    Msgbox("False")
  
End If
End Sub
Reply With Quote
  #2 (permalink)  
Old 01-02-2008, 10:19 PM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 366
Awards Showcase
Beta Tester 
Total Awards: 1
Default 8 bits not 1

I came accross this a while back, from memory I think boleans are implemented in Basic4ppc as 8 bits (not 1 bit as it strictly should be) so perhaps the check is comparing 0000001=1 or something like that?
Reply With Quote
  #3 (permalink)  
Old 01-03-2008, 02:54 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 768
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi agraham,
I confirm your finding. This phenomena shows up only with user
defined Boolean flags. There is an earlier discussion on this issue:
http://www.basic4ppc.com/forum/showthread.php?t=1358

If flag = true Then...NG
If flag Then...OK

If flag = false Then...NG
If Not(flag) Then...OK
Reply With Quote
  #4 (permalink)  
Old 01-03-2008, 08:00 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You should not declare the array as a boolean type.
Change it to:
Code:
Sub Globals
  
'Declare the global variables here.
  Dim Checks(10)
  
Dim Flag
End Sub

Sub App_Start
  
For x = 0 To 9
    Checks(x) = 
false
  
Next
  
MsgBox(Checks(0))    
  Form1.Show
  Test
End Sub

Sub test
  
'If Not(Checks(0)) Then ' this works
  If Checks(0) = false Then ' this doesn't when Checks() are Boolean
    Msgbox("False")
  
End If
End Sub
Reply With Quote
  #5 (permalink)  
Old 01-03-2008, 09:31 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Hi Robert
Quote:
Originally Posted by alfcen View Post
There is an earlier discussion on this issue:
http://www.basic4ppc.com/forum/showthread.php?t=1358
This is actually a different issue - that was boolean treatment in B4PPC default types. This is a "problem" with actual Boolean types.

Hi Erel
Quote:
Originally Posted by Erel View Post
You should not declare the array as a boolean type.
Change it to
That's a bit of get-out! Of course I know that works with default types but I wanted a large array to pass to a library and thought that I would declare it Boolean to save memory. I ran into this problem manipulating the returned results when I wrote what "came naturally" as a VB type conditional. At least the "C" type "if Bool then" conditional check works.
Reply With Quote
  #6 (permalink)  
Old 01-03-2008, 10:01 AM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 366
Awards Showcase
Beta Tester 
Total Awards: 1
Default hmmm

Have to say I think if an option to declare as Bolean is there it should work 'as expected'
its potentially problematic to have to keep a mental list of what ways things should and shouldnt be done? Especially for newbies or people porting basic code from other sources??

Im confused so the exact definitions in Basic4ppc of
true
True
false
False

Can anyone tell me?

Last edited by colin9876 : 01-03-2008 at 11:17 AM.
Reply With Quote
  #7 (permalink)  
Old 01-03-2008, 12:29 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by colin9876 View Post
Im confused so the exact definitions in Basic4ppc of
true
True
false
False
Can anyone tell me?
true and True are the same as are False and false.
"true" and "True" are not the same, neither are "false" and "False"

var = True actually sets a variable to the string value "true"
var = False actually sets a variable to the string value "false"
Because they are not quoted strings but are reserved keywords B4PPC treats them as a special case and lower-cases them if they are not already.

var = "true" achieves the same as var = true but var = "True" is NOT the same as in this case "True" is a quoted string and is assigned unchanged.

B4PPC conditional equality checks for true and false appear to be actually string comparisons against "true" and "false".

All this is because of the weak typing implemented in B4PPC.
Reply With Quote
  #8 (permalink)  
Old 01-03-2008, 12:51 PM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 366
Awards Showcase
Beta Tester 
Total Awards: 1
Default hmmm some typing might be useful

Thanks ... clear as mud lol!

Erel - I mentioned once before that personally I would like to have the option to 'type' a variable, for example number% as INT.
It would give speed increases, as Ive already found using number(0) as INT to perform faster than number when it defaults to a string.

Would this be something u would consider for the next version of Basic4ppc or do u not think its a good idea?
Reply With Quote
  #9 (permalink)  
Old 01-03-2008, 01:03 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Quote:
Would this be something u would consider for the next version of Basic4ppc or do u not think its a good idea?
Yes. I do consider it.

agraham explanation is correct and in the next update Boolean arrays will work properly.
Reply With Quote
  #10 (permalink)  
Old 01-03-2008, 01:22 PM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 768
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Andrew,
Thanks a lot for the lecture. That ties it. As a former embVB programmer I
imagined True = -1 and False = 0, irrespective of case. I should have
realised that True and False are no Basic4ppc constants like cPI, cE, etc.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font type mozaharul Questions (Windows Mobile) 4 05-18-2009 10:17 AM
Conditional runnig of modules Cableguy Basic4ppc Wishlist 2 10-11-2008 04:30 PM
Cannot type in Device IDE Leginus Bug Reports 3 02-03-2008 04:47 PM
How to get the PDA type and make HARRY Questions (Windows Mobile) 3 01-13-2008 12:19 PM
Another Reason for IntPtr Type Louis Basic4ppc Wishlist 4 10-24-2007 07:17 PM


All times are GMT. The time now is 03:56 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0