Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202172 27 févr. 2009 à 14:39
Option Explicit
Private Type Job
Name As String
Comment As String
RGB As OLE_COLOR
Release As Long
Due As Long
Weight As Long
Oper() As String
OperCount As Long
End Type
Private Type Shop
Name As String
Jobs() As Job
JobCount As Long
End Type
Private Sub Form_Load()
Dim xsLines() As String
Dim sLine As String
Dim i As Long
Dim sName As String
Dim sValue As String
Dim nPos As Long
Dim xtShops() As Shop
Dim nShopCount As Long
Dim xsParts() As String
'# Chaque ligne sera un élément du tableau xsLines
Open "c:\a.txt" For Input As #1
xsLines = Split(Input(LOF(1), #1), vbNewLine)
Close #1
For i = 0 To UBound(xsLines)
sLine = Trim$(xsLines(i))
If LenB(sLine) Then
'# On va séparer chaque ligne en deux champs. sName et sValue
nPos = InStr(sLine, ":")
If nPos Then
sName = Trim$(Left$(sLine, nPos - 1))
sValue = Trim$(Mid$(sLine, nPos + 1))
If sName = "Shop" Then
'# On ajoute une case au tableau de Shops
ReDim Preserve xtShops(nShopCount)
nShopCount = nShopCount + 1
xtShops(nShopCount - 1).Name = sValue
Else
'# Les champs lus vont être stockés dans le dernier magasin du tableau
With xtShops(nShopCount - 1)
Select Case sName
Case "Job"
'# On agrandit notre tableau
ReDim Preserve .Jobs(.JobCount)
.JobCount = .JobCount + 1
.Jobs(.JobCount - 1).Name = sValue
Case "Comment"
.Jobs(.JobCount - 1).Comment = sValue
Case "RGB"
'# Ici, je convertit en RGB... a voir si ca convient
xsParts = Split(sValue, ";")
If UBound(xsParts) = 2 Then
.Jobs(.JobCount - 1).RGB = RGB(Val(xsParts(0)), Val(xsParts(1)), Val(xsParts(2)))
End If
Case "Release"
.Jobs(.JobCount - 1).Release = sValue
Case "Due"
.Jobs(.JobCount - 1).Due = sValue
Case "Weight"
.Jobs(.JobCount - 1).Weight = sValue
Case "Oper"
'# On stockes le tout dans un tableau dynamique
With .Jobs(.JobCount - 1)
'# On ajoute un case ...
ReDim Preserve .Oper(.OperCount)
.OperCount = .OperCount + 1
.Oper(.OperCount - 1) = sValue
End With
End Select
End With
End If
End If
End If
Next i
'# Ici, a toi de jouer a manipuler le tableau xtShops. Le fichier a été lu et analysé
Stop
End Sub