2 Replies - 2322 Views - Last Post: 18 October 2009 - 05:18 PM Rate Topic: -----

#1 progvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 29-September 09

How to use dll component in Windows Forms Application

Posted 17 October 2009 - 02:21 PM

Public Class NAND
	Private inputA As Integer
	Private inputB As Integer
	Private outputQ As Integer


	Public Sub New(ByVal inputA As Integer, ByVal inputB As Integer, ByVal outputQ As Integer)
		Me.inputA = inputA
		Me.inputB = inputB
		Me.outputQ = outputQ
	End Sub

	Public Function calcNAND() As Integer
		If inputA = 1 & inputB = 1 Then
			outputQ = 0
		Else
			outputQ = 1
		End If
	End Function
End Class



I have this code and I hope that this is correct. I build a dll component from the class file that contains this code and I am trying to use it as a reference in windows forms application. I have allready made this forms application and added the ddl to the reference but I do not know how to use it in there. I would like to activate (insert value 1) inputA & inputB using checkbox and that the outputQ is displayed in textbox (1 or 0). Do I have to use a vb interface to do this? And how can I use this code as dll component in the forms application?

This post has been edited by progvb: 17 October 2009 - 02:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to use dll component in Windows Forms Application

#2 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: How to use dll component in Windows Forms Application

Posted 18 October 2009 - 05:06 AM

If everything is done correctly as you say,

Imports NAND



You will be able to declare a New instance and have access to the function - calcNAND()

Hope this helps

This post has been edited by dzone41: 18 October 2009 - 05:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: How to use dll component in Windows Forms Application

Posted 18 October 2009 - 05:18 PM

The code isn't correct.

First up:

	Public Function calcNAND() As Integer
		If inputA = 1 & inputB = 1 Then
			outputQ = 0
		Else
			outputQ = 1
		End If
	End Function


This function always returns 0. Either make it a Sub, or make it a function that returns something.

This line isn't doing what you think it is doing because you use the wrong operator:
If inputA = 1 & inputB = 1 Then

& is the String concatenation operator - nothing to do with the Boolean AND.
Reflector (a disasembler) shows that the code does something very weird:
If -((inputA = CDbl(("1" & inputB.ToString))) > False) Then


You should really say:
If (InputA = 1) And (InputB = 1) Then

or, slightly more efficient is:
If (InputA = 1) AndAlso (InputB = 1) Then

(This is more efficient because if InputA is not equal to 1 then it won't bother testing InputB.)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1