Solved

Boolean Logic using VB functions

Posted on 2004-04-21
8
457 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:junebrady
8 Comments
 
LVL 5

Expert Comment

by:ennixo
ID: 10877259
you must define variables' types


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
0
 
LVL 6

Expert Comment

by:PhilAI
ID: 10877425
Or use the CBool function to convert each variable to Boolean
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 10877458
>> Please note also that the variables A,B,C,D,E,F,H all represent smaller formula's

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!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 76

Expert Comment

by:David Lee
ID: 10877483
I don't think you HAVE to define the variables types, although it certainly makes sense to do so.  Consider the online help text for the Boolean data type:

----

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.
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10890787
I think that the author meant something different.

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 ?
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11447807
PAQed - no points refunded (of 125)

Netminder
Site Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA loop through headers using value 3 57
VBA: Add rows to listbox based on criteria 7 73
Opening Remote & Local Data Connection 2 51
Saving history changes to sub form 4 36
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 members asked questions and received personalized solutions in the past 7 days.

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now