La parte del programma che da problemi e segnalata
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim dividi(2) As String
Dim Stopciclo As Boolean = False
Dim d As Integer = 0
Dim esci As Integer = 0
Dim Conta As Integer = 0
Dim _File As IO.FileInfo
Dim xz As Integer
Dim indice2 As Integer
Dim dis As New IO.DirectoryInfo(Dir)
Dim aryFile As IO.FileInfo() = dis.GetFiles("*.epub")
Dim aryFile3 As IO.FileInfo() = dis.GetFiles("*.pdf")
Dim FileEsisitente As Integer = 0
Dim list As New List(Of String)
For Each Dir As String In System.IO.Directory.GetDirectories(OldFolder)
Dim dirInfo As New System.IO.DirectoryInfo(Dir)
list.Add(dirInfo.FullName)
Next
For i = 0 To list.Count - 1
For Each Dir As String In System.IO.Directory.GetDirectories(list.Item(i))
Dim dirInfo As New System.IO.DirectoryInfo(Dir)
list.Add(dirInfo.FullName)
Next
Next
For Each _File3 In aryFile3
dividi = Split(_File3.Name, "- ")
Dim substring As String = dividi(1).Substring(0, 1)
dividi(2) = dividi(2).Replace(".pdf", "")
'Avvio Smistamento
For z = 0 To array.Count - 1
If substring = array(z) Then
d = d + 1
'indice = indice + 1
Dim NewFileName As String = dividi(1) & " - " & dividi(2) & " - " & dividi(0)
If File.Exists(ArrayList & "\" & array(z) & "\" & NewFileName & ".pdf") = False Then
Conta += 1
File.Copy(Dir & "\" & _File3.Name, ArrayList & "\" & array(z) & "\" & _File3.Name)
My.Computer.FileSystem.RenameFile(ArrayList & "\" & array(z) & "\" & _File3.Name, NewFileName & ".pdf")
Else
FileEsisitente += 1
End If
End If
esci = esci + 1
Next
Next
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
' Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = True
' Add a new workbook.
wbXl = appXL.Workbooks.Add
' shXL = wbXl.ActiveSheet
'indice = 1
For xz = 0 To 10
xz = xz + 1
'indice = 1
indice2 = indice2 + 1
Dim shXL As Excel.Worksheet
' Add table headers going cell by cell.
[color=#FF0000] shXL.Cells(xz, 1).Value = "pippo"[/color] il codice di errore e questo
[color=#FFFF00] "System.NullReferenceException: 'Riferimento a un oggetto non impostato su un'istanza di oggetto.'"[/color]
shXL.Cells(1, 2).Value = "Pippo2"
shXL.Cells(1, 3).Value = "Full Name"
shXL.Cells(1, 4).Value = "Specialization"
' Format A1:D1 as bold, vertical alignment = center.
With shXL.Range("A1", "D1")
.Font.Bold = True
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
End With
' Create an array to set multiple values at once.
Dim students(5, 2) As String
students(0, 0) = "Zara"
students(0, 1) = "Ali"
students(1, 0) = "Nuha"
students(1, 1) = "Ali"
students(2, 0) = "Arilia"
students(2, 1) = "RamKumar"
students(3, 0) = "Rita"
students(3, 1) = "Jones"
students(4, 0) = "Umme"
students(4, 1) = "Ayman"
' Fill A2:B6 with an array of values (First and Last Names).
shXL.Range("A2", "B6").Value = students
' Fill C2:C6 with a relative formula (=A2 & " " & B2).
raXL = shXL.Range("C2", "C6")
raXL.Formula = "=A2 & "" "" & B2"
' Fill D2:D6 values.
With shXL
.Cells(2, 4).Value = "Biology"
.Cells(3, 4).Value = "Mathmematics"
.Cells(4, 4).Value = "Physics"
.Cells(5, 4).Value = "Mathmematics"
.Cells(6, 4).Value = "Arabic"
End With
' AutoFit columns A:D.
raXL = shXL.Range("A1", "D1")
raXL.EntireColumn.AutoFit()
' Make sure Excel is visible and give the user control
' of Excel's lifetime.
appXL.Visible = True
appXL.UserControl = True
' Release object references.
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
Next
Exit Sub
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
End Sub