salve ragazzi,
stò facendo un programma che sistema il contenuto file txt in quanto ho un programma vb che poi lo dovrà analizzare...
volevo sapere c'è un modo per restituire il valore nothing se qualcosa va storto all'inizializzazione della classe che conterrà i dati di ogni singola bAnca?
CODICE:
codice:
Public Class Form1
Dim arrBanche As ArrayList
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim arrRighe As String(), b As Banca
arrRighe = LeggiFile("c:\tababicab.txt")
If arrrighe IsNot Nothing Then
arrBanche = New ArrayList
For Each s As String In arrRighe
b = New Banca(s)
If b IsNot Nothing Then
ListBox1.Items.Add(b.Descrizione)
arrBanche.Add(b)
End If
Next
End If
arrRighe = Nothing
End Sub
Function LeggiFile(ByVal strPath As String) As String()
Dim content As String, SR As System.IO.StreamReader
SR = New System.IO.StreamReader(strPath)
content = SR.ReadToEnd
SR.Close()
SR = Nothing
If content IsNot Nothing Then
Return content.Split(ControlChars.Tab)
Else
Return Nothing
End If
End Function
End Class
CODICE DELLA CLASSE:
codice:
Public Class Banca
Private intABI As Integer
Private strDescrizione As String
Private intCAB As Integer
Private strFiliale As String
Private strIndirizzo As String
Private strLocalità As String
Private intCAP As Integer
Private strProvincia As String
Private dtData As DateTime
ReadOnly Property ABI() As Integer
Get
Return intABI
End Get
End Property
ReadOnly Property Descrizione() As String
Get
Return strDescrizione
End Get
End Property
ReadOnly Property CAB() As Integer
Get
Return intCAB
End Get
End Property
ReadOnly Property Filiale() As String
Get
Return strFiliale
End Get
End Property
ReadOnly Property Indirizzo() As String
Get
Return strIndirizzo
End Get
End Property
ReadOnly Property Località() As String
Get
Return strLocalità
End Get
End Property
ReadOnly Property CAP() As Integer
Get
Return intCAP
End Get
End Property
ReadOnly Property Provincia() As String
Get
Return strProvincia
End Get
End Property
ReadOnly Property Data() As DateTime
Get
Return dtData
End Get
End Property
Public Sub New(ByVal Stringa As String)
Dim arrCampi As String()
arrCampi = Stringa.Split(ControlChars.Tab)
If Not IsNumeric(arrCampi(0)) Then
MyBase.Finalize()
Exit Sub
End If
intABI = CInt(arrCampi(0))
strDescrizione = arrCampi(1)
arrCampi = Nothing
End Sub
End Class