[AIDE] Put FTP TextBox value.

Résolu
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 - Modifié par NeriXs le 4/05/2015 à 16:38
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 - 8 mai 2015 à 11:50
Bonjour à tous,
Sur la base du code ci-dessous.
J'envoie le contenu du fichier texte suivant:
!R! FRPO L2,76; FRPO L4,67; STAT1; EXIT;
J'aimerais que les valeurs envoyés FRPO L2 et FRPO L4 respectivement 76 et 67 soient saisies dans des TextBox
Pouvez-vous m'aider?
Bien cordialement

Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
'Const INTERNET_DEFAULT_FTP_PORT = 21 ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for FTP connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1 ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3 ' via named proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 ' prevent using java/script/INS
Const MAX_PATH = 260
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Const PassiveConnection As Boolean = True

Private Sub cmd_exit_Click()
End
End Sub

Private Sub cmd_send_Click()
Dim hConnection As Long, hOpen As Long, sOrgPath As String
'open an internet connection
hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
'connect to the FTP server
hConnection = InternetConnect(hOpen, txt_ftp.Text, INTERNET_DEFAULT_FTP_PORT, txt_login.Text, txt_pw.Text, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
'create a buffer to store the original directory
sOrgPath = String(MAX_PATH, 0)
'get the directory
FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
'upload the file 'test.htm'
FtpPutFile hConnection, "" & App.Path & "\Onin42.txt", "Onin42.txt", FTP_TRANSFER_TYPE_UNKNOWN, 0
'close the internet connection
InternetCloseHandle hOpen
MsgBox ("Sucesful")

End Sub

17 réponses

vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
5 mai 2015 à 12:42
Bonjour
Ceci implique-t-il le fait que ces 4 valeurs sont variables ?
C'est-à-dire que tu peux très bien envoyer 45 et 98 et 54 et 36 comme valeurs comme envoyer 87 et 75 et 84 et 65 par exemple !

En supposant les 4 valeurs contenues dans Textbox1 à Textbox4 cela donnerait :

Open "C:\MonFichier.txt" For Output As #1 
Dim chaine as string
chaine = "!R! FRPO L1," & Textbox1.text
chaine = chaine & "; FRPO L2," & Textbox2.text
chaine = chaine & "; FRPO L3," & Textbox3.text
chaine = chaine & "; FRPO L4," & Textbox4.text
chaine = chaine & "; STAT1; EXIT;"
Print #1, chaine
1
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
6 mai 2015 à 07:21
Salut Nerix
Lorsque tu quittes le programme le fichier texte n'est pas vide ! Le Close #1 ne fait que fermer le canal de communication entre ton programme et le fichier texte lui-même !
Le mieux est d'effacer le fichier avec un
Kill "C:\MonFichier.txt"


De toute façon tu recrées le fichier avec le Open
1
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
Modifié par ucfoutu le 6/05/2015 à 10:01
Bonjour,
ce qui ne serait donc finalement que :
Private Sub Combo1_Click()
MsgBox "STAT" & Combo1.List(Combo1.ListIndex)
End Sub


________________________
Nul ne saurait valablement coder ce qu'il ne saurait exposer clairement.
1
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
Modifié par NeriXs le 4/05/2015 à 18:09
J'avais pensé enregister la valeur du TextBox dans le fichier texte comme ceci :

Private Sub cmdEnregistrer_Click() 
Dim texte
texte = Text1.Text
Open "C:\MonFichier.txt" For Output As #1
Print #1, texte
Close #1


puis le lire l'enregistrement

Private Sub cmdLireEnreg_Click() 
Dim crlf, tout, texte
On Error Resume Next
crlf = Chr(13) + Chr(10)
Open "C:\MonFichier.txt" For Input As #1
Line Input #1, texte
tout = texte
If Len(tout) <> 0 Then
While Not EOF(1)
Line Input #1, texte
tout = tout + crlf + texte
Wend
End If
Text1.Text = tout
Close #1
End Sub


je ne sais pas comment placer mes valeurs au bonne endroit dans le fichier texte.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
4 mai 2015 à 18:57
Avec mes 4 TextBox

Ecriture des TextBox

Private Sub cmdEnregistrer_Click() 
Dim L1, L2, L3, L4
L1 = L1.Text
L2 = L2.Text
L3 = L3.Text
L4 = L4.Text
Open "C:\MonFichier.txt" For Output As #1
Print #1, L1
Print #1, L2
Print #1, L3
Print #1, L4
Close #1
End Sub


Puis lire l'enregistrement

Private Sub cmdLireEnreg_Click() 
Dim crlf, Enreg_L1, Enreg_L2, Enreg_L3, Enreg_L4, L1,L2,L3,L4
On Error Resume Next
crlf = Chr(13) + Chr(10)
Open "C:\MonFichier.txt" For Input As #1
Line Input #1,L1
Line Input #1,L2
Line Input #1,L3
Line Input #1,L4
Enreg_L1=L1
Enreg_L2 =L2
Enreg_L3 =L3
Enreg_L4 =L4
If Len(tout) <> 0 Then
While Not EOF(1)
Line Input #1,L1
Enreg_L1= Enreg_L1+ crlf +L1
Wend
If Len(Enreg_L2) <> 0 Then
While Not EOF(1)
Line Input #1,L2
Enreg_L2 = Enreg_L2 + crlf +L2
Wend
If Len(Enreg_L3) <> 0 Then
While Not EOF(1)
Line Input #1,L3
Enreg_L3 = Enreg_L3 + crlf +L3
Wend
If Len(Enreg_L4) <> 0 Then
While Not EOF(1)
Line Input #1,L4
Enreg_L4 = Enreg_L4 + crlf +L4
Wend
End If
End If
End If
End If
L1.Text = Enreg_L1
L2.Text = Enreg_L2
L3.Text = Enreg_L3
L4.Text = Enreg_L4
Close #1
End Sub


je ne voix toujours pas comment placer mes valeurs au bonne endroit.

!R! FRPO L1,25; FRPO L2,76; FRPO L3,36; FRPO L4,67; STAT1; EXIT;
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
4 mai 2015 à 19:06
Bonjour,
Je dois te dire qu'entre ton premier message et les messages suivants, j'ai personnellement des difficultés à comprendre ce que tu cherches et veux dire.
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
4 mai 2015 à 19:50
Bonjour,
Je ne suis peut-être pas sur la bonne voie !
Je cherche à modifier une partie du contenu d'un fichier texte par des textbox avant d'envoyer ce fichier texte via FTP.
Il ne semble pas possible de le faire sans passer par un fichier texte.
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
Modifié par NeriXs le 5/05/2015 à 22:41
Merci vb95 c'est exactement ce que je cherchais a faire :)

J'ai placé ton code dans un CommandButton et ajouté Close #1 a la fin pour fermer le fichier texte.

Private Sub Command1_Click()
Open "C:\MonFichier.txt" For Output As #1
Dim chaine As String
chaine = "!R! FRPO L1," & Textbox1.Text
chaine = chaine & "; FRPO L2," & Textbox2.Text
chaine = chaine & "; FRPO L3," & Textbox3.Text
chaine = chaine & "; FRPO L4," & Textbox4.Text
chaine = chaine & "; STAT1; EXIT;"
Print #1, chaine

Close #1

End Sub


Dans le Form_Load j'ai aussi ajouté l'ouverture et la fermeture du fichier texte pour le « vider » mais je pense qu'il y a une solution plus adéquate !!

Private Sub Form_Load()
Open "C:\MonFichier.txt" For Output As #1
Close #1
End Sub
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
5 mai 2015 à 22:53
Open "C:\MonFichier.txt" For Output As #1
Close #1


J'avais oublié le Close #1
Inutile de mettre ces 2 lignes dans le Form_Load si tu l'as déjà mis dans le Command1_Click

Qu'entends-tu par "vider" le fichier ?
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
6 mai 2015 à 00:00
Pour être sur que le fichier texte soit vide quand je quite le programme.
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
6 mai 2015 à 08:53
Salut vb95 et merci :)

