COMBOBOX | Récupération des infos d'un .ini

Résolu
cs_Richard92 Messages postés 22 Date d'inscription mardi 5 juillet 2005 Statut Membre Dernière intervention 27 janvier 2006 - 30 août 2005 à 22:43
cs_Richard92 Messages postés 22 Date d'inscription mardi 5 juillet 2005 Statut Membre Dernière intervention 27 janvier 2006 - 1 sept. 2005 à 10:46
SALUT à TOUS,
Je fais un app où l'user doit enregistrer des infos dans un ini.
Voilà un exemple de ini

[Vol]
Date = 30.08.2005
Heure = 22.40
[Agression]
Date = 20.08.2005
Heure = 02.15

Je voudrais avoir une combobox avec comme choix :
- Vol
- Agression
Et quand un choix est fait les variantes vont dans txt1 et txt2

Un code est bienvenu. Merci

5 réponses

Zlub Messages postés 809 Date d'inscription mercredi 11 octobre 2000 Statut Membre Dernière intervention 29 septembre 2010 8
1 sept. 2005 à 06:52
Salut,


Ah oki, j'avais pas capté ... Bon alors, j'espere que c'est ça cette fois ...





Private Sub Form_Load()

Dim F As Integer

F = FreeFile

Dim tmp As String



cboTypeAffichage.AddItem ""



Open App.Path & "\fichier.ini" For Input As #F

Do While Not EOF(F)

Input #F, tmp

If InStr(1, tmp, "[") = 1 Then cboTypeAffichage.AddItem Mid(tmp, 2, Len(tmp) - 2)

Loop

Close #F



End Sub



Private Sub cboTypeAffichage_Click()

Dim index As Integer

index = cboTypeAffichage.ListIndex



If index < 1 Then Exit Sub



txt(index - 1).Text = "date : " & LireINI(cboTypeAffichage.Text, "Date")

txt(index - 1).Text = txt(index - 1).Text & vbCrLf & _


"Heure : " & LireINI(cboTypeAffichage.Text, "Heure")

End Sub





++

Zlub

<hr size="2" width="100%">
3
Zlub Messages postés 809 Date d'inscription mercredi 11 octobre 2000 Statut Membre Dernière intervention 29 septembre 2010 8
30 août 2005 à 23:06
Salut,


voici Form1.frm



VERSION 5.00

Begin VB.Form Form1

BorderStyle = 3 'Fixed Dialog

Caption = "Form1"

ClientHeight = 3180

ClientLeft = 45

ClientTop = 375

ClientWidth = 2850

LinkTopic = "Form1"

MaxButton = 0 'False

MinButton = 0 'False

ScaleHeight = 3180

ScaleWidth = 2850

ShowInTaskbar = 0 'False

StartUpPosition = 3 'Windows Default

Begin VB.TextBox txtAffiche

Height = 1485

Left = 368

MultiLine = -1 'True

TabIndex = 1

Top = 1155

Width = 2115

End

Begin VB.ComboBox cboTypeAffichage

Height = 315

Left = 368


Style
= 2 'Dropdown List

TabIndex = 0

Top = 525

Width = 2115

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Option Explicit



Private Sub Form_Load()

cboTypeAffichage.AddItem ""

cboTypeAffichage.AddItem "Vol"

cboTypeAffichage.AddItem "Agression"

End Sub





Private Sub cboTypeAffichage_Click()

If cboTypeAffichage.ListIndex < 1 Then Exit Sub



txtAffiche.Text = "date : " & LireINI(cboTypeAffichage.Text, "Date")



txtAffiche.Text = txtAffiche.Text & vbCrLf & _


"Heure : " & LireINI(cboTypeAffichage.Text, "Heure")

End Sub





et ici le moduleINI.bas



Attribute VB_Name = "FichierINI"

Option Explicit

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As
Long



Function LireINI(Entete As String, Variable As String) As String

Dim Retour As String

Dim fichier As String

fichier = App.Path & "\fichier.ini"

Retour = String(255, Chr(0))

LireINI = Left$(Retour, GetPrivateProfileString(Entete, ByVal Variable, "", Retour, Len(Retour), fichier))

End Function

Function EcrireINI(Entete As String, Variable As String, valeur As String) As String

Dim fichier As String

fichier = App.Path & "\fichier.ini"

EcrireINI = WritePrivateProfileString(Entete, Variable, valeur, fichier)

End Function







et enfin fichier.ini



[Vol]

Date = 30.08.2005

Heure = 22.40

[Agression]

Date = 20.08.2005

Heure = 02.15





Tu enregistres chacun dans un fichier texte que tu renommes avec le nom en gras et tu fais un projet avec ...


++

Zlub

<hr size="2" width="100%">
0
Zlub Messages postés 809 Date d'inscription mercredi 11 octobre 2000 Statut Membre Dernière intervention 29 septembre 2010 8
30 août 2005 à 23:13
Salut,

zut tu voulais deux textbox ... bon b'hein tu remplaces Form1.frm par ceci :



VERSION 5.00

Begin VB.Form Form1

BorderStyle = 3 'Fixed Dialog

Caption = "Form1"

ClientHeight = 3180

ClientLeft = 45

ClientTop = 375

ClientWidth = 5220

LinkTopic = "Form1"

MaxButton = 0 'False

MinButton = 0 'False

ScaleHeight = 3180

ScaleWidth = 5220

ShowInTaskbar = 0 'False

StartUpPosition = 3 'Windows Default

Begin VB.TextBox txt

Height = 1485

Index = 1

Left = 2625

MultiLine = -1 'True

TabIndex = 2

Top = 1155

Width = 2115

End

Begin VB.TextBox txt

Height = 1485

Index = 0

Left = 368

MultiLine = -1 'True

TabIndex = 1

Top = 1155

Width = 2115

End

Begin VB.ComboBox cboTypeAffichage

Height = 315

Left = 368


Style
= 2 'Dropdown List

TabIndex = 0

Top = 525

Width = 2115

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Option Explicit



Private Sub Form_Load()

cboTypeAffichage.AddItem ""

cboTypeAffichage.AddItem "Vol"

cboTypeAffichage.AddItem "Agression"

End Sub





Private Sub cboTypeAffichage_Click()

Dim index As Integer

index = cboTypeAffichage.ListIndex



If index < 1 Then Exit Sub



txt(index - 1).Text = "date : " & LireINI(cboTypeAffichage.Text, "Date")



txt(index - 1).Text = txt(index - 1).Text & vbCrLf & _


"Heure : " & LireINI(cboTypeAffichage.Text, "Heure")

End Sub






++

Zlub

<hr size="2" width="100%">
0
cs_Richard92 Messages postés 22 Date d'inscription mardi 5 juillet 2005 Statut Membre Dernière intervention 27 janvier 2006
31 août 2005 à 10:32
Non c pas ça lool. Ce que je veux : c que les options de la combo soit défini par lecture du .ini.
0

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

Posez votre question
cs_Richard92 Messages postés 22 Date d'inscription mardi 5 juillet 2005 Statut Membre Dernière intervention 27 janvier 2006
1 sept. 2005 à 10:46
ben je pense que ça va allez. Réponse acceptée
0
Rejoignez-nous