me puse a hacer cosillas en plan hobby, leyendo tutoriales por internet.
Me puse a hacer un programilla para leer el contenido de unas carpetas, pero me da error y no consigo solucionarlo.
Se trata de leer un directorio y poner el listado de carpetas en un listbox, y al seleccionar un elemento de la lista
a la derecha se muestren los datos del texto en tres textbox, pero
me da este error, "Referencia a objeto no establecida como instancia de un objeto", al intentar mostrarlo.
En todos los sitios que mire, decian que faltaba un "New", pero no se donde ni porque

Otra cosilla, la variable " leenfo" le he dado el valor de "0 to 1010", deberia ser " 0 to stadnum",
que es el numero de carpetas que contiene el directorio, pero al llegar a "1011" me daba error (El valor de 1011 no es valido para index).
Esta es la parte del codigo que meda el error. Espero haberme esplicado bien.
Un saludo
Código PHP:
Option Explicit On
'Option Strict On
Imports System.IO
Public Class Menu
'Dar valor al directorio del kitserver
Public kspath As String = "E:\pes 6\kitserver\GDB"
'Cargar Directorios
Dim stapath As String = kspath + "\stadiums"
Dim bootpath As String = kspath + "\boots"
Dim stadnum As Integer
Dim scrshot As Integer = 0
Dim nfobui() As String
Dim nfocap() As String
Dim nfocit() As String
Public Shared Function Left( _
ByVal str As String, _
ByVal Length As Integer _
) As String
End Function
Public stadnam As Object
Private Sub Menu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''''''''''''''''''''
'Carga carpetas
'''''''''''''''''''''
' Obtener todos los directorios
For Each archivos As String In Directory.GetDirectories(stapath, "*.*", SearchOption.TopDirectoryOnly)
' extraer el nombre de la carpeta de la ruta completa
archivos = archivos.Substring(archivos.LastIndexOf("\") + 1).ToString
' Agregar el valor
lststad.Items.Add(archivos.ToString)
Next
stadnum = lststad.Items.Count
'cargar info stadios
Dim lineRead As String
Dim fileReader As System.IO.StreamReader
Dim textFile As File
Dim screen(0 To 14) As String
Dim nfobui() As String
Dim nfocap() As String
Dim nfocit() As String
Dim objReader As System.IO.StreamReader
Dim leenfo As Integer
ReDim Preserve nfobui(stadnum)
ReDim Preserve nfocap(stadnum)
ReDim Preserve nfocit(stadnum)
For leenfo = 0 To 1010
Dim built As String
Dim capacity As String
Dim city As String
SPath = kspath & "\stadiums\" & lststad.Items(leenfo).ToString & "\info.txt"
With My.Computer.FileSystem
If .FileExists(SPath) Then Else File.WriteAllText(SPath, "hola")
End With
fileReader = textFile.OpenText(SPath)
While fileReader.Peek <> -1
lineRead = fileReader.ReadLine()
If Microsoft.VisualBasic.Left(lineRead, 5) = "built" Then built = lineRead
If Microsoft.VisualBasic.Left(lineRead, 5) = "Built" Then built = lineRead
If Microsoft.VisualBasic.Left(lineRead, 8) = "capacity" Then capacity = lineRead
If Microsoft.VisualBasic.Left(lineRead, 8) = "Capacity" Then capacity = lineRead
If Microsoft.VisualBasic.Left(lineRead, 4) = "city" Then city = lineRead
If Microsoft.VisualBasic.Left(lineRead, 4) = "City" Then city = lineRead
End While
nfobui(leenfo) = Replace(built, " ", "")
nfobui(leenfo) = Replace(nfobui(leenfo), "=", "")
nfobui(leenfo) = Replace(nfobui(leenfo), "built", "")
nfocap(leenfo) = Replace(capacity, " ", "")
nfocap(leenfo) = Replace(nfocap(leenfo), "=", "")
nfocap(leenfo) = Replace(nfocap(leenfo), "capacity", "")
nfocit(leenfo) = Replace(city, " ", "")
nfocit(leenfo) = Replace(nfocit(leenfo), "=", "")
nfocit(leenfo) = Replace(nfocit(leenfo), "city", "")
built = ""
capacity = ""
city = ""
Next
lststad.SelectedItem = lststad.Items(0)
tbbui.Text = nfobui(0)
tbcit.Text = nfocit(0)
tbcap.Text = nfocap(0)
' ''''''''''`'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Menu Estadios
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Stadlist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lststad.SelectedIndexChanged
lblsta.Text = lststad.SelectedItem
tbbui.Text = nfobui(lststad.SelectedIndex)
tbcit.Text = nfocit(lststad.SelectedIndex)
tbcap.Text = nfocap(lststad.SelectedIndex)
End Sub
End Class