473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

logic gates in VB.NET 2005

I just recently got VB.NET 2005 Express Edition. How do I represent logic
gates (AND, OR, NOT, etc.) in VB? I considered a function because functions
return a value. For example, a 2-input AND gate function would have 2 input
parameters & 1 output. But suppose that I want to build a "circuit" using
different gates. I can't have a bunch of functions representing an AND gate.
I don't want to have to create a separate function every time I need another
AND gate. I considered a logic gate object. I can have more than 1 instance
of an AND object running at the same time, can't I? Can objects be linked
together? In other words, can the output of 1 AND object be used as the input
to another AND object? Can these logic gate objects be dynamic? In other
words, can I use the logic gate objects to create different "circuits"
instead of being "hardwired"? Thank you.
May 20 '06 #1
5 3970
You don't need to have multiple objects or functions to accomplish what you
want, I don't think.

For example:

Function AndGate (in1 as object, in2 as object) as object
AndGate = in1 ANd in2
end function

Function OrGate (in1 as object, in2 as object) as object
OrGate = in1 OR in2
end function

Dim Ans as object = AndGate(OrGate(AndGate(In1, In2), OrGate(In3, In4)),
OrGate(In5, AndGate(In6, In7)))
Tom
"pcnerd" <pc****@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I just recently got VB.NET 2005 Express Edition. How do I represent logic
gates (AND, OR, NOT, etc.) in VB? I considered a function because
functions
return a value. For example, a 2-input AND gate function would have 2
input
parameters & 1 output. But suppose that I want to build a "circuit" using
different gates. I can't have a bunch of functions representing an AND
gate.
I don't want to have to create a separate function every time I need
another
AND gate. I considered a logic gate object. I can have more than 1
instance
of an AND object running at the same time, can't I? Can objects be linked
together? In other words, can the output of 1 AND object be used as the
input
to another AND object? Can these logic gate objects be dynamic? In other
words, can I use the logic gate objects to create different "circuits"
instead of being "hardwired"? Thank you.

May 20 '06 #2
pcnerd wrote:
In other words, can I use the logic gate objects to create different
"circuits" instead of being "hardwired"?


Yes, but you need to think about how you're going to be able to "plug"
different things (i.e. Gates and Values) together.

For example, an AND Gate takes two inputs, but these might be two simple
Values or two other Gates or a mixture. So you have to be able to treat
a Value and a Gate in "the same" way.

Here's one suggestion:

Interface IBool
' Any IBool object has a Value
Function Value as Boolean
End Interface

Class BooleanValue
Implements IBool

Public Sub New(ByVal bValue as Boolean)
m_bValue = bValue
End Sub

' The "Value" is simply the value we created it with
Public Function Value() As Boolean _
Implements IBool.Value

Return m_bValue
End Property

Private m_bValue As Boolean = False

End Class
Class ANDGate
Implements IBool

Public Sub New(
ByVal oValue1 as IBool _
, ByVal oValue2 as IBool _
)
m_oValue1 = oValue1
m_oValue2 = oValue2
End Sub

' The "Value" is calculated from the Value functions
' on each object (operand)
Public Function Value() As Boolean _
Implements IBool.Value

Return m_oValue1.Value And m_oValue2.Value
End Property

Private m_oValue1 As IBool = Nothing
Private m_oValue2 As IBool = Nothing

End Class

So then you can set up "circuits" like this:

Dim oYes as New BooleanValue(True)
Dim oMaybe as BooleanValue _
= FunctionThatReturnsABooleanValue()

Dim oAND1 as New ANDGate(oYes, oNo)

Console.Writeline(oAND1.Value())

HTH,
Phill W.
May 22 '06 #3

HUH???
Thanks for the info, but that's all Greek to me. I'm a VB.NET beginner. My
philosophy is KISS - Keep it simple, stupid. What is IBool? I hope that I can
come up with a simpler solution, like maybe a truth table array of type
Boolean. Since we're on the subject of objects - can there be more than one
object of the same name? If so, how does VB keep track of them & distinguish
one from the other? Thank you.
"Phill W." wrote:
pcnerd wrote:
In other words, can I use the logic gate objects to create different
"circuits" instead of being "hardwired"?


Yes, but you need to think about how you're going to be able to "plug"
different things (i.e. Gates and Values) together.

For example, an AND Gate takes two inputs, but these might be two simple
Values or two other Gates or a mixture. So you have to be able to treat
a Value and a Gate in "the same" way.

Here's one suggestion:

Interface IBool
' Any IBool object has a Value
Function Value as Boolean
End Interface

Class BooleanValue
Implements IBool

Public Sub New(ByVal bValue as Boolean)
m_bValue = bValue
End Sub

' The "Value" is simply the value we created it with
Public Function Value() As Boolean _
Implements IBool.Value

