|
-
Apr 11th, 2007, 04:56 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Exception from HRESULT: 0x800A03EC ???
Hey Guys!
I have written a code (shown below). It is supposed to determine the dimension (in pixels) of .bmp files from an input folder and write these dimensions in an existing excel file alongside its filename.
The code seems to work fine when the number of .bmp files in the folder is small (around 20) but the ones i need to use have ard 260 files. In such cases after a while.. this error comes up.
COMException was unhandled
Exception from HRESULT: 0x800A03EC
This error is shown on the line:
oSheet.Range(Destination).Value = (ReqdWidth)
Code:
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
Public Class SelectFolders
Private Sub SelectFolders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DirPath, TempFilePath As String
Dim file_name() As String = {}
Dim i As Long = 0
Dim x As Integer = 0
Dim ReqdWidth As Long
Dim result, fullpath, tempaddress As String
Dim dimension As Size
Dim oExcel As New Object
Dim oBook As Object
Dim oSheet As Object
Dim c
Dim RowAddress As String
Dim Destination As String
If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
DirPath = FolderBrowserDialog1.SelectedPath
End If
'MessageBox.Show("Select Template Excel File")
MsgBox("Select Template Excel File")
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
TempFilePath = OpenFileDialog1.FileName
End If
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.open(TempFilePath)
With (oBook)
oSheet = .Worksheets("Sheet1")
End With
oSheet = oBook.ActiveSheet
Dim fld As New System.IO.DirectoryInfo(DirPath)
Dim fil As System.IO.FileInfo
ReDim file_name(fld.GetFiles("*.bmp").Length - 1)
For Each fil In fld.GetFiles("*.bmp")
result = fil.Name 'Returns the filename with ext (in FileInfo)
fullpath = fil.FullName 'Returns full path to the file (in FileInfo)
file_name(i) = Path.GetFileNameWithoutExtension(fullpath)
dimension = GetBitmapSize1(fullpath)
ReqdWidth = dimension.Width.ToString
For Each c In oSheet.Range("A3:A501")
If c.Value = (file_name(i)) Then
tempaddress = c.address
'MessageBox.Show(tempaddress)
'Reverse Looping and Checking for "$"
For x = Len(Trim(tempaddress)) To 1 Step -1
If Mid(tempaddress, x, 1) <> "$" Then
RowAddress = Mid(tempaddress, x, 1) & RowAddress
Else 'The first "$" found from Right
'Exit Loop
Exit For
End If
Next x
'MessageBox.Show(RowAddress)
End If
Next (c)
Destination = ("C" & RowAddress.ToString)
'MessageBox.Show(Destination)
oSheet.Range(Destination).Value = (ReqdWidth)
i = i + 1
RowAddress = ""
Next
oBook.SaveAs("C:\Book2.xls")
oSheet = Nothing
oBook = Nothing
oExcel.visible = True
oExcel.Quit()
oExcel = Nothing
MessageBox.Show("xls saved")
End Sub
Private Function GetBitmapSize1(ByVal Path As String) As Size
If File.Exists(Path) Then
Dim b As New Bitmap(Path)
Dim s As New Size(b.Width, b.Height)
b.Dispose()
Return s
Else
Throw New FileNotFoundException()
End If
End Function
End Class
Is there a problem with the data type and its limits?? This is very important..
Please Advise
cheers
Abhilash
Last edited by Abhilash007; Apr 11th, 2007 at 05:02 AM.
-
Apr 11th, 2007, 06:18 AM
#2
Re: [2005] Exception from HRESULT: 0x800A03EC ???
Hi
Are you sure the app compiles without error ? Should be
[vbcode]oSheet.Range(Destination).Value = ReqdWidth[/vbcode] intead of [vbcode]oSheet.Range(Destination).Value = (ReqdWidth)[/vbcode]
"The dark side clouds everything. Impossible to see the future is."
-
Apr 11th, 2007, 10:07 PM
#3
Thread Starter
Member
Re: [2005] Exception from HRESULT: 0x800A03EC ???
Hey...
Wenever i build the code, its done successfully... i tried wad you said but it din work... the problem is.. the code works for around the first 90 .bmp files and then shows the error.. i cant seem to figure out wads wrong..
please advise..
cheers
Abhilash
-
Apr 12th, 2007, 03:09 AM
#4
Thread Starter
Member
Re: [2005] Exception from HRESULT: 0x800A03EC ???
Hey Guys!!!
I figured out the problem wid the code.. there was a error in the logic and i had not considered all the possible outcomes.. have sorted it out now.. thx
cheers
Abhilash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|