|
dBrong wrote: is there a list of .net objects that explicity need dispose() to be called manually?
No, absolutely not. Such a list could never be complete, as the framework is growing with each new version, and there are thousands of thrird party libraries that contain objects that needs disposing.
If in doubt, check if the object has a Dispose method. If it does, there is a reason for that. Not every class that implements IDisposable needs disposing, but unless you have determined that it's actually not needed, you should always call the Dispose method if there is one.
Calling the Dispose method will not hurt even if it is not neccessary for that specific object. For example, you can close a SqlConnection object either by calling the Close method or the Dispose method, as the Dispose method makes sure that the Close method has been called. You can also call the Close method first, then the Dispose method, without harm. You can even call the Dispose method more than once on the same object without problems, you will never get an "object already disposed" error if you happen to call Dispose again.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Public Class Employee
Public Name As String = Nothing
Public Age As Integer = 0
End Class
Module Module1
Sub Main()
Dim emp1 As New Employee()
emp1.Name = "Calvin"
emp1.Age = 30
Console.WriteLine("Emp1: " & emp1.Name & ", " & emp1.Age)
Dim emp2 As New Employee()
emp2 = emp1
emp2.Name = "Bob"
emp2.Age = 40
Console.WriteLine("Emp1: " & emp1.Name & ", " & emp1.Age)
Console.WriteLine("Emp2: " & emp2.Name & ", " & emp2.Age)
Dim emp3 As Employee = emp1
emp3.Name = "Bryan"
emp3.Age = 50
Console.WriteLine("Emp1: " & emp1.Name & ", " & emp1.Age)
Console.WriteLine("Emp2: " & emp2.Name & ", " & emp2.Age)
Console.WriteLine("Emp3: " & emp3.Name & ", " & emp3.Age)
Console.Read()
End Sub
End Module
Here are the results when run:
Emp1: Calvin, 30
Emp1: Bob, 40
Emp2: Bob, 40
Emp1: Bryan, 50
Emp2: Bryna, 50
Emp3: Bryan, 50
My question is:
How can I copy Emp1 to Emp2 and then if I change the Emp2 only Emp2 is changed, Not Emp1.
|
|
|
|
|
You can create a Copy function on the Employee class that returns a shallow copy of the object.
Public Function Copy() As Employee
Return CType(Me.MemberwiseClone, Employee)
End Function
then say
Dim emp2 As Employee = emp1.Copy()
I noticed that your example doesn't really gain from having a copy of the object. I'm assuming you have some other case where you don't just override the copied data with new values, because if you just override the old values right away
|
|
|
|
|
The more correct method name would be Clone and potentially implementing the ICloneable interface.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
I did not recommend that interface because it is actually recommended against by Microsoft[^]. The general reason the interface is not recommended is that you do not know if it is a deep or shallow copy (which in this case does not matter), and there are no library functions that really use that interface anyway.
You are right though in suggesting the function name Clone, as it does seem to be more "standard."
|
|
|
|
|
Gideon Engelberth wrote: I did not recommend that interface because it is actually recommended against by Microsoft
You are absolutely correct. I had completely forgotten about this piece of guidance.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
The solution Gideon provided is the best one, although the method should be named Clone not Copy and you should possibly implement the ICloneable interface as well.
[modification: 28-Aug-2008]The ICloneable interface is actually not recommended[^] per the Framework Design Guidelines.[/modification]
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
modified on Thursday, August 28, 2008 11:51 PM
|
|
|
|
|
Thanks guys!
Gideon, yes I will be using it differently. I just used this example to test what happens. However, I still do not understand what is the difference between the following:
Dim emp1 As New Employee()
Dim emp2 as Employee = emp1 ' What is the difference between this
Dim emp2 as New Employee = emp1 ' and this
|
|
|
|
|
CodingYoshi wrote: Dim emp1 As New Employee()
That will declare the reference variable emp1, then it will create a new instance of the Emplyee class and assign it's reference to the variable.
CodingYoshi wrote: Dim emp2 as Employee = emp1
That will declare the reference variable emp2 and assign to it the reference from the varaible emp1. The result is two reference variables that are referencing the same object.
CodingYoshi wrote: Dim emp2 as New Employee = emp1
That doesn't compile at all, does it? You probably mean:
Dim emp2 as New Employee()<br />
emp2 = emp1
That will declare the reference variable emp2, create a new instance of the Employee class and assign it to the variable. Then it will throw away that instance and instead copy the reference from the emp1 variable. The result is two reference variables that are referencing the same object.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Suppose I have an application that takes orders and save them in an Access databse. And after taking each order I need to print a summary of that order. The summary should contain the items, prices, order number... I need to automatically print this summary right after I save the order. Can this be done in VB.net?
I tried to save the orders in a table called Order1 & the summary in a table called Summary. And I retrieved the need information from Summary to a new form. But this form is being only printed at run time, which I want to avoid?
So is there any way to automatically print the summary for each order, right after the order itself?
I am using a VB.Net application with an Access database.
Thank you in advance.
John,
|
|
|
|
|
It is not clear to me what you mean by wanting to avoid printing at run time but...
If you want to print via .NET you will need to work with the PrintDocument class (System.Drawing.Printing namespace). I am certain you can find some articles on this site and/or via an internet google that provide examples of working with the PrintDocument class.
Good luck with your project.
|
|
|
|
|
The only function I found & worked with me was a function that prints a form at run time. Which means to print the desired form I should open the form, and with a button click on that form the pritings is intiated. Otherwise, The print function will print me the background & not te summary of th order I want.
You get my point now? It is kinda complicated actually. I just can't find the correct printing function.
John,
|
|
|
|
|
You can definitely do what you want to do via the PrintDocument class/object when the order is received, as opposed to just using some function that automatically prints a form with a button click sometime after the order. With the PrintDocument class you would programitically do the formatting (output lines, fonts, etc.) and tell the object what printer to use. It is a little complicated but, once again, there are article examples floating around on this site and elsewhere on the web.
|
|
|
|
|
Here's a thought ...
1) Create your report with MS-Acess
2) Create a macro in MS-Access that Opens the report and uses the default view of Print, then quits Access; call it myMacro
3) From the command line you could use this syntax to have the report automatically generated: "msaccess c:\temp\db1.mdb /x myMacro"
The idea is that from your VB.net program, you issue the above command line and have MS-Access do the report for you.
|
|
|
|
|
You may generate html document from the same database, and run javascript for printing this page, this page may blink for a while and also write close window command in javascript.
May this help.
Happy Programming.
|
|
|
|
|
Hi,
Im working with Reporting services. I can create the report, but i want the user to:
get a page where he can input things in textboxes and the report is generated according to that... in vb.net code....
can you please help me with this..any help!
|
|
|
|
|
Here is a stub of code that I used in an application to launch a report from a command button.
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim myReport As New ReportDocument()<br />
Dim rptConnection As IConnectionInfo<br />
<br />
Dim paramFields As New ParameterFields()<br />
Dim paramField As New ParameterField()<br />
Dim discreteVal As New ParameterDiscreteValue()<br />
Dim rangeVal As New ParameterRangeValue()<br />
Dim ActiveEmpDR As TCDataSet.qry_ActiveEmpsRow<br />
Dim i As Integer<br />
<br />
Dim sGlobalDBname As String<br />
'Dim myTableLogOnInfos As TableLogOnInfos<br />
<br />
Me.CrystalReportViewer1.ReportSource = Nothing<br />
<br />
<br />
sGlobalDBname = Mid(My.Settings.dbConnectionString, InStr(My.Settings.dbConnectionString, "Source") + 7)<br />
'Debug.Print("rptPath=" + My.Resources.rptPath)<br />
<br />
myReport.Load(My.Settings.rptPath.ToString + "\rptTime.rpt")<br />
<br />
For Each rptConnection In myReport.DataSourceConnections<br />
rptConnection.SetConnection(sGlobalDBname, sGlobalDBname, False)<br />
Next<br />
'myTableLogOnInfos = Me.CrystalReportViewer1.LogOnInfo()<br />
<br />
'For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos<br />
'myTableLogOnInfo.ConnectionInfo.ServerName = sGlobalDBname<br />
'myTableLogOnInfo.ConnectionInfo.DatabaseName = sGlobalDBname<br />
'Next<br />
<br />
paramField.ParameterFieldName = "LoDate"<br />
discreteVal = New ParameterDiscreteValue()<br />
discreteVal.Value = Me.MonthCalendar1.SelectionStart<br />
<br />
paramField.CurrentValues.Add(discreteVal)<br />
paramFields.Add(paramField)<br />
<br />
paramField = New ParameterField()<br />
paramField.ParameterFieldName = "HiDate"<br />
discreteVal = New ParameterDiscreteValue()<br />
discreteVal.Value = Me.MonthCalendar1.SelectionEnd<br />
paramField.CurrentValues.Add(discreteVal)<br />
paramFields.Add(paramField)<br />
<br />
paramField = New ParameterField()<br />
paramField.ParameterFieldName = "myEmpID"<br />
<br />
If (Me.but_All.Checked) Then<br />
Me.QryActiveEmpsBindingSource.MoveFirst()<br />
For i = 1 To Me.QryActiveEmpsBindingSource.Count<br />
ActiveEmpDR = CType(CType(Me.QryActiveEmpsBindingSource.Current, DataRowView).Row, TCDataSet.qry_ActiveEmpsRow)<br />
' Debug.Print(ActiveEmpDR.EmpID + " " + ActiveEmpDR.Full_Name)<br />
<br />
discreteVal = New ParameterDiscreteValue()<br />
discreteVal.Value = ActiveEmpDR.EmpID.ToString<br />
paramField.CurrentValues.Add(discreteVal)<br />
<br />
Me.QryActiveEmpsBindingSource.MoveNext()<br />
Next<br />
Else<br />
discreteVal = New ParameterDiscreteValue()<br />
discreteVal.Value = Me.ComboBox1.SelectedValue.ToString<br />
paramField.CurrentValues.Add(discreteVal)<br />
End If<br />
'Finalize the EmpID field and all of its values.<br />
paramFields.Add(paramField)<br />
<br />
'myReport.SetParameterValue()<br />
<br />
CrystalReportViewer1.ParameterFieldInfo = paramFields<br />
<br />
<br />
Me.CrystalReportViewer1.ReportSource = myReport<br />
Me.CrystalReportViewer1.Visible = True<br />
<br />
End Sub<br />
|
|
|
|
|
Hi to all,
I need source code for scanning an image in format of bmp or tif from vb.net windows based application directly and possible to perform operation on that image like rotating...
So if anyone knows it then reply me as soon as possible.
Its urgent.
|
|
|
|
|
krinaljariwala wrote: I need source code
This is not a code shop
krinaljariwala wrote: vb.net windows based application directly and possible to perform operation on that image like rotating...
You need to use some library/component which supports the scanning of the documents.
There after, you can easily implement(find examples on Google) for operation like rotatiing, cropping etc...
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
|
Ex: convert from dat to 3gb
|
|
|
|
|
farouk gaber wrote: you have convert porgraming in vb.net2008 ?
farouk gaber wrote: convert from dat to 3gb
Well, there is no inbuilt support ofr that in .Net (or in any other language).
You will need to do this your self or find some already developed component/library which does it.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
What the heck are you asking?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
Once again, I fail to understand the question either because I have left my telepathic head at home, or more likely, you have simply written a load of rubbish.
How do you expect anyone to help if you don't ask a question?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
someone has a working code of this control. I already found some in C but I can't convert them into VB.net
Thanks Jan
PS: I work with 2008
|
|
|
|