Return m_bValue
End Property

Private m_bValue As Boolean = False

End Class
Class ANDGate
Implements IBool

Public Sub New(
ByVal oValue1 as IBool _
, ByVal oValue2 as IBool _
)
m_oValue1 = oValue1
m_oValue2 = oValue2
End Sub

' The "Value" is calculated from the Value functions
' on each object (operand)
Public Function Value() As Boolean _
Implements IBool.Value

Return m_oValue1.Value And m_oValue2.Value
End Property

Private m_oValue1 As IBool = Nothing
Private m_oValue2 As IBool = Nothing

End Class

So then you can set up "circuits" like this:

Dim oYes as New BooleanValue(True)
Dim oMaybe as BooleanValue _
= FunctionThatReturnsABooleanValue()

Dim oAND1 as New ANDGate(oYes, oNo)

Console.Writeline(oAND1.Value())

HTH,
Phill W.

Jun 3 '06 #4
pcnerd wrote:
HUH???
Thanks for the info, but that's all Greek to me. I'm a VB.NET beginner. My
philosophy is KISS - Keep it simple, stupid.
And trying to get to grips with .Net? You /do/ like a challenge, don't
you ;-)
What is IBool?
IBool is an Interface that I've defined. You'll hear people talk about
an Interface being a "contract" between two separate bits of code.
In this case I've defined an Interface that, no matter what Object I
find it in, will always be able to give me a "Value" of type Boolean.
I hope that I can come up with a simpler solution, like maybe a truth table
array of type Boolean.
That /really/ depends what you're trying to achieve.

OK, so you set up a Truth Table, but then how do you use it?
As I recall, you asked for "logic gate /objects/" from which you could
construct "different circuits". Paste the code into a console
application and try it; take a little time to read around the code (in
MSDN) and see if(?) it makes any more sense after that.
Since we're on the subject of objects - can there be more than one
object of the same name?
Can you have two classes with the same name (in the same Namespace)?
No.

Public Class AndGate
End Class
Public Class AndGate
End Class

Can you have more than one instance of an object that has a particular
name?
Oh Yes.

Dim x As New BooleanValue( True )
Dim y As New BooleanValue( False )

x and y are both BooleanValue objects, but are totally separate from one
another.
If so, how does VB keep track of them & distinguish one from the other?
Beats me - it just does. ;-)
Seriously, I could go off rattling on about Pointers (oops!) and memory
allocation and Garbage Collection and all sorts of other wierd stuff;
but not today - it can and it does.

HTH,
Phill W.

Thank you. "Phill W." wrote:
pcnerd wrote:
In other words, can I use the logic gate objects to create different
"circuits" instead of being "hardwired"?

Yes, but you need to think about how you're going to be able to "plug"
different things (i.e. Gates and Values) together.

For example, an AND Gate takes two inputs, but these might be two simple
Values or two other Gates or a mixture. So you have to be able to treat
a Value and a Gate in "the same" way.

Here's one suggestion:

Interface IBool
' Any IBool object has a Value
Function Value as Boolean
End Interface

Class BooleanValue
Implements IBool

Public Sub New(ByVal bValue as Boolean)
m_bValue = bValue
End Sub

' The "Value" is simply the value we created it with
Public Function Value() As Boolean _
Implements IBool.Value

Return m_bValue
End Property

Private m_bValue As Boolean = False

End Class
Class ANDGate
Implements IBool

Public Sub New(
ByVal oValue1 as IBool _
, ByVal oValue2 as IBool _
)
m_oValue1 = oValue1
m_oValue2 = oValue2
End Sub

' The "Value" is calculated from the Value functions
' on each object (operand)
Public Function Value() As Boolean _
Implements IBool.Value

Return m_oValue1.Value And m_oValue2.Value
End Property

Private m_oValue1 As IBool = Nothing
Private m_oValue2 As IBool = Nothing

End Class

So then you can set up "circuits" like this:

Dim oYes as New BooleanValue(True)
Dim oMaybe as BooleanValue _
= FunctionThatReturnsABooleanValue()

Dim oAND1 as New ANDGate(oYes, oNo)

Console.Writeline(oAND1.Value())

HTH,
Phill W.

Jun 5 '06 #5

One of my questions was :
Since we're on the subject of objects - can there be more than one
object of the same name?

Your reply was: Can you have more than one instance of an object that has a particular
name?
Oh Yes.

Dim x As New BooleanValue( True )
Dim y As New BooleanValue( False )

x and y are both BooleanValue objects, but are totally separate from one
another.
Variables x & y don't have the same name. I thought about it after I sent
the e-mail. So, I answered my own question. It's not possible to have 2
variables of the same name. VB would be confused. As far as I know, there
cannot be 2 of anything with the same name - variable, object, etc. VB would
be confused & not be able to distinguish one from the other.

