|
That's probably why it's claiming that one of the dependencies cannot be found; your component references something that's not available (or registered!) on the target-machine.
VB6 isn't interested in what your component uses; but the things that the component uses "should" be available on the target-machine. The .NET runtime will then load them for you.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you Eddy and Marcus Kramer..
Some how i got the result not upto the mark though.
|
|
|
|
|
Again, we're not talking about your VB6 code at all. All we're interested in is the VB.NET code you wrote to write this component.
If you added references in your VB.NET project to other libraries, you MUST copy those libraries over to the target machine at install time for your component. If your component code is using something in a library, how is the code going to work if the item referenced is not on the machine?? It'll throw the very error you're getting, specifically, the part about "or one of its dependencies".
You do NOT need to add any references in your VB6 code, other than the one to your COM component. Those references won't work for your component anyway. You DO need to make sure that everything your component uses is installed on the target machine.
|
|
|
|
|
Let's put things in other words, maybe you'll understand then.
You created a dll in .Net for COM interop, let's give it a name here: MyCOM.dll.
When you created MyCOM.dll, you referenced ThirdParty.dll. That means, MyCOM.dll depends on ThirdParty.dll to be available.
On your machine - where you developed MyCOM.dll - ThirdParty.dll is available.
But on the other machine, it is not.
How to solve: copy ThirdParty.dll into the same directory as MyCOM.dll.
|
|
|
|
|
|
As the subject states I am having some trouble with implementing a delegate to solve this issue that I am having.
The error that I am receiving is that cross-thread operation is not valid. I have windows form that we will call Form1 for example that has many buttons. For one those buttons opens up another form that we will call for this example Form2 that will display some data. Form2 has a COM obj that is similar to a datagridview, but it displays the data which is similar to a pdf viewer that can allowing zooming and formatting. Before I start posting where my problem is in code I did some searches and everyone suggests to use Delegates to prevent the cross-threading problem. I am quite new to delegates so I have been reading the MSDN Documentation[^] about delegates, but I am still not understanding it quite well. Also, I have read this great article A Beginner's Guide to Delegates[^] about 3 times. I understand it's a introduction article.
Here is snippet of code that is causing me problems while I am using delegates (incorrectly???)
Note: This snippet of code is from Form1
Public Delegate Sub StoreDetailedOutputID(ByVal strID As String)
Private strKey1 As String
Private Sub AnalysisResultsEngineName(ByVal strEngineName As String)
frmAnalysis_Results_Form.Set_Engine_Name(strEngineName)
End Sub
Private Sub cmdSpreadSheetOutput_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSpreadSheetOutput.Click
strKey1 = "Please work!"
Dim dEngineName As StoreDetailedOutputID
dEngineName = AddressOf AnalysisResultsEngineName
dEngineName.Invoke(strKey1)
End Sub
With that I have a few additional questions so that I may understand what delegates are all about.
-Where should the delegate be created within my program? Form1? Form2?
-Should the Delegates be created on both forms?
-Should I use BeginInvoke instead of Invoke?
-Is Delegates indeed the correct route to go? Should I use Threading?
Any help to clarify my misunderstanding of delegates would be greatly appreciated.
|
|
|
|
|
A Delegate is a method-pointer, you could look at it as an interface on a method-only-level. That means that it defines a Type , like an Integer , but not for data, but for methods. That means you can store a reference to a method.
When a single-threaded application is executed, it's the UI-thread or the main-thread that builds the controls. A thread executes the instructions in the code one after another. That's why you sometimes see a form go completely white when it is doing a lot of processing; the UI thread is too busy to do the drawing. To prevent that from happening, and have a responsive UI, we do the heavy work on a separate thread.
Clark Kent123 wrote: -Where should the delegate be created within my program? Form1? Form2?
On the place where you intend to call it, you'll need an instance. That instance could be passed using a parameter, as a Delegate is a Type that "acts" as a variable.
Clark Kent123 wrote: -Should the Delegates be created on both forms?
No, but the delegate is often public, so that it's Type can be used in other forms (from where it's called, for instance)
Clark Kent123 wrote: -Should I use BeginInvoke instead of Invoke?
Invoke should execute it on the same thread; that Exception you mention should only occur when you use BeginInvoke , as that creates a new thread. In that case you'll also need the Invoke-pattern[^].
Clark Kent123 wrote: -Is Delegates indeed the correct route to go? Should I use Threading?
You should be able to answer that by yourself now; threading is for heavy tasks, delegates are method-variables. Here's an example that uses both;
Imports System.Windows.Forms
Imports System.Threading
Public Delegate Sub MyCallbackProto(Count As Integer)
Public Class TheThreadClass: Inherits Object
Private mySomeCallbackRoutine As MyCallbackProto
Private myThread As Thread
Public Sub New(aSomeCallback As MyCallbackProto)
mySomeCallbackRoutine = aSomeCallback
myThread = New Thread(AddressOf Work)
myThread.Start
End Sub
Public Sub Work()
For i As Integer = 0 To 100
Thread.Sleep(50)
mySomeCallbackRoutine(i)
Next
Application.Exit
End Sub
End Class
Public Class Form1: Inherits Form
Private myProgressBar As New ProgressBar
Private myThread As TheThreadClass
Public Sub New()
Controls.Add(myProgressBar)
myThread = new TheThreadClass(AddressOf OnUpdate)
End Sub
Sub OnUpdate(Count As Integer)
myProgressBar.Value = Count
End Sub
End Class
Public Class MyApp
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
Another cool intro to delegates is the A Beginner's Guide to Delegates[^] article. There is a series (5 articles I believe) on threads called Beginners Guide to Threading in .NET: Part 1 of n[^].
Enjoy
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I appreciate that answer. Yeah, I do agree that by now I should be able to answer whether threading or Delegates is the way to go. I am going to stick with Delegates and take some time to digest all this information. As well as go reread all those delegate articles.
I am sure later on I will look back and think of how easy it was to set this up.
Thanks again.
|
|
|
|
|
Clark Kent123 wrote: I appreciate that answer.
..which motivates to answer questions. Thanks for the feedback
Clark Kent123 wrote: I do agree that by now I should be able to answer whether threading or Delegates is the way to go.
That depends on how good my explanation was; if it isn't clear, then my explanation wasn't what it should have been. I agree that I kinda buried you under a lot of information.
Threads are for long-running, CPU intensive tasks. Delegates are variables for methods.
Depending on what you are doing to Form2 (from the point of view from Form1), you might need an event, not just a delegate. Let's try it another way;
- Are you trying to "inform" another class that something changed? (event)
- Are you trying to "execute" another method from another class? (delegate)
- Are you trying to "run" something that seems to hang your app? (threads)
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Quote: Depending on what you are doing to Form2 (from the point of view from Form1), you might need an event, not just a delegate. Let's try it another way;
Are you trying to "inform" another class that something changed? (event)
Are you trying to "execute" another method from another class? (delegate)
Are you trying to "run" something that seems to hang your app? (threads)
In all honesty, I am just trying to prevent the error message from popping up. So I was not paying too close attention on what Delegates were, but had the mind set of copy and paste sample code and hope the error goes away.
I think the "informing" the other class that something has changed might be the what I want to do. Upon reading and reflecting (something new this time ) on what delegates can do I think a delegate event might be beneficial in my scenario. I think. It's an experiment I want to try. I stumbled upon this MSDN VB related documentation[^] that lead me to thought of trying the delegate event.
My mind set of programming has been linear that the idea of something asynchronously is foreign to me and it's taking me a while to grasp how to implement it in my app. I get the concept of what it does, but I am not yet there of saying "Oh, this would be a perfect place to make this method async with threads" or "Wait, this needs a delegate". I hope that makes sense.
|
|
|
|
|
Clark Kent123 wrote: In all honesty, I am just trying to prevent the error message from popping up. So I was not paying too close attention on what Delegates were, but had the mind set of copy and paste sample code and hope the error goes away.
I quickly dropped that method of learning, as it becomes frustrating very quickly. Incomplete samples, fishing out the unrelated parts, the "cool" feature you missed because the example used a simpeler overload..
Clark Kent123 wrote: I think the "informing" the other class that something has changed might be the what I want to do.
Hehe, I was afraid that this would be the answer; there's a specialized form to use the delegate, called the event. If your class where to "notify" another class that it has finished loading that huge text-file, you'd typically raise an event (RaiseEvent[^]), something called "OnLoadFinished" or something like that.
Clark Kent123 wrote: I am not yet there of saying "Oh, this would be a perfect place to make this method async with threads" or "Wait, this needs a delegate".
All too well; especially if a technique is still abstract in ones mind, often the case with design-patterns. To make it worse, there are usually multiple ways to achieve something, often with no clear "correct" way, but multiple trade-offs to go either here or there.
Clark Kent123 wrote: My mind set of programming has been linear that the idea of something asynchronously is foreign to me and it's taking me a while to grasp how to implement it in my app.
As a quick rule-o-thumb, anything that takes more than 0.5 second to complete, should be on it's own thread. Loading large pictures, parsing text-files, loading large tables; all of those would be candidates for their own thread (ideally with a progress-indication).
Learning threading, delegates and events all at once is a bit much to dive into. I suggest you pick one of the three and try to create the smallest console-app possible to see it in action. MSDN is your friend here
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hi everyone,
I am trying to find out how to organize some documents I have for work so that my colleagues could use them efficiently.
I thought of creating a table with the documents' names, hyperlinks and the corresponding keywords.
My colleagues should be able to retrieve the right documents by choosing some of those keywords.
In order to do that I thought that the best idea would be to insert some checkboxes representing the keywords in an Excel file on the network, and when you check some of the checkboxes only the documents having those keywords associated would be listed with the hyperlinks to where to be accessed.
Does this sound complicated? The problem is that I studied VBA and other programming languages many years ago in university so my knowledge now kind of equals to "zero". Is there any sample code I could start with or some tutorials on how to do this? Is there an easier way to do this?
I would very much appreciate your opinions.
|
|
|
|
|
My suggestion would strongly depend on the way how you want to store and maintain your list.
Using Excel / VBA, your list may be easy to maintain in Excel itself, but proper coding might be hard – at least from a certain point where you want to make your tool as user friendly as possible (with forms, checkboxes etc.).
Using VB.NET (you're in the VB.NET forum here) you have the free Express Versions to build a perfect solution e.g. with generic lists. The task itself sounds easy, but you have to dive into VB.NET a bit, as there are other basic tasks connected with it (e.g. in which format would you store your data, how would you read them, which controls would you use to present them, how would you present the data to your users, etc).
If you choose to use VB.NET, you might want to download VB.NET Express and read some articles on the net (many of them also have code samples) about
- how to create a form
- how to read/write text or xml files
- how to use generic lists
|
|
|
|
|
That does not sound complicated, but maybe an overview of what VB is all about would be a good start. Here is a link to help you get your zero VB knowledge to something above zero. This way you might think of additional solutions on how to get what you want.
Channel9 MSDN: Visual Basic Development for Absolute Beginners[^]
Let me know if this helps.
|
|
|
|
|
Sounds like a pretty straight forward utility.
How about this:
Store your keywords inside the Excel documents themselves, then you will be able to dynamically determine which docs match your selection crieria.
For example:
1) All docs are stored on "myserver"\"some share"
2) Your utility presents the user with some checkbox selections
3) Open the docs on this share and build a list of docs that match the selection criteria
Check this page out on how to store data in your Excel file properties.
http://www.addintools.com/documents/excel/where-is-document-properties/where-is-document-properties.html[^]
Depending on how manny docs you have, you could build an indexing utility which would scan the folder periodically and build the matrix of keywords and filenames in a single location so that your utility would not have to scan all the docs each time.
Sounds like a cool project.
The folks here are really good about answering questions when you get stuck. There are lots of good code samples available too.
Good luck.
|
|
|
|
|
maybe this function will get you started ...
Imports Microsoft.Office.Interop
Private Function GetExcelComments(ByVal sFname As String) As String
Dim sRetVal As String = ""
Dim ExcelApp As New Excel.Application
Dim ExcelBook As Excel.Workbook
Dim DocProps As Object
ExcelApp.Workbooks.Open(sFname, , True)
ExcelBook = ExcelApp.Workbooks(1)
docprops = ExcelBook.BuiltinDocumentProperties
sRetVal = DocProps("Comments").Value.ToString
ExcelBook.Close(True)
ExcelApp.Quit()
Return sRetVal
End Function
|
|
|
|
|
Tks everyone, I'll take a look at all your answers and will try to find the best solution. I'll come back with more questions surely.
|
|
|
|
|
I have multiple tables to call. So, I need to have a next button that call's the next row data.
Here's my coding:
Try
cmd.Connection = connection
cmd.CommandText = "SELECT tblExpenses.Date, tblExpenses.Allowance, tblExpenses.Total, tblExpenses.Wallet,"
cmd.CommandText += "tblFoodAndBeverage.Breakfast, tblFoodAndBeverage.Lunch, tblFoodAndBeverage.Dinner,"
cmd.CommandText += "tblFoodAndBeverage.Supper, tblFoodAndBeverage.Snack, tblFoodAndBeverage.Beverage,"
cmd.CommandText += "tblFoodAndBeverage.Grocerries, tblFoodAndBeverage.Sub_Total, tblEntertainment.Video_Rental,"
cmd.CommandText += "tblEntertainment.Cinema, tblEntertainment.Concert, tblEntertainment.Sport,"
cmd.CommandText += "tblEntertainment.Games, tblEntertainment.Club_Bar_Disco, tblEntertainment.Others,"
cmd.CommandText += "tblEntertainment.Sub_Total FROM tblExpenses, tblFoodAndBeverage, tblEntertainment WHERE tblExpenses.Food_And_Beverage=tblFoodAndBeverage.Food_And_BeverageID AND tblExpenses.Entertainment=tblEntertainment.EntertainmentID"
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read
DateTimePicker1.Value = dr.Item(0)
txtAllowance.Text = dr.Item(1)
txtTotalUsage.Text = dr.Item(2)
txtWalletCash.Text = dr.Item(3)
txtBreakFeast.Text = dr.Item(4)
txtLunch.Text = dr.Item(5)
txtDinner.Text = dr.Item(6)
txtSupper.Text = dr.Item(7)
txtSnack.Text = dr.Item(8)
txtBeverage.Text = dr.Item(9)
txtGroceries.Text = dr.Item(10)
txtSubFnB.Text = dr.Item(11)
txtVideo.Text = dr.Item(12)
txtCinema.Text = dr.Item(13)
txtConcert.Text = dr.Item(14)
txtSport.Text = dr.Item(15)
txtGames.Text = dr.Item(16)
txtClubBarDisco.Text = dr.Item(17)
txtEntertainmentOthers.Text = dr.Item(18)
txtSubEntertainment.Text = dr.Item(19)
End While
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
|
|
|
|
|
..I think you need to practice on a simpler project.
You're reading "all" records into the textboxes, only showing the latest record. It's overwriting the values for each record in your database.
Read them into a table or a list, and display them from there. No, I'm not writing code today, too damn hot outside - search for a tutorial.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Okay this is my latest working coding with navigation button but with some un-accurate display.
Public Class DailyExpenses
Dim connection As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8, cmd9 As New SqlClient.SqlCommand
Dim da As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim i As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If connection.State <> ConnectionState.Open Then
connection.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PersonalExpenses.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
connection.Open()
End If
Call Fill_Template()
End Sub
#Region "Fill Data"
Sub Fill_Template()
cmd.CommandText = "SELECT Date,Allowance,Total,Wallet FROM tblExpenses"
cmd.Connection = connection
da.SelectCommand = cmd
da.Fill(ds, "tblExpenses")
If (ds.Tables("tblExpenses").Rows.Count > 0) Then
DateTimePicker1.Value = ds.Tables("tblExpenses").Rows(i)(0).ToString
txtAllowance.Text = ds.Tables("tblExpenses").Rows(i)(1).ToString
txtTotalUsage.Text = ds.Tables("tblExpenses").Rows(i)(2).ToString
txtWalletCash.Text = ds.Tables("tblExpenses").Rows(i)(3).ToString
End If
cmd1.CommandText = "SELECT tblFoodAndBeverage.Breakfast,tblFoodAndBeverage.Lunch,tblFoodAndBeverage.Dinner,"
cmd1.CommandText += "tblFoodAndBeverage.Supper,tblFoodAndBeverage.Snack,tblFoodAndBeverage.Beverage,"
cmd1.CommandText += "Grocerries,Sub_Total FROM tblFoodAndBeverage,tblExpenses WHERE tblFoodAndBeverage.Food_And_BeverageID = tblExpenses.Food_And_Beverage"
cmd1.Connection = connection
da.SelectCommand = cmd1
da.Fill(ds, "tblFoodAndBeverage")
If (ds.Tables("tblFoodAndBeverage").Rows.Count > 0) Then
txtBreakFeast.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(0).ToString
txtLunch.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(1).ToString
txtDinner.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(2).ToString
txtSupper.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(3).ToString
txtSnack.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(4).ToString
txtBeverage.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(5).ToString
txtGroceries.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(6).ToString
txtSubFnB.Text = ds.Tables("tblFoodAndBeverage").Rows(i)(7).ToString
End If
End Sub
#End Region
#Region "Data_Fill"
#End Region
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
If (i <= 0) Then
MsgBox("You are already at first position.")
Else
i = 0
Call Fill_Template()
End If
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If (i <= 0) Then
MsgBox("You are already at first position.")
Else
i = i - 1
Call Fill_Template()
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim RowCount, RowCount1 As String
RowCount = ds.Tables("tblExpenses").Rows.Count - 1
RowCount1 = ds.Tables("tblFoodAndBeverage").Rows.Count - 1
If (i = RowCount) And (i = RowCount1) Then
MsgBox("You are already at Last position.")
Else
i = i + 1
Call Fill_Template()
End If
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
Dim RowCount, RowCount1 As String
RowCount = ds.Tables("tblExpenses").Rows.Count - 1
RowCount1 = ds.Tables("tblFoodAndBeverage").Rows.Count - 1
If (i = RowCount) And (i = RowCount1) Then
MsgBox("You are already at Last position.")
Else
i = ds.Tables("tblExpenses").Rows.Count
i = ds.Tables("tblFoodAndBeverage").Rows.Count
Call Fill_Template()
End If
End Sub
End Class
Problem:
1. When I click next it shows the other rows data correctly but (let's say my tblExpenses has 4 rows of data and my tblFoodAndBeverage has 2 rows of data) then when I click next after the 2nd row data the FoodAndBeverage shouldn't display any data because its null after the 2nd row but it displays duplicate data.
2. My table Expenses actually has a column(Food_And_Beverage(int)) that connects to the table FoodAndBeverage(Food_And_BeverageID). My problem is how to retrieve data based on that 2 relationship.
For example:
tblExpenses(Date(18/8/2012)) has also data on Foods but then (19/8/2012) has its own data in its table but the Foods data is null but still displays other data on that date except for food with blank data.
|
|
|
|
|
Good to see a quick learner
garyu87 wrote: 1. When I click next it shows the other rows data correctly but (let's say my tblExpenses has 4 rows of data and my tblFoodAndBeverage has 2 rows of data) then when I click next after the 2nd row data the FoodAndBeverage shouldn't display any data because its null after the 2nd row but it displays duplicate data.
Are the duplicates already in the set when you execute the Sql statement? Might be easily fixed by changing the "SELECT [fieldnames]" to "SELECT DISTINCT [fieldnames]".
garyu87 wrote: 2. My table Expenses actually has a column(Food_And_Beverage(int)) that connects to the table FoodAndBeverage(Food_And_BeverageID). My problem is how to retrieve data based on that 2 relationship.
For example:
tblExpenses(Date(18/8/2012)) has also data on Foods but then (19/8/2012) has its own data in its table but the Foods data is null but still displays other data on that date except for food with blank data.
Might be solved by 1.
I'd suggest creating a routine that fetches a record from a table, based on the primary key- the number you used to connect the tables. That's usually an INT , a BIGINT or a GUID .
public function GetFoodAndBeverageRecord(PrimaryKey As Integer) as List(Of String)
Dim result as New List(Of Object)
ClearTextBoxes()
Using con As New SqlConnection(connectionstring)
Using cmd As con.CreateCommand
cmd.CommandText = File.Load("GetFoodAndBeverageRecord.sql")
con.Open
using rdr = con.ExecuteReader
if rdr.Read()
for i = 0 to rdr.FieldCount -1
result.Add(rdr.GetField(i)
next
end if
end using
end using
end using
End Function
Private Sub ClearTextBoxes()
txtBoxBla.Text = ""
txtBoxBla2.Text = ""
End Sub
I know it's more efficient (resource-wise) to get the data using a single select-statement, but it's a lot easier to separate the tasks. In this case, it would make it easy to fetch the Expenses. It would "contain" the keys that point to the FoodAndBeverage table, and if the user clicks on a row, I merely have to fetch the key, execute abovementioned method with the key as a parameter, and it'd return a FoodAndBeverage-record WHERE the key equals the passed parameter. That same method also makes programming a forward- and back button easy; it fetches the record with the current id, next that gets called is a method to display it.
A better way would be to return a class, and not a list of values; for that you'd need a FoodAndBeverage class, with public properties for each field in the table. Similar to below;
Public Class FoodAndBeverage
Public Property Id As Integer
Public Property FoodName As String
Public Property Cost As Double
End Class
If the method can return one of those, life becomes easier again; .NET has a lot of support for databinding, and you can throw a BindingList(Of whatever class against a DataGridView, and .NET will do the rest
Hope I didn't overload you with information, just keep the momentum.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Okay thanks.....I'll try it out.
|
|
|
|
|
You're welcome
|
|
|
|
|
i am looking for source code to interface with hp impedance tester 4285A to perform the automated sorting system.
Can vb communicate with tester with only handler interface.(centronic connector)
can anyone help pls.
|
|
|
|
|
You will not "find" source code - it is something that has to be written. If you are looking for somebody to do the work for you, this is the wrong place; here we answer questions on implementation-problems, compiler-errors and runtime-exceptions.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|