# Is it really true? Is it not false?

• (2 Pages)
• 1
• 2

## 17 Replies - 5294 Views - Last Post: 30 June 2012 - 05:46 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=266847&amp;s=675dec2a30d67876e843f79fdd050be7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 vb#

Reputation: 0
• Posts: 6
• Joined: 05-March 12

## Re: Is it really true? Is it not false?

Posted 05 March 2012 - 04:00 AM

GenHornet18, on 17 February 2012 - 12:31 AM, said:

Processing past Mach 2...:
```1	if(seen == true)
2	{engage.afterburners();}
3	else
4	{crashnburn();}

```

I just saw the irony in his signature!!

### #17 MentalFloss

Reputation: 531
• Posts: 1,397
• Joined: 02-September 09

## Re: Is it really true? Is it not false?

Posted 29 June 2012 - 08:12 PM

djkitt, on 20 February 2012 - 03:16 PM, said:

This is the kind of code I encountered when I started in my current position:

```
If a = 0 Then b = 1
If a = 0 Then c = 1
If a = 1 Then b = 2
If a = 1 Then c = 2
If a <> 0 And a <> 1 Then b = 3
If a <> 0 And a <> 1 Then c = 3

```

This kind of code was everywhere and was much lengthier.

The young man that preceded me had just graduated from college, but c'mon...

I had to think about this a bit to get a good idea about what was actually happening here. Anyway, here's my crack at it. You might find it worse.

```' Assuming a VB dialect.

'Ranges of values possible
'	A = 0, 1
'       B = 1, 2, 3
'       C = 1, 3

' Only B and C are set to anything so A can obviously be a boolean value.

// Let's rewrite it now with true and falses (you would have to change the data type of A at this point.

If a = false Then b = 1
If a = false Then c = 1
If a = true Then b = 2
If a = true Then c = 2
If a != true And a != false Then b = 3
If a != false And a != true Then c = 3

// Ok it's pretty clear what's going on now

Enum databaseResult
noResult = 1
result = 2
nullResult = 3
End Enum

Sub Main()
Dim result as databaseResult = databaseResult.nullResult

// Do some kind of database work where you return a boolean field that can have true,false,null and assign it to "a"

If a = false Then result = databaseResult.noResult
If a = true Then result = databaseResult.result
If a != true And a != false Then result = databaseResult.nullResult

End Sub

// But let's just refine that a little bit. Bear in mind I do not know VB. I'm winging it and it most likely isn't accurate but we're removing the mystery.

Sub Main()
Dim result as databaseResult = nullResult

// Do some kind of database work where you return a boolean field that can have true,false,null and assign it to "a"

Select Case a
Case true
result = databaseResult.result
Case false
result = databaseResult.noResult
Case Else
result = databaseResult.nullResult
End Select

End Sub

// Now this might not be what it is for but I at least added context to your code. Now it can be refined even further logically based on its actual operation and purpose.

```

Again, not a VB coder and I am curious what this was for in the first place.

EDIT: Man I cannot figure out how to comment in VB so please just do the best you can with it. Sorry.

EDIT 2: I suppose I assumed this was a business application and if it's not then you'll probably have reason for what you're doing. I would recode it like this if that's the case:

```b = a + 1
If a <> 0 And a <> 1 Then b = 3
c = b

```

It's functionally the same. I just have no idea what it's for.

Example:
a comes in as -1 and 1 is added to it. b = 0 but it doesn't matter because when it's checked on the If statement, b = 3. Then finally c = b so b and c both = 3 as expected.

a comes in as 0 and 1 is added to it. b = 1 and so since a = 0 then b will not equal 3. c then = b and so both equal 1.

a comes in as 1 and 1 is added to it. b = 2 and since a = 1 then b will not equal 3. c then = b and so both equal 2. all expected.

a comes in as 2. 2 is not 0 or 1 so b will equal 3. everything is identical.

sorry for the confusion with my initial pass at this.

This post has been edited by MentalFloss: 29 June 2012 - 08:37 PM

### #18 MentalFloss

Reputation: 531
• Posts: 1,397
• Joined: 02-September 09

## Re: Is it really true? Is it not false?

Posted 30 June 2012 - 05:46 AM

Well Mr. Duckington, you are the first to vote me negative in a long, long time. I would like to know what you found so offensive about my exploratory post. If you have nothing to say, please change your vote. I am serious about this forum and this community. I do not take lightly to troll posts.

EDIT: Oh I'm sorry. My post didn't seem to click.

```b = a + 1
If a <> 0 And a <> 1 Then b = 3
c = b

```

Good enough for you out of context of a business application?

BTW: Forum formatting seems off to me. Review this posts tags and see how it might be corrected.

This post has been edited by MentalFloss: 30 June 2012 - 05:51 AM