Tom's Guide > Forum > Programmation > [Résolu] Pièce jointe (VB6)

[Résolu] Pièce jointe (VB6)

Forum Programmation : [Résolu] Pièce jointe (VB6)

TomsGuide.com : 800 000 inscrits répondent à toutes vos questions high-tech et informatique. Pour obtenir de l'aide, inscrivez-vous gratuitement !
Mot :    Pseudo :           
 

Bonsoir ^^

J'aurais besoin de votre aide en ce qui concerne quelques trucs sur VB6.

Alors voilà, j'ai 2 questions concernant mon programme :

1.
J'ai une base de donnée "Etudiant.MDB" avec une table "ETUDIANT", "ETUDE", "ENSEIGNANT" et "DEPARTEMENT".
La table ETUDIANT a comme clé principale NUMETUDIANT. La table ETUDE a comme clé p. NUMETUDE et comme clé étrangère NUMETUDIANT. La table ENSEIGNANT quand à elle comporte comme c.p. "NUMENSEIGN" et comme c.e. "NUMETUDE".
Enfin, la table DEPARTEMENT a comme c.p. "NUMDEP" et comme clé étrangère "NUMENSEIGN".
Je voudrais savoir en fait le nombre d'étudiants (Nombre d'enregistrements de la table ETUDIANT) pour chaque departement.
Ex: J'ai un Form contenant une combobox, je sélectionne le numéro du département NUMDEP, et il me donne (en MsgBox ou dans un nouveau Form) le nombre d'étudiants de ce département.

2.
Est-ce possible de créer une interface graphique VB6 ou on pourrait parcourir les répertoires pour sélectionner un fichier ?
Un peu comme pour parcourir une pièce jointe sur les interfaces des boites mails ?
Je voudrais sélectionner une pièce jointe dans un formulaire, mais je ne trouve pas le bouton "Parcourir" dans la boite d'outils.

Si vous savez quoi que ce soit, n'hésitez pas à partager vos connaissances avec un débutant comme moi! ;)
Merci d'avance pour toute aide et bonne soirée! ^.^


Message édité par love-ayu le 25-08-2009 à 19:12:34
Liens sponsorisés
Inscrivez-vous ou connectez-vous pour masquer ceci.

Pour le point n°2, j'utilise un module qui me fourni des interfaces simplement !
Ca utilise les API de windows, ca marche sous win95, win98, win2000 et win XP sûr, j'ai pas testé sous les autres Windows.

Met ceci dans un module :

Code :
  1. Option Explicit
  2. Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  3. Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
  4. Public Type OPENFILENAME
  5.     lStructSize As Long
  6.     hwndOwner As Long
  7.     hInstance As Long
  8.     lpstrFilter As String
  9.     lpstrCustomFilter As String
  10.     nMaxCustFilter As Long
  11.     nFilterIndex As Long
  12.     lpstrFile As String
  13.     nMaxFile As Long
  14.     lpstrFileTitle As String
  15.     nMaxFileTitle As Long
  16.     lpstrInitialDir As String
  17.     lpstrTitle As String
  18.     flags As Long
  19.     nFileOffset As Integer
  20.     nFileExtension As Integer
  21.     lpstrDefExt As String
  22.     lCustData As Long
  23.     lpfnHook As Long
  24.     lpTemplateName As String
  25. End Type
  26. Public Function OuvreChoixFichier() As String
  27. Dim sRet  As String
  28. Dim of    As OPENFILENAME
  29.     sRet = String(254, 0& )
  30.     of.flags = 4
  31.     of.hInstance = App.hInstance
  32.     of.lpstrInitialDir = "c:\"
  33.     of.lpstrTitle = "Charger un fichier"
  34.     of.hwndOwner = 0&
  35.     of.nFileExtension = 1
  36.     of.lpstrFile = sRet
  37.     of.nMaxFile = 254
  38.     of.lStructSize = Len(of)
  39.     of.lpstrFilter = "Fichier texte(*.text)" & vbNullChar & _
  40.               "*.txt" & vbNullChar & _
  41.               "Tous les fichiers (*.*)" & vbNullChar & _
  42.               "*.*" & vbNullChar & vbNullChar
  43.     If GetOpenFileName(of) > 0 Then
  44.         OuvreChoixFichier = Left(of.lpstrFile, InStr(1, of.lpstrFile, Chr(0)) - 1)
  45.     End If
  46. End Function
  47. Public Function OuvreSauveFichier(sExt As String, Optional sChemin As String = vbNullString) As String
  48. Dim sRet  As String
  49. Dim of    As OPENFILENAME
  50.     sRet = String(254, 0& )
  51.     of.flags = 1
  52.     of.hInstance = App.hInstance
  53.     of.lpstrInitialDir = sChemin
  54.     of.lpstrTitle = "Enregistrer sous ..."
  55.     of.hwndOwner = 0&
  56.     of.nFileExtension = 1
  57.     of.lpstrFile = sRet
  58.     of.nMaxFile = 254
  59.     If sExt = "txt" Then
  60.         of.lpstrDefExt = "txt"
  61.         of.lpstrFilter = "fichier Texte (*.txt)" & vbNullChar & _
  62.                   "*.txt" & vbNullChar & _
  63.                   "Tous les fichiers (*.*)" & vbNullChar & _
  64.                   "*.*" & vbNullChar & vbNullChar
  65.     Else
  66.         of.lpstrFilter = "Tous les fichiers (*.*)" & vbNullChar & _
  67.                   "*.*" & vbNullChar & vbNullChar
  68.     End If
  69.     of.lStructSize = Len(of)
  70.     If GetSaveFileName(of) > 0 Then
  71.         OuvreSauveFichier = Left(of.lpstrFile, InStr(1, of.lpstrFile, Chr(0)) - 1)
  72.     End If
  73. End Function
  74. Public Function getRepertoire(Optional repertoireInit As String = "c:\" ) As String
  75. Dim oShell As Object
  76. Dim oFolder As Object
  77. Dim oFolderItem As Object
  78.     Set oShell = CreateObject("Shell.Application" )
  79.     Set oFolder = oShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&, repertoireInit)
  80.     If Not oFolder Is Nothing Then
  81.         Set oFolderItem = oFolder.Self
  82.         getRepertoire = oFolderItem.Path
  83.     End If
  84. End Function



et ensuite, depuis n'importe où tu peux faire :

Code :
  1. s = OuvreChoixFichier()
  2.     MsgBox (s)


et 's' contiendra le fichier choisi, ou sera vide si la personne a annuler

Code :
  1. s = OuvreSauveFichier("txt" )
  2.     MsgBox (s)


et 's' contiendra le fichier choisi pour l'enregistrement, ou sera vide si la personne a annuler

Code :
  1. s = getRepertoire()
  2.     MsgBox (s)


et 's' contiendra le répertoire sélectionné ou sera vide si la personne a annuler

Répondre à sylfeline

Merci bien, ton code est intéressant! ^^

C'est bon par rapport à la première question, j'ai trouvé =)


Message édité par love-ayu le 25-08-2009 à 19:11:20
Répondre à love-ayu
Tom's Guide > Forum > Programmation > [Résolu] Pièce jointe (VB6)
Aller à :

Il y a 2146 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici.

Liens