Code:
Public strPdfFolder As String = "Folder"
Public strDatasheetFolder As String = Folder"
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'-------------------------------------------------------------------------------
' initializing
'-------------------------------------------------------------------------------
Dim E3Dev As e3.e3Device
Dim oActFile As System.IO.FileInfo
Dim sDevName As String
Dim sArtNr As String
Dim bFound As Boolean
Dim iDevIds() As Object
Dim iDevId As Integer
Dim iSelCount As Integer
Try
If StartUpError = True Then
MsgBox("E3.Series steht nicht zur Verfügung oder kann nicht angesprochen werden.", MsgBoxStyle.Critical, "Programm wird beendet...")
Me.Close()
Else
iSelCount = E3Prj.GetSelectedAllDeviceCount
If iSelCount = 1 Then
bFound = False
E3Dev = E3Prj.CreateDeviceObject
E3Prj.GetSelectedAllDeviceIds(iDevIds)
iDevId = iDevIds(1)
E3Dev.SetId(iDevId)
sDevName = E3Dev.GetComponentName
iDevId = E3Dev.GetId
sArtNr = Mid(sDevName, 1, 7)
oActFile = GetFile(strPdfFolder, sArtNr)
If IsNothing(oActFile) = False Then
bFound = True
Process.Start(oActFile.FullName)
End If
oActFile = GetFile(strDatasheetFolder, sArtNr)
If IsNothing(oActFile) = False Then
bFound = True
Process.Start(oActFile.FullName)
End If
If bFound = False Then
MsgBox("Es wurden keine Daten zum markierten Objekt gefunden!")
End If
E3Dev = Nothing
Me.Close()
End If
End If
Catch ex As Exception
E3Dev = Nothing
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler in frmMain: frmMain_Load")
Me.Close()
End Try
End Sub
Public Function GetFile(ByVal SrcDir As String, ByVal ArtNr As String) As System.IO.FileInfo
Dim oFile As System.IO.FileInfo
Dim oActFile As System.IO.FileInfo = Nothing
Dim oFiles() As System.IO.FileInfo
Dim sSrcString As String
Try
sSrcString = ArtNr & "*"
If System.IO.Directory.Exists(SrcDir) Then
Dim Dir As New System.IO.DirectoryInfo(SrcDir)
oFiles = Dir.GetFiles(sSrcString)
Application.DoEvents()
Else
Return Nothing
End If
If oFiles.Length > 0 Then
For Each oFile In oFiles
If IsNothing(oActFile) = True Then
oActFile = oFile
Else
If oFile.LastWriteTime > oActFile.LastWriteTime Then
oActFile = oFile
End If
End If
Next
Return oActFile
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler in Functions: GetFile")
Return Nothing
End Try
End Function