Bonjour,
Après avoir passé de très nombreuses heures sur un problème de débutant, je fais à nouveau appel à notre bienveillante communauté, en essayant de m'expliquer mieux qu'hier.
Je souhaite pouvoir rentrer une matrice en format *.txt dans une textbox pour travailler dessus ensuite.
C'est à dire, au lieu de dire (dans le programme ci dessous qui fonctionne)
Dim arr(,) As Double = {{0.0, 0.1, 0.2}, {1.0, 1.1, 1.2}}
dire queque chose du genre : Dim arr(,) As Double = textbox1.text
cependant à chaque fois, j'ai droit au :
"Une valeur de type 'String' ne peut pas être convertie en 'Tableau à 2 dimension(s) de Double. "
Je suis ouvert à toutes vos propositions et je vous remercie pour votre aide ...SOS Galérien débutant
!
Mon programme complet pour info : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr(,) As Double = {{0.0, 0.1, 0.2}, {1.0, 1.1, 1.2}} Dim i, j As Integer
For i = 0 To arr.GetUpperBound(0)
For j = 0 To arr.GetUpperBound(1)
RichTextBox1.SelectedText = (arr(i, j) & " - ")
Next
Next
Dim arr2(,) As Double = TransposeMatrix(arr)
For i = 0 To arr2.GetUpperBound(0)
For j = 0 To arr2.GetUpperBound(1)
RichTextBox2.SelectedText = (arr2(i, j) & " - ")
Next
Next
End Sub
Function TransposeMatrix(ByVal arr(,) As Double) As Double(,)
Dim startRow As Integer, startCol As Integer
Dim endRow As Integer, endCol As Integer
Dim row As Integer, col As Integer
startRow = arr.GetLowerBound(0)
endRow = arr.GetUpperBound(0)
startCol = arr.GetLowerBound(1)
endCol = arr.GetUpperBound(1)
Dim res(endCol, endRow) As Double
For row = startRow To endRow
For col = startCol To endCol
res(col, row) = arr.GetValue(row, col)
Next
Next
Return res
End Function
End Class