|
What a ridiculous question to post in a progamming forum. If yuo don't know how to do calculations try Google, there are loads of pages devoted to all sorts of caluations from simple percentages to complex scientific formulae.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Look, if you have a problem with my post, DONT READ IT. Ive gone through this before on code project. Someone remarked that my post was dumb and shouldnt be here. Guess what? I dont really care whether you approve of my post being here or not. I know that most programmers enjoy writing equations and calculations so I was helping to give a couple of programmers something fun to do. And I do know how to do calculations, Im just not good with percentages. If you dont have something to add to the question I asked, dont post a reply. You are wasting your time trying to criticize people's posts in a forum. It is childish and rude. Dont you have something better to do with your time? Like I said, if you dont like it, DONT READ IT!!!!! That goes for the other guy that criticized my post too, both of you. Grow up and get a life!
On the upside though thank you for your suggestion on using Google. However I already tried searching the web to find a solution and had no luck. THATS WHY I CAME HERE...
|
|
|
|
|
Joey Picerno wrote: Look, if you have a problem with my post, DONT READ IT.
How do I know if I can help if I don't read it?
Joey Picerno wrote: I know that most programmers enjoy writing equations and calculations
I know a lot of programmers enjoy cooking, but I wouldn't ask for a recipe in a programmng forum
Joey Picerno wrote: However I already tried searching the web to find a solution and had no luck. THATS WHY I CAME HERE...
Not very good at Google either then. The top entry of http://www.google.co.uk/search?hl=en&q=how+to+calculate+percentage&meta=[^] tells you in easy to understand terms.
I, like most of the people who actually answer questions on CP and other forums, try and help those less experienced or who have real programming problems. To do this I have to read posts to see if I can help. There are more than enough questions posted where 2 minutes on Google would reveal the solution without people posting what, despite your claims, is nothing to do with programmng.
Finally,
Joey Picerno wrote: Ive gone through this before on code project. Someone remarked that my post was dumb and shouldnt be here
Joey Picerno wrote: That goes for the other guy that criticized my post too
Notice a trend here?
and don't worry, I won't waste my time readng any more of your ramblings.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ashfield wrote: I know a lot of programmers enjoy cooking, but I wouldn't ask for a recipe in a programmng forum
Ashfield wrote: despite your claims, is nothing to do with programmng
So your saying that programmers never use calculations and equations???
Also, if my question had nothing to do about programming how was user "Guffa" able to give me a correct response with an equation that could be utilized in VB???
You arent making any sense and again are being very childish. Just drop it and go do something that is actually productive.
|
|
|
|
|
I have written a document imaging system in VB.Net, using Pegasus tool kit.
We have over 100 client's with no problems. However our latest client is experiencing problems. They have two users and both are having the same problem. The error message is to the affect:
"attempt to read or write to protected memory"
This is occuring after they open and close a scaning window numerous times over the course of 30 minutes.
I made sure that I disposed of all the Pegasus tools (put msgbox()) in the window's dispose method. I don't create any 'fancy' objects, although I do open file streams. But I make sure they are closed, as I do for Sqlconnections and data readers.
I put a garbage collector button in the parent window:
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
MessageBox.Show("Done!" + vbCrLf + _
"Memory Allocated: " + GC.GetTotalMemory(False).ToString, "Garbage Collection")
I can see the memory usage going up everytime I instantiate a new window. What's interesting is that from run to run the amount reported by GetTotalMemory is always different.
Does anyone have any advice as how to approach this? Are there common VB objects that need to be manually disposed of?
Thanks!
|
|
|
|
|
dBrong wrote: I put a garbage collector button in the parent window
You really don't want to do this. Each time you call GC.Collect() you are freezing your applications main thread so the GC can run.
dBrong wrote: Are there common VB objects that need to be manually disposed of?
Any object that you are using that implements the IDisposable interface really should be cleaned up with a call to Dispose() or you should use it inside a using block.
You specifically mention that you are opening streams and database connections, but how are you making sure that they are closed properly? If you aren't using a try/finally or a using block to ensure that the Close() or Dispose() method is being called even if an exception occurs then you aren't guaranteed that the objects will get cleaned up properly. Going beyond streams and database connections, since you are in an document imaging system, any Graphics objects or any image objects (Bitmap , Image , etc.) also should be cleaned up by calling Dispose() .
These same rules apply for the Pegasus objects as well. If they aren't wrapped in a try/finally or a using block there is no guarantee that they are actually being cleaned up properly.
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
|
|
|
|
|
Scott,
Thanks for the response. I have a couple of questions:
I figure that memory usage should always be the same. However each time I start the app, and call GC.GetTotalMemory I get a different value!
Are there any system calls I can make to help me find out what's really happening with memory usage?
Secondly, is there a list of .net objects that explicity need dispose() to be called manually?
I'll wrap the close/dispose in try/catch. I was under the impression that if it failed I'd get a runtime error?
Thanks.
|
|
|
|
|
dBrong wrote: Are there any system calls I can make to help me find out what's really happening with memory usage?
There aren't any system calls you can make that I am aware of. There may be some unmanged Win32 API calls, but I'm not sure. The best option to see what is happening with the GC is to use some of the performance counters that are built in. Check this post[^] on Channel 9 for more information.
dBrong wrote: Secondly, is there a list of .net objects that explicity need dispose() to be called manually?
Unfortunately, there really isn't. The best option is to look at the following things:
- Does the object provide a
Close or Dispose method?
- Does the object inherit from
IDisposable ? You can also look at the MSDN documentation or use Reflector to check as well. The best rule of thumb is that if the object "feels" like it should be disposed of after you're done using it, it probably implements IDisposable .
dBrong wrote: I'll wrap the close/dispose in try/catch. I was under the impression that if it failed I'd get a runtime error?
It all depends on how your objects (or the objects you are using) are implemented. If for some reason a disposable object were to throw an exception that was caught and eaten your calling code may not know about it and/or the call to Dispose may never occur. By putting the call to Dispose inside of a finally or using block you can guarantee that it will get called under all conditions.
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
|
|
|
|
|
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 />
|
|
|
|
|