1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'sauvegarder dans le fichier text
If TBname.Text.Trim <> "" Then
FolderBrowserDialog1.ShowDialog()
If Trim(FolderBrowserDialog1.SelectedPath) <> "" Then
Chemin_defaut = New DirectoryInfo(FolderBrowserDialog1.SelectedPath)
If InStr(UCase(TBname.Text.Trim), ".TXT") = 0 Then
If InStrRev(TBname.Text.Trim, ".") > 0 Then
TBname.Text = Mid(TBname.Text.Trim, 1, InStrRev(TBname.Text.Trim, ".") - 1)
End If
TBname.Text = TBname.Text.Trim + ".txt"
End If
'
' If Chemin_Origine.FullName = Chemin_defaut.FullName And Nom_Origine_du_TXT.Trim = TBname.Text.Trim Then
' 16=Image Critical, 4=Yes et No, 256=Position sur 2ème bouton
If MsgBox("Voulez-vous vraiment enregistrer ?", 16 + 4 + 256, "Ecriture Fichier Texte") = MsgBoxResult.No Then
TBname.Focus()
Exit Sub
'End If
Else
Dim Fic As New FileInfo(Chemin_defaut.FullName + "\" + TBname.Text.Trim)
If Fic.Exists Then
If MsgBox("Le fichier " + Fic.Name + " existe déjà!" + Chr(13) + "Voulez-vous l'écraser ?", 16 + 4 + 256, "Ecriture Fichier Texte") = MsgBoxResult.No Then
TBname.Focus()
Exit Sub
End If
End If
End If
Dim Sw As StreamWriter = File.CreateText(Chemin_defaut.FullName + "\" + TBname.Text.Trim)
Dim chaine As String
Dim Prefixe_zone As String = ""
Dim Nom_objet As String = ""
Dim Valeur As String = ""
For Lg = 1 To 8
chaine = "Ligne_" + Lg.ToString.Trim
For Cl = 1 To 5
Select Case Cl
Case 1
Prefixe_zone = "TBFon"
Case 2
Prefixe_zone = "TBCod"
Case 3
Prefixe_zone = "TBAtt"
Case 4
Prefixe_zone = "TBPoz"
Case 5
End Select
Nom_objet = Prefixe_zone + Lg.ToString.Trim
Valeur = Replace(Me.GroupBox2.Controls(Nom_objet).Text.ToString.Trim, ",", ".")
If Valeur = "" Then
Valeur = "-"
End If
chaine = chaine + "," + Replace(Valeur, ",", ".")
Next
Sw.WriteLine(chaine)
Next
Sw.Close()
Init_zone()
MsgBox("Enregistrement OK.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Enregistrement des données")
Else
MsgBox("Veuillez donner un nom de fichier!.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Contrôle des saisies")
End If
End If
End Sub |
Partager