471,319 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Excel Application close problem -- vb

i opened an excel application using follwing code to load test data to run mstest cases


Public Class ExcelMatrixReader

Public oXL As Excel.Application
Public oWB As Excel.Workbook
Public oSheet As Excel.Worksheet
Public path As String

Public ExValuetoPass As String
Public Exexpected As String

Dim searchmethod As String
Dim scenariokey As String

Dim irow As Integer
Dim icol As Integer


Public Sub New(ByVal s As String)
path = s
End Sub



Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

Catch
Finally
o = Nothing
End Try
End Sub



Public Sub FindScenario(ByVal classname As String, ByVal scenarioke As String)

'Try
oXL = CreateObject("Excel.Application")
'oWB = oXL.Workbooks.Open("C:\source\Source\UnitTests\Int egration\SecureSync\Test_Data\IronMtn.StringFormat ter.Test.Data.xls")
oWB = oXL.Workbooks.Open(path)
oSheet = oWB.Worksheets(classname)
scenariokey = scenarioke
'irow = 3
icol = 1
For irow = 1 To 20
searchmethod = Convert.ToString(oSheet.Cells(irow, icol).Value)


If (searchmethod.Equals(scenariokey)) Then ' if equal return -1

ExValuetoPass = Convert.ToString(oSheet.Cells(irow, icol + 1).Value)
Exexpected = Convert.ToString(oSheet.Cells(irow, icol + 2).Value)
'oXL.Quit()
End If

Next irow
'Catch ex As System.Runtime.InteropServices.COMException


oXL.Quit()



NAR(oSheet)
NAR(oWB)
NAR(oXL)
GC.Collect()

End Sub

End Class


here is the test case in mstest



<TestClass()> Public Class StringFormatterTest

Private Exobj As New TestData.ExcelMatrixReader("C:\source\Source\UnitT ests\Integration\SecureSync\Test_Data\IronMtn.Stri ngFormatter.Test.Data.xls")
Private testContextInstance As TestContext

'''<summary>
'''Gets or sets the test context which provides
'''information about and functionality for the current test run.
'''</summary>
Public Property TestContext() As TestContext
Get
Return testContextInstance
End Get
Set(ByVal value As TestContext)
testContextInstance = value
End Set
End Property




''''<summary>
''''A test for ToUSAPhoneFormat()
''''</summary>
<TestMethod()> _
Public Sub ToUSAPhoneFormatTest()
Dim valueToPass As String
Dim expected As Object
Dim actual As Object
Dim target As StringFormatter

' Scenario 1 : Passing Numbers with characters
exobj.FindScenario("StringFormatter", "ToUSAPhoneFormatTest.Scenario1")
valueToPass = exobj.ExValuetoPass
target = New StringFormatter(valueToPass)
expected = exobj.Exexpected
actual = target.ToUSAPhoneFormat()
Assert.AreEqual(expected, actual, "StringFormatter.ToUSAPhoneFormat() Scenario 1 did not return the expected value.")


'' Scenario 2 : Passing Numbers
exobj.FindScenario("StringFormatter", "ToUSAPhoneFormatTest.Scenario2")
valueToPass = exobj.ExvaluetoPass
target = New StringFormatter(valueToPass)
expected = exobj.Exexpected
actual = target.ToUSAPhoneFormat()
Assert.AreEqual(expected, actual, "StringFormatter.ToUSAPhoneFormat) Scenario 2 did not return the expected value.")

'' Scenario 3 : Passing Numbers and characters , number count less than 10
exobj.FindScenario("StringFormatter", "ToUSAPhoneFormatTest.Scenario3")
valueToPass = exobj.ExvaluetoPass
target = New StringFormatter(valueToPass)
expected = exobj.Exexpected
actual = target.ToUSAPhoneFormat
Assert.AreEqual(expected, actual, "StringFormatter.ToUSAPhoneFormat() Scenario 3 did not return the expected value.")

End Sub




after running the application still the EXCEL.EXE is running in the task manager

can u please help me to overcome this problem
May 15 '07 #1
0 1306

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Lorenzo Melato | last post: by
6 posts views Thread by Matthew Wieder | last post: by
6 posts views Thread by Gunawan | last post: by
9 posts views Thread by Doug Glancy | last post: by
7 posts views Thread by =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.