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. 5 3992
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****@discuss ions.microsoft. com> wrote in message
news:C0******** *************** ***********@mic rosoft.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.
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(Tr ue)
Dim oMaybe as BooleanValue _
= FunctionThatRet urnsABooleanVal ue()
Dim oAND1 as New ANDGate(oYes, oNo)
Console.Writeli ne(oAND1.Value( ))
HTH,
Phill W.
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(Tr ue) Dim oMaybe as BooleanValue _ = FunctionThatRet urnsABooleanVal ue()
Dim oAND1 as New ANDGate(oYes, oNo)
Console.Writeli ne(oAND1.Value( ))
HTH, Phill W.
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(Tr ue) Dim oMaybe as BooleanValue _ = FunctionThatRet urnsABooleanVal ue()
Dim oAND1 as New ANDGate(oYes, oNo)
Console.Writeli ne(oAND1.Value( ))
HTH, Phill W.
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(Tr ue) Dim oMaybe as BooleanValue _ = FunctionThatRet urnsABooleanVal ue()
Dim oAND1 as New ANDGate(oYes, oNo)
Console.Writeli ne(oAND1.Value( ))
HTH, Phill W. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 # Good!
>>> that is it is not it
|
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 the Gate$ Foundation is no more than
a front to promote and try to claw onto marketshare for windos by lining
the pockets of Third World government bureaucrats all in the name of
helping "children with AIDS".
But, let's pretend that we've been...
|
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 understand best
(i.e. C returns non-zero as true, and zero as false), is there anything
I should be aware of given Python's different approach? Namely any
pitfalls or neat tricks that make the Python approach cool or save my
butt.
Thank you!
|
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 services.
· MABLE utilizes SOAP 1.2 protocol.
· MABLE uses AXIS 1.4 as a web service transport.
· MABLE support state-full conversations by implementing a conversation
session.
|
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 think it
is going to be bigger than Google... Now Bill Gates is on record
saying they have a great business model and that Google should be
worried.
| |
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 think it
is going to be bigger than Google... Now Bill Gates is on record
saying they have a great business model and that Google should be
worried.
|
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 in. My business classes are, of
course, decorated with the:
<System.ComponentModel.DataObject() attribute.
So, I drop a GridView on a webform and set its datasource to an
ObjectDatasource which in turn is using one of my business logic...
|
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 and
always will be!
Thanks for existing! If I could meet you I would give a kiss on your mouth!
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |