My goal is be able to print out a Structure as a receipt without using a SortedList.
Structure:
Private Structure Facture
Dim noClient As String
Dim nom As String
Dim prenom As String
Dim adresse As String
Dim ville As String
Dim province As String
Dim codePostal As String
Dim courriel As String
Dim noTel As String
Dim noProduit As String
Dim marque As String
Dim modele As String
Dim annee As String
Dim couleur As String
Dim categorie As String
Dim noSerie As String
Dim prix As String
Dim dateVente As String
End Structure
Structure Instance :
Private Function getFacture(ByVal ID As Integer) As Facture
Dim receipt As Facture
receipt.noClient = mtxtNoClient.Text
receipt.nom = txtNom.Text
receipt.prenom = txtPrenom.Text
receipt.adresse = txtAdresse.Text
receipt.ville = txtVille.Text
receipt.province = CboProvince.Text
receipt.codePostal = mtxtCodePostal.Text
receipt.courriel = txtCourriel.Text
receipt.noTel = mtxtNoTel.Text
receipt.noProduit = mtxtNoProduit.Text
receipt.marque = txtMarque.Text
receipt.modele = txtModele.Text
receipt.annee = mtxtAnnee.Text
receipt.couleur = txtCouleur.Text
receipt.categorie = txtCategorie.Text
receipt.noSerie = txtNoSerie.Text
receipt.prix = mtxtPrix.Text
receipt.dateVente = dtpickerDateVente.Text
Return (receipt)
End Function
And I need to print this along side an Array of Strings.
FORMAT :
Private Sub btnAfficherVente_Click(sender As Object, e As EventArgs) Handles btnAfficherVente.Click
' gotta read each line and print them as toString formatted for facturation
Dim infoProduit As String() = New String() {"No de client:", "Nom:", "Prénom:", "Adresse:", "Ville:", "Province:", "Code Postal:", "Courriel:", "Téléphone:",
"No de produit:", "Marque:", "Modèle:", "Année:", "Couleur:", "Catégorie:", "No de série:", "Prix:", "Date de vente:"}
'Output in facturation formatted text
Dim i As Integer = 0
Do While i < infoProduit.Length
If i = 9 Then
txtFacturation.Text += vbCrLf + "==============================================" + vbCrLf
End If
txtFacturation.Text += String.Format("{0, -20}", infoProduit(i)) & vbTab & getFacture(i).ToString & vbCrLf
i += 1
Loop
End Sub
OUTPUT :
I have looked at the documentation and multiple questions on StackOverflow. Most of the answers are in regards of using a Dictionnary, Collection or SortedList.
In the documentation, the only thing I found was to Override the ToString() in the Structure, which would no work for me because that would mean I have to individually format them in ToString but that would mess the final output since I have to print it along side an Array of Strings.

getFacturedoesn't make sense. It ignores the ID-parameter. You are also calling it in the loop with the index as parameter but you just need to use the same, single instance ofFacturebecause you want to get all fields of it.IDto determine which property of the current facture to show. You don't need to create a new one every time and you can't just return the entire thing. For instance ifIDis 0 returnnoClient, ifIDis 1 returnnom(and so on).getFacture(i).ToString()is wrong! you dpn't useIDparam inside thegetFacture()function. Why you don't use a dictionary? You need to use reflecection to get properties by index which may be not required!