Torna al Thread
'Parte da un file excel dove sulla prima colonna c'è il campo e sulla seconda il tipo di dati
'a partire da questo crea una classe con Campi e proprietà
'poi crea i metodi Salva e Carica
Dim XLS As New Microsoft.Office.Interop.Excel.Application 'Excel.Application
XLS.Workbooks.Open(txtPathFile.text)
'XLS.Workbooks.Open "C:\DettaglioProInt.xls"
XLS.Visible = False
Dim Riga As Integer
Riga = 2
Dim CellaCampo As String = "A"
Dim CellaTipoDati As String = "B"
'leggo le righe a partire dalla seconda, la prima cella è il campo, la seconda il tipo
'questo ciclo inserisce i campi della classe
For Riga = 2 To 50
CellaCampo = "A" & Riga.ToString
CellaTipoDati = "B" & Riga.ToString
If XLS.Range(CellaCampo).Value = "" Then Exit For
txtClasse.Text &= "Private _" & XLS.Range(CellaCampo).Value.ToString & " as " & TipoVar(XLS.Range(CellaTipoDati).Value.ToString) & vbCrLf
Next
txtClasse.Text &= vbCrLf
Dim Campo As String
Dim TipoDati As String
'questo ciclo crea le proprietà
For Riga = 2 To 50
CellaCampo = "A" & Riga.ToString
CellaTipoDati = "B" & Riga.ToString
If XLS.Range(CellaCampo).Value = "" Then Exit For
Campo = XLS.Range(CellaCampo).Value.ToString
TipoDati = TipoVar(XLS.Range(CellaTipoDati).Value.ToString)
txtClasse.Text &= vbCrLf & "Public Property " & Campo & "() as " & TipoDati & vbCrLf
txtClasse.Text &= " Get" & vbCrLf & " Return _" & Campo & vbCrLf & " End Get" & vbCrLf
txtClasse.Text &= " Set(ByVal value As " & TipoDati & ")" & vbCrLf
txtClasse.Text &= " _" & Campo & " = Value" & vbCrLf & " End Set" & vbCrLf
txtClasse.Text &= "End Property" & vbCrLf
Next
txtClasse.Text &= vbCrLf & vbCrLf