J'ai fait un petit oublie.
La "commande" STAT1 peut nécessiter d'être a 0 ou a 1.

J'ai tenté avec un ComboBox

Private Sub Form_Load()
combo1.AddItem "0"
combo1.AddItem "1"
End Sub


private sub combo1_click()
if combo1.listindex = 0 then
msgbox "STAT0"
elseif combo1.listindex = 1 then
msgbox "STAT1"
end if


comment intégrer la valeur dans la "chaine"?
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
6 mai 2015 à 10:17
Bonjour,
Et donc:

chaine = chaine & "; STAT" & Combo1.List(Combo1.ListIndex)
chaine = chaine & "; EXIT;"
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
6 mai 2015 à 17:50
Private Sub Command1_Click()
if Combo1.Listindex = -1 then
msgbox "valeur STAT non précisée":Exit Sub
end if
Open "C:\MonFichier.txt" For Output As #1
Dim chaine As String
chaine = "!R! FRPO L1," & Textbox1.Text
chaine = chaine & "; FRPO L2," & Textbox2.Text
chaine = chaine & "; FRPO L3," & Textbox3.Text
chaine = chaine & "; FRPO L4," & Textbox4.Text
chaine = chaine & "; STAT" & Combo1.List(Combo1.ListIndex)&";EXIT;"
Print #1, chaine
Close #1