Maybe, an array of Structures. Each Structure would be a different gate -
AND, OR, NOT, NAND, XOR. I don't know how to implement logic gates in
VB.NET. But your suggestion is confusing to me. I hope that there is a simple
solution. I'll have to keep on looking. Maybe, I'll find the answer on the
'net. Thank you.

"Phill W." wrote:
pcnerd wrote:
HUH???
Thanks for the info, but that's all Greek to me. I'm a VB.NET beginner. My
philosophy is KISS - Keep it simple, stupid.


And trying to get to grips with .Net? You /do/ like a challenge, don't
you ;-)
What is IBool?


IBool is an Interface that I've defined. You'll hear people talk about
an Interface being a "contract" between two separate bits of code.
In this case I've defined an Interface that, no matter what Object I
find it in, will always be able to give me a "Value" of type Boolean.
I hope that I can come up with a simpler solution, like maybe a truth table
> array of type Boolean.


That /really/ depends what you're trying to achieve.

OK, so you set up a Truth Table, but then how do you use it?
As I recall, you asked for "logic gate /objects/" from which you could
construct "different circuits". Paste the code into a console
application and try it; take a little time to read around the code (in
MSDN) and see if(?) it makes any more sense after that.
Since we're on the subject of objects - can there be more than one
object of the same name?


Can you have two classes with the same name (in the same Namespace)?
No.

Public Class AndGate
End Class
Public Class AndGate
End Class

Can you have more than one instance of an object that has a particular
name?
Oh Yes.

Dim x As New BooleanValue( True )
Dim y As New BooleanValue( False )

x and y are both BooleanValue objects, but are totally separate from one
another.
If so, how does VB keep track of them & distinguish one from the other?


Beats me - it just does. ;-)
Seriously, I could go off rattling on about Pointers (oops!) and memory
allocation and Garbage Collection and all sorts of other wierd stuff;
but not today - it can and it does.

HTH,
Phill W.

Thank you.
"Phill W." wrote:
pcnerd wrote:
In other words, can I use the logic gate objects to create different
"circuits" instead of being "hardwired"?
Yes, but you need to think about how you're going to be able to "plug"
different things (i.e. Gates and Values) together.

For example, an AND Gate takes two inputs, but these might be two simple
Values or two other Gates or a mixture. So you have to be able to treat
a Value and a Gate in "the same" way.

Here's one suggestion:

Interface IBool
' Any IBool object has a Value
Function Value as Boolean
End Interface

Class BooleanValue
Implements IBool

Public Sub New(ByVal bValue as Boolean)
m_bValue = bValue
End Sub

' The "Value" is simply the value we created it with
Public Function Value() As Boolean _
Implements IBool.Value

Return m_bValue
End Property

Private m_bValue As Boolean = False

End Class
Class ANDGate
Implements IBool

Public Sub New(
ByVal oValue1 as IBool _
, ByVal oValue2 as IBool _
)
m_oValue1 = oValue1
m_oValue2 = oValue2
End Sub

' The "Value" is calculated from the Value functions
' on each object (operand)
Public Function Value() As Boolean _
Implements IBool.Value

Return m_oValue1.Value And m_oValue2.Value
End Property

Private m_oValue1 As IBool = Nothing
Private m_oValue2 As IBool = Nothing

End Class

So then you can set up "circuits" like this:

Dim oYes as New BooleanValue(True)
Dim oMaybe as BooleanValue _
= FunctionThatReturnsABooleanValue()

Dim oAND1 as New ANDGate(oYes, oNo)

Console.Writeline(oAND1.Value())

HTH,
Phill W.

Jun 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: F. Petitjean | last post by:
I want to know if iter(iterator) returns always its argument (when argument is an iterator) So : >>> iterable = range(10) >>> it = iter(iterable) >>> that = iter(it) >>> that is it True #...
6
by: Zip Code | last post by:
"The large print giveth, and the small print taketh away.", so said Tom Waites in his classic rap, "Step Right Up", a paean about come ons and rip offs. Now, we have all explored the fact that...
22
by: James H. | last post by:
Greetings! I'm new to Python and am struggling a little with "and" and "or" logic in Python. Since Python always ends up returning a value and this is a little different from C, the language I...
0
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web...
2
by: alex | last post by:
Hello Friends, Please go through the text. Bill Gates thinks Google should be worried! ------------------------------------------- You must have heard by now about Agloco and how many people...
4
by: alex | last post by:
Hello Friends, Please go through the text. Bill Gates thinks Google should be worried! ------------------------------------------- You must have heard by now about Agloco and how many people...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
6
by: Paulo | last post by:
Hi Bill Gates and all your team, I love you man... I hope you can read this! Im doing beautiful things with asp.net 2.0... I love your company and your products... MS is the best of the world...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.