The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Solved

Posted on 2004-04-21

I need to get visual basic to do boolean algebra so it can act like a combinational logic circuit.

I programmed it to give an output with a boolean equation but it has been returning decimal values. Why is this? This is the code I used :

Gout = ((NOT B) OR ((NOT A) AND (NOT D)) OR ((NOT A) AND (NOT C) AND (NOT F)) OR ((NOT A) AND (NOT C) AND (NOT E) AND (NOT H))

Please note also that the variables A,B,C,D,E,F,H all represent smaller formula's. These formula's use binary inputs from text boxes. The smaller formula's are all written before the Gout output in the program.

Can you please help me with this its very urgent.

I programmed it to give an output with a boolean equation but it has been returning decimal values. Why is this? This is the code I used :

Gout = ((NOT B) OR ((NOT A) AND (NOT D)) OR ((NOT A) AND (NOT C) AND (NOT F)) OR ((NOT A) AND (NOT C) AND (NOT E) AND (NOT H))

Please note also that the variables A,B,C,D,E,F,H all represent smaller formula's. These formula's use binary inputs from text boxes. The smaller formula's are all written before the Gout output in the program.

Can you please help me with this its very urgent.

6 Comments

Dim A As Boolean, B As Boolean, C As Boolean, D As Boolean, E As Boolean, F As Boolean, H As Boolean, Gout As Boolean

Your formulaes must return Boolean values. For testing purpose do this.

MsgBox A

MsgBox B

MsgBox C

MsgBox D

MsgBox E

MsgBox F

MsgBox G

MsgBox H

If any of them display any values other than a "True" or a "False", then you know where to check!

----

Boolean variables are stored as 16-bit (2-byte) numbers, but they can only be True or False. Boolean variables display as either True or False (when Print is used) or #TRUE# or #FALSE# (when Write # is used). Use thekeywords True and False to assign one of the two states to Boolean variables.

When other numeric types are converted to Boolean values, 0 becomes False and all other values become True. When Boolean values are converted to other data types, False becomes 0 and True becomes -1.

----

If the values coming back are 0 and/or -1, then you are getting the numeric representation of a True/False result. If the values are something other than 0 and -1, then as the help text states "all other values become true". Declaring the variables as type Boolean will make interpreting the results easier and will preclude a varibale from having a value other than true or false, but it's not absolutely essential so long as you understand the rules the system uses to determine true and false values in non-Boolean data.

Suggestion:

These variables A,B,C,D,E,F,G and H are 8 bit numbers from 0 to 255.

So he want to make some bitwise operations like AND:

01110100

AND

00110010

________

00110000

This is "boolean algebra" for me.

junebrady: How many states (different values) your variables from A to H can have ? Is your A-H variables can contain only 0 and 1 (1 bit) or they can contain 8 bit values ?

"I programmed it to give an output with a boolean equation but it has been returning decimal values. Why is this" - Because these AND , NOT , OR operates over bits in bytes. So as above AND example, this is equivalent to

116 (Decimal)

AND

50 (Decimal)

______________

48 (Decimal)

For example try this:

MsgBox 116 And 50 ' Returns 48 as above

MsgBox 255 And 47 ' Returns 47

MsgBox 1 Or 2 ' Returns 3

MsgBox 1 Or 3 ' Returns 3

MsgBox 2 Or 3 ' Returns 3

MsgBox Not 255 ' Returns 0

You can "feel" boolean algebra logic in last 4 MsgBox examples.

Is that you need ?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code.
This l…

- Microsoft Office
- Office 365
- Microsoft Access
- VBA
- Microsoft Excel
- Visual Basic Classic

Course of the Month10 days, 18 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.