|
Hello,
I'm making a program that make use of Excel. In it, I create an Excel application and then make it visible, then perform several operations with it. Up to this point, everything OK.
The problem comes when I try to close the Excel. At first I thougt that, being an object created within my app, the process will be destroyed by the garbage collector. Then I realized that not. I tried to use the ExcelApp.Quit() method, but it doesn't work either.
In conclusion, I find myself with my program closed, but with a residual Excel process within an SVCHOST parent process I can't kill. Things turn to worse when I execute my app several times: I end up with several Excel processes, consuming no less than 8MB of memory each!!!
I invoke the Excel with the following code:
Imports Microsoft.Office.Interop.Excel
...
Private Excel As New Microsoft.Office.Interop.Excel.Application() ' el Excel
What can I do? Any help will be welcomed!
Thanks in advance,
Juan Pedro Pérez
|
|
|
|
|
Give this a try when you are done using Excel:
' Release Application object:
If Not oExcel.UserControl Then oExcel.UserControl = True
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
'Release worksheet:
If Not oWorkSheet Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkSheet)
oWorkSheet = Nothing
End If
'Release workbook:
If Not oWorkBook Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkBook)
oWorkBook = Nothing
End If
oExcel = Nothing
oExcel is your Excel application object.
oWorksheet is your Excel worksheet object if you have one instantiated.
oWorkbook is your Excel workbook object if you have one instantiated.
Dean
|
|
|
|
|
Thanks Dean, I'll try this and I'll tell you how it works.
Juan Pedro Pérez
|
|
|
|
|
Hai,
I am facing the following problem when I am doing with my vb project,
In my program I need to copy files from Server to client. If client is not having sufficient privilages, then it should prompt for admin account and copy it in admin account.
When I try to copy a file through user account insufficient privilage message ,I got.
Through net ,I found that we can do it using 'Run as' command.
But i don't have clear idea to use it in VB.
Can anybody help me to show the right way to do this?
Thanks very much in advance.
Thank You,
rahul.p.menon
|
|
|
|
|
I've developed a website thro' and i'd like to see the suggestions of the users.
For that purpose i'd like to get the feedback from the users once they fill in the form.
The feedback must be sent to my email id automatically from the filled in information
when i tried i got the following error.................................
----------------------------------------------------------
the code goes like this
----------------------------------------------------------
Dim myMailServer As SmtpMail
myMessage.BodyFormat = MailFormat.Text
myMessage.Priority = MailPriority.High
myMessage.From = "xyz@urdomain.com" 'From Address
myMessage.To = "mymailid@mydomain.com" 'To Address
myMessage.Subject = "hi"
myMessage.Body = "hello"
myMailServer.SmtpServer = "smtp.net4india.com"
'This is my mail server
myMailServer.Send(myMessage)
myMessage = Nothing
----------------------------------------------------------
error msg is like this
----------------------------------------------------------
The transport failed to connect to the server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.
Source Error:
Line 103: myMailServer.SmtpServer = "smtp.net4india.com" 'This is my mail server '
Line 104: myMailServer.Send(myMessage)
|
|
|
|
|
The SmtpServer property and Send method are static. Don't use a reference.
SmtpMail.SmtpServer = "smtp.net4india.com"<br />
SmtpMail.Send(myMessage)
---
b { font-weight: normal; }
|
|
|
|
|
You have not created the object myMailServer . You have just declared it
Divya Rathi
|
|
|
|
|
! Hello everyone,
I need help.
I want to get the filestream or memorystream from Image Object.
Dim img As Image
Dim path As String = "temp"
Dim fs As IO.FileStream
Dim br As IO.BinaryReader
Dim bytes() As Byte
Dim sqlImg As SqlTypes.SqlBinary
Try
img = picPhoto.Image
img.Save(path)
fs = New IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read)
br = New IO.BinaryReader(fs)
bytes = br.ReadBytes(fs.Length)
sqlImg = New SqlTypes.SqlBinary(bytes)
SQL_Parameter(i).Value = sqlImg
'Save Image to Sql Database
Catch ex As Exception
Throw ex
Finally
If Not br Is Nothing Then
br.Close()
br=Nothing
End If
If Not fs Is Nothing Then
fs.Close()
fs = Nothing
End If
bytes = Nothing
img.Dispose()
sqlImg = Nothing
End Try
'It is working but sometime throw the error
' A generic error occurred in GDI+
'Thanks.
!alien!
|
|
|
|
|
Try using Save method.
Nibu thomas
Software Developer
|
|
|
|
|
This code will convert any imageformat to a MemoryStream.
<br />
Imports System.Drawing.Imaging<br />
Imports System.IO<br />
<br />
Public Class Form1<br />
<br />
Public JpegStream As MemoryStream<br />
Public myImageCodecInfo As ImageCodecInfo = GetEncoderInfo("image/jpeg")<br />
Public myEncoder As Encoder<br />
Public myEncoderParameter As EncoderParameter<br />
Public myEncoderParameters As EncoderParameters<br />
<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
Dim filename As String = "C:\test.jpg"<br />
Dim Bmp = New Bitmap(filename)<br />
JpegStream = Nothing<br />
JpegStream = New MemoryStream<br />
<br />
Bmp.Save(JpegStream, myImageCodecInfo, myEncoderParameters)<br />
' Image is now in MemoryStream<br />
End Sub<br />
<br />
Private Function GetEncoderInfo(ByVal MYmimeType As String) As ImageCodecInfo<br />
Dim i As Integer<br />
Dim encoders As System.Drawing.Imaging.ImageCodecInfo() = Imaging.ImageCodecInfo.GetImageEncoders()<br />
For i = 0 To (encoders.Length - 1)<br />
If (encoders(i).MimeType = MYmimeType) Then<br />
GetEncoderInfo = encoders(i)<br />
End If<br />
Next i<br />
End Function<br />
<br />
End Class<br />
<br />
Remember to close all objects when done.
Programming is like Mathematics… you take ONE step at the time!
-- modified at 12:11 Friday 24th February, 2006
|
|
|
|
|
Thanks you for your reply.
!alien!
|
|
|
|
|
your welcome!
Programming is like Mathematics… you take ONE step at the time!
|
|
|
|
|
i m working on vb.net project it is runing nice if i run it on my machine. if i copy its exe in another machine it show problem in another machine . i m using mxflexgrid component of vb and excel refrence it show error in these parts and if i run it on both machine in same time then it show problem related to sql server database.
please helpn me
for sql server it show error-the maximum simultaneous user count of 1 license for this standard edition server has been exccedd.
additonal licenses should be obtained and isstalled or u should upgrade to full version
and for mshflexgrid and excel ref it show---
for assembly name axinterop mshflexgridlib or one of its dependencies was not found
vivek
|
|
|
|
|
Well your English is quite poor so I don’t understand all you said.
For the “mshflexgrid« problem: you do not have the required assemblies on that computer.
And if I understood you right for the SQL server part: your version only supports one connection at a time (as the error message says) and so you can’t be connected more times than that.
You should really read the messages as they are quite helpful.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hi all,
Im Working with Excel Macro facility.
i need to write some text in notepad.how can i open a notepad from vba..
(in VBA we can add commondialog control box and open a notepad.. i need some other way)
Help ME
Thanks n Regards,
Ramya.R
-- modified at 4:04 Friday 24th February, 2006
|
|
|
|
|
/*The following code Opens notepad when a key is pressed . When the up key is pressed , notepad will open */
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim keyPress As Double
If KeyCode = vbKeyUp Then
keyPress = Shell("notepad.exe", vbNormalFocus)
End If
End Sub
Divya Rathi
|
|
|
|
|
Thanks Divya,
I use VBA in Macro level..still no forms are used...
by using shell("notepad.exe") command i open the Note pad..
I need to append the data to that opened Notepad and save that file...
Help me Please..
Thanks in advance....
Thanks n Regards,
Ramya.R
-- modified at 4:10 Friday 24th February, 2006
|
|
|
|
|
this shd be useful
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office09072000.asp
|
|
|
|
|
why do u explictly need to create notepad ? coz if u want to save data from some text box then there are many file handling operations are there.
Divya Rathi
|
|
|
|
|
I make a application with a numbers of forms,
When I open the application in client computer,
I found some of them chnage their screen to higher DPI.
This affect my application label become a larger font.
Beside, A client change its window font,
It doesn't matter that I have setted the form face and the font size,
the whole view of my form style is totally changed.
So, does any method to handle these case?
Thank you!
|
|
|
|
|
It appears it is time once again to show my stupidity. I hope as i only got .net a few days ago i can be forgiven... I'm still converting my brain over from VB6.
1. I am attempting to find the .net equivalent of VB6's "Open ("C:\Text.txt") as input"... statment... basically just generic loading and saving of text and variables... if you want to give examples, lets just deem the file path as the C:\text.txt file. it getts easier than "INSERT PATH" or the like. I have found many examples in my research, but they tended to be variations, so im not sure whats what.. i really just want a simple explination with a breakdown of the parts and their functions.
2. I need to figure out how to bind Database fields to textboxes in .net.. there used to be a property for it, but that is no longer on the list. I have Office XP (2002) and intend to use access. I also have a guide that shows me how to convert access to SQL files, but thats another matter.
Any help would be much appreciated... and please think no less of me. lol The only bad thing from converting over is feeling like im back in 8th grade... (when i learnt VB6)...
"Love, Life and Option Explicit"
|
|
|
|
|
You can access files via the System.IO.File class.
Here's a quick example on how to read a text file.
Dim sr As System.IO.StreamReader
Dim text As String = String.Empty
Try
sr = System.IO.File.OpenText("c:\text.txt")
text = sr.ReadToEnd()
Catch
Finally
If (Not (sr Is Nothing)) Then sr.Close()
End Try
And right, the standard TextBox doesn't take a DataSource. You'll either have to push your database info into it yourself or use a different control.
|
|
|
|
|
just so i understand:
Dim sr As System.IO.StreamReader sets the variable sr as a file that is read.
Dim text As String = String.Empty sets the text variable to blank.
Try I assume is like a VB6 loop.
sr = System.IO.File.OpenText("c:\text.txt") reads the file.
text = sr.ReadToEnd()CatchFinally inputs the file into the variable... not sure on the CatchFinally...
If (Not (sr Is Nothing)) Then sr.Close() if the file is blank, stop.
End Try again assume is like ExitDo...
i'll look up the Try sequence.. will probably make more sense then.. i think i am getting it now... as for the Databaseing, anyone know a simple tutorial page for setting up a DB... basically i want to set up when i load the DB, it loads the information into variables. I then will use these variables for textboxes, and some sub-manipulation. (Gold + Income - Expenses)
"Love, Life and Option Explicit"
|
|
|
|
|
ThePmanLives wrote: Dim sr As System.IO.StreamReader sets the variable sr as a file that is read.
It declares a StreamReader reference variable. It has not been assigned a StreamReader object yet. So at first, it references "Nothing".
Files are read in streams. Think of a stream as an array of bytes, which could come from memory, the hard disk, floppy disk, etc.
ThePmanLives wrote: Dim text As String = String.Empty sets the text variable to blank.
Yes. It creates a string variable and immediately assigns it to a string object having no characters. "Empty" is a Shared (static in C#) property which returns a predefined empty string object.
ThePmanLives wrote: Try I assume is like a VB6 loop.
No. Keywords "Try", "Catch", and "End Try" are used together in exception handling. Any exception thrown in a Try block will get caught in the Catch block. Such as a FileNotFoundException. You should always use exception handling when working with files, because they're more likely to occur there.
The closest thing to this in VB6 is the "On Error GoTo" statement. In VB.NET, Microsoft decided to implement exception handling the same way it is done in C++, C#, and Java.
ThePmanLives wrote: sr = System.IO.File.OpenText("c:\text.txt") reads the file.
text = sr.ReadToEnd() outputs the file into the variable
Yes. Pretty easy eh?
|
|
|
|
|
Okey. makes a LOT more sense now. thanks... 1 last question though. what does the:
Finally
If (Not (sr Is Nothing)) Then sr.Close()
line do? Is it part of the try/catch? or is it just closeing the file afterward? (the main thing is the "finally". never seen that in vb6, so it must be new)
"Love, Life and Option Explicit"
|
|
|
|