Lid |
|
In mijn programma kan je via een listview kiezen welk sub-programma je wilt starten. Deze programma's staan beschreven in .mdl bestanden in de map \Modules.
Ik heb de onderstaande code. Deze werkt niet, want na tijdens de for each is eerst externalmodulecollection(0).FileName [...]\Modules\IGC.mdl. In de 2e keer dat hij er langs gaat is externalmodulecollection(0).FileName ineens [...]\Modules\IGSW.mdl.
Gedeelte van de code van Form1
Public Class Form1
Dim externalmodulecollection As New List(Of ExternalModule)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ListView1.Items.Clear()
Dim _map As New IO.DirectoryInfo(GetAppPath() + "\modules")
Dim _arrayFiles As IO.FileInfo() = _map.GetFiles("*.mdl")
Dim _info As IO.FileInfo
For Each _info In _arrayFiles
Dim itm As New ExternalModule
itm.FileName = _info.FullName
itm.Read()
ImageList1.Images.Add(itm.FileName, New Bitmap(My.Computer.FileSystem.GetParentPath(itm.FileName) + "\" + itm.Image))
Dim LVitm As New ListViewItem(itm.ProgName, ImageList1.Images.Count - 1)
ListView1.Items.Add(LVitm)
externalmodulecollection.Add(itm)
Try
MsgBox(externalmodulecollection(0).FileName)
MsgBox(externalmodulecollection(1).FileName) 'Klein testje!
MsgBox(externalmodulecollection(2).FileName)
Catch ex As Exception
MsgBox("")
End Try
Next
Dim this As New ListViewItem("", 0)
ListView1_SelectedIndexChanged()
End Sub
Public Class Form1 Dim externalmodulecollection As New List(Of ExternalModule) Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ListView1.Items.Clear() Dim _map As New IO.DirectoryInfo(GetAppPath() + "\modules") Dim _arrayFiles As IO.FileInfo() = _map.GetFiles("*.mdl") Dim _info As IO.FileInfo For Each _info In _arrayFiles Dim itm As New ExternalModule itm.FileName = _info.FullName itm.Read() ImageList1.Images.Add(itm.FileName, New Bitmap(My.Computer.FileSystem.GetParentPath(itm.FileName) + "\" + itm.Image)) Dim LVitm As New ListViewItem(itm.ProgName, ImageList1.Images.Count - 1) ListView1.Items.Add(LVitm) externalmodulecollection.Add(itm) Try MsgBox(externalmodulecollection(0).FileName) MsgBox(externalmodulecollection(1).FileName) 'Klein testje! MsgBox(externalmodulecollection(2).FileName) Catch ex As Exception MsgBox("") End Try Next Dim this As New ListViewItem("", 0) ListView1_SelectedIndexChanged() End Sub
En een gedeelte uit de module waar Externalmodule in is gedeclareerd:
Imports System.Windows.Forms
Imports System.Reflection
Module M_Load_Externall_Dll
Public Structure ExternalModule
Shared fn As New String("")
Shared nm As New String("")
Shared ds As New String("")
Shared img As New String("")
Shared dll As New String("")
Public Sub SetFileName(ByVal NewFileName As String)
FileName = NewFileName
End Sub
Public Property FileName() As String
Get
FileName = fn
End Get
Set(ByVal value As String)
fn = value
End Set
End Property
Public Property ProgName() As String
Get
ProgName = nm
End Get
Set(ByVal value As String)
nm = value
End Set
End Property
Public Property Description() As String
Get
Description = ds
End Get
Set(ByVal value As String)
ds = value
End Set
End Property
Public Property Image() As String
Get
Image = img
End Get
Set(ByVal value As String)
img = value
End Set
End Property
Public Property DllFile() As String
Get
DllFile = dll
End Get
Set(ByVal value As String)
dll = value
End Set
End Property
Public Function Read() As Boolean
Try
Dim ta() As String = My.Computer.FileSystem.ReadAllText(fn).Split("&")
nm = ta(0)
ds = ta(1)
img = ta(2)
dll = ta(3)
RaiseEvent ReadCompleted()
Read = True
Catch ex As Exception
RaiseEvent ReadError()
Read = False
End Try
End Function
Public Event ReadError()
Public Event ReadCompleted()
End Structure
Imports System.Windows.Forms Imports System.Reflection Module M_Load_Externall_Dll Public Structure ExternalModule Shared fn As New String("") Shared nm As New String("") Shared ds As New String("") Shared img As New String("") Shared dll As New String("") Public Sub SetFileName(ByVal NewFileName As String) FileName = NewFileName End Sub Public Property FileName() As String Get FileName = fn End Get Set(ByVal value As String) fn = value End Set End Property Public Property ProgName() As String Get ProgName = nm End Get Set(ByVal value As String) nm = value End Set End Property Public Property Description() As String Get Description = ds End Get Set(ByVal value As String) ds = value End Set End Property Public Property Image() As String Get Image = img End Get Set(ByVal value As String) img = value End Set End Property Public Property DllFile() As String Get DllFile = dll End Get Set(ByVal value As String) dll = value End Set End Property Public Function Read() As Boolean Try Dim ta() As String = My.Computer.FileSystem.ReadAllText(fn).Split("&") nm = ta(0) ds = ta(1) img = ta(2) dll = ta(3) RaiseEvent ReadCompleted() Read = True Catch ex As Exception RaiseEvent ReadError() Read = False End Try End Function Public Event ReadError() Public Event ReadCompleted() End Structure
Inhoud van de map \Modules:
IGC.mdl
IGC.png
IGSW.mdl
IGSW.png
Inhoud van IGC.mdl
IGisoft Converter 2010&Reken getallen van de ene naar de andere eenheid om&IGC.png&IGC.dll
Inhoud van IGSW.mdl
IGisoft Stopwatch 2010&Meet tijden&IGSW.png&IGSW.dll
Iemand een oplossing zodat de List niet ineens veranderd?
|