Tu fai una cosa più o meno come questo esempio ?
Public Sub Main()
Dim ss As String[] = ["1", "2", "3", "4"]
Dim s As String
Dim ff As New Float[]
For Each s In ss
ff.Push(Val(s))
Next
End
Concettualmente il codice di LuMo è corretto pertanto l'errore è nel passaggio dei dati al vettore float
Mi sono permesso di variare leggermente il codice di vuott per dimostrarlo:
Public Sub Main()
Dim ss As String[] = Split("11,11|22,22|33,33|44,44", "|") '["1", "2", "3", "4"]'
Dim s As String
Dim ff As New Float[]
Dim f As Float
' add o push sono praticamente la stessa funzione se devi solo accodare i valori'
For Each s In ss
ff.Push(Val(s))
Next
For Each f In ff
Print f
Next
End
Grazie a tutti per le risposte. I numeri che salvo su file sono di tipo float in pratica:
dim n as float = 21.2
dim hFile as file
dim path as string = application.path &/ "nomeFile"
hFile = Open path For Write Append
Write #hFile, str(n) & "|"
Close hFile
---------------------------
dim s as String = File.Load(application.path &/ "nomeFile"
dim arrString as New String[]
dim elem as String
dim arrFloat as New Float[]
arrString = Split(s, "|")
For Each elem in arrString
print elem
arrFloat.Add(Val(elem))
Next
Naturalmente ora provo i vostri suggerimenti
Così funziona, ma non capisco perché Split restituisce anche i null :-\
Public Sub Main()
Dim n As Float = 21.2
Dim hFile As File
Dim path As String = application.path &/ "nomeFile.txt"
Dim b As Byte
hFile = Open path For Write Append
For b = 0 To 9
Write #hFile, Str(n) & "|"
Next
Close hFile
File_Read()
End
Public Sub File_Read()
Dim s As String = File.Load(application.path &/ "nomeFile.txt")
Dim arrString As String[]
Dim arrFloat As New Float[]
Dim f As Float
arrString = Split(s, "|", Null, True)
For Each s In arrString
'Print s
If Not IsNull(s) Then arrFloat.Push(Val(s))
Next
For Each f In arrFloat
Print f
Next
End
Nota: Occorre ricordare che i valori salvati nell'applicazione una volta compilato il programma diventano inservibili perché di sola lettura.