End Sub


Les 3 premières lignes évitent l'oubli de préciser une valeur pour STAT
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
6 mai 2015 à 18:34
Bonjour, vb95,
Pourquoi passer par un bouton de commande ?
L'évènement click de la combo est suffisant et permet d'éviter de vérifier qu'un article a été sélectionné (ton listindex = -1). Il l'a forcément été.
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169 > ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018
6 mai 2015 à 18:58
Bonsoir Ucfoutu
Le Command1_Click est dans le code d'origine de Nerixs . Je l'avais donc laissé.
Mais ce que tu dis est fort judicieux

Je le propose en ton nom a NériXs : modification de notre ami Ucfoutu
La chaine à envoyer est formée lorsque l'on sélectionne la valeur 0 ou 1 de la Combobox
Private Sub Combo1_Click()
Open "C:\MonFichier.txt" For Output As #1
Dim chaine As String
chaine = "!R! FRPO L1," & Textbox1.Text
chaine = chaine & "; FRPO L2," & Textbox2.Text
chaine = chaine & "; FRPO L3," & Textbox3.Text
chaine = chaine & "; FRPO L4," & Textbox4.Text
chaine = chaine & "; STAT" & Combo1.List(Combo1.ListIndex)&";EXIT;"
Print #1, chaine
Close #1

End Sub


bonsoir à toi Ucfoutu et bonne prog
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
6 mai 2015 à 23:57
Merci à vous deux pour ces retours :)

Auriez-vous une idée de comment gérer depuis un CheckBox le fait que un ou plusieurs TextBox soient grisés et verrouillés (peut-être avec les propriétés Enabled et BackColor?) mais, surtout que la ou les chaines correspondantes ne soient pas renseignées dans le fichier texte ?
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
7 mai 2015 à 17:55
Il faut à mon avis vérifier que chaque Textbox contienne bien une valeur numérique. Si les 4 sont ok on crée le fichier sinon on informe l'utilisateur par un message d'erreur!

Mais là c'est un autre problème ! Si tu ne trouves pas ouvre une nouvelle discussion
Bonne prog
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
7 mai 2015 à 18:17
Comme le précise vb95, que je salue, il s'agit là d'une autre difficulté technique, n'ayant rien à voir avec celle qui a justifié l'ouverture de cette discussion.
Si la difficulté exposée à l'ouverture de la présente discussion est résolue, veux-tu bien, s'il te plait, libérer cette discussion par un clic sur le tag RESOLU au niveau de ton tout premier message ?
Merci de te conformer à cette règle.
0
NeriXs Messages postés 258 Date d'inscription lundi 4 mai 2015 Statut Membre Dernière intervention 27 février 2024 1
8 mai 2015 à 11:50
Bonjour,

Effectivement je sors du sujet de base avec cette action sur les TextBox.
Je vais étudier cela et revenir vers vous si besoin.
Merci pour votre aide.

Bonne prog à tous
0
Rejoignez-nous