Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15214

VS 2010 conversion from string " " to type 'Double' is not valid

$
0
0
I don't even use Double datatype in my code, even though I assume it come from CDec function.
I set a condition to make the value in it to 0 when it is null (code not included), it still get error
Here is my code.
Code:

        Dim di = New DirectoryInfo("E:\ขาย2564\R-HS2564\R-HS64-05")
'I Dim all variable As string, except ef As Boolean
        result = "E:\ภาษีขาย64\รายงานภาษีขายอัตโนมัติ.xlsx"
        ExcelApp2 = CreateObject("Excel.Application") 
        ExcelWorkbook2 = ExcelApp2.Workbooks.Open("C:\Users\ACER\Desktop\ต้นแบบ\แบบฟอร์มรายงานภาษีขาย.xlsx")
        For Each fi In di.EnumerateFileSystemInfos()
            If (fi.Attributes & FileAttributes.Directory) = FileAttributes.Directory Then
                Console.WriteLine(fi.FullName + " is a directory")
            Else
                pathfile = fi.FullName         
                checkfile = Dir$(pathfile)
                ExcelApp = CreateObject("Excel.Application") 
                ExcelWorkbook = ExcelApp.Workbooks.Open(pathfile)
                'MessageBox.Show(fi.FullName + " is a file")

                'check vat not equal to real price
                If ExcelApp.Worksheets("R-HS").Range("K31").Value = ExcelApp.Worksheets("SO").Range("E26").Value - ExcelApp.Worksheets("SO").Range("E27").Value Then 'yes vat equal no prob
                Else    'vat not equal we got a prob
                    ExcelApp.Worksheets("R-HS").Range("K30").Value = CDec(ExcelApp.Worksheets("R-HS").Range("K30").Value) + CDec(ExcelApp.Worksheets("SO").Range("E26").Value) - CDec(ExcelApp.Worksheets("SO").Range("E27").Value) - CDec(ExcelApp.Worksheets("R-HS").Range("K31").Value)
                End If

                For n As Integer = 2 To 4    'ExcelApp2.Worksheets.Count 'page 'find free page and position
                    'if consider for page 2 or more
                    tp = "หน้า" & n.ToString
                    For r As Integer = 9 To 55 'only 45 list per page
                        If ExcelApp2.Worksheets(tp).Range("A" & r).Value Is Nothing Then
                            freepage = n.ToString
                            freeline = r.ToString
                            ef = True 'find target line set ef for loop exit
                            Exit For
                        End If
                    Next

                    If ef = True Then
                        Exit For
                    End If
                Next
                If freepage = 2 Then
                    ExcelApp2.Worksheets("หน้า" & freepage).Range("A" & freeline).Value = freeline - 8
                ElseIf freepage = 3 Then        'page 3
                    ExcelApp2.Worksheets("หน้า" & freepage).Range("A" & freeline).Value = freeline - 8 + 44
                ElseIf freepage = 4 Then      'page 4
                    ExcelApp2.Worksheets("หน้า" & freepage).Range("A" & freeline).Value = freeline - 8 + 88
                End If

                ExcelApp2.Worksheets("หน้า" & freepage).Range("B" & freeline).Value = ExcelApp.Worksheets("SO").Range("E6").Value
                ExcelApp2.Worksheets("หน้า" & freepage).Range("C" & freeline).Value = Split(fi.Name, ".")(0)
                ExcelApp2.Worksheets("หน้า" & freepage).Range("D" & freeline).Value = ExcelApp.Worksheets("SO").Range("B7").Value
                If ExcelApp.Worksheets("SO").Range("D8").Value IsNot Nothing Then
                    ExcelApp2.Worksheets("หน้า" & freepage).Range("E" & freeline).Value = ExcelApp.Worksheets("SO").Range("D8").Value
                Else : ExcelApp2.Worksheets("หน้า" & freepage).Range("E" & freeline).Value = "-"
                End If

                ExcelApp2.Worksheets("หน้า" & freepage).Range("F" & freeline).Value = "สำนักงานใหญ่"
                ExcelApp2.Worksheets("หน้า" & freepage).Range("G" & freeline).Value = "-"
                ExcelApp2.Worksheets("หน้า" & freepage).Range("H" & freeline).Value = ExcelApp.Worksheets("R-HS").Range("K29").Value

                ExcelApp2.DisplayAlerts = False
                ExcelApp2.Worksheets("หน้า1").SaveAs(filename:=result)       
                ExcelApp2.DisplayAlerts = True

                ExcelApp.DisplayAlerts = False
                ExcelApp.Quit()
                ExcelApp.DisplayAlerts = True
            End If
        Next
        MessageBox.Show("d o n e")

I try to find the root of problem all day, I think I am dead end now.
Thank you

Viewing all articles
Browse latest Browse all 15214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>