puipuich
Messages postés2Date d'inscriptionjeudi 14 avril 2005StatutMembreDernière intervention31 août 2009
-
31 août 2009 à 15:44
puipuich
Messages postés2Date d'inscriptionjeudi 14 avril 2005StatutMembreDernière intervention31 août 2009
-
31 août 2009 à 15:53
Bonjour à tous !!!
Je post pour la première fois ici car (là) je suis bloqué avec un problème à la con.
Pour faire court (je donnerais des détails si besoin sur le contexte) je suis en stage en Tchéquie. On m'a confié le développement d'un affichage d'un compteur de prod.
Pour cela je viens récupérer le nombre de pièce sortie de ligne dans un fichier Excel de traçabilité. A la fermeture de ce dernier j'exporte cette donnée déjà existante dans un fichier texte (ça, ça marche !!!)
Ensuite j'ai développé une interface sur VB 2008 Express qui me permet d'afficher :
- l'heure
- le compteur de prod total (provenant du fichier texte)
- l'objectif de prod total et pour une heure (provenant de deux autres fichier texte)
- un compteur de prod par heure (calculer avec remise à zéro auto à chaque heure).
Nous arrivons au problème : de temps en temps (de manière irrégulière) le compteur plante mais l'heure tourne encore. Une personne du service informatique (en France) pense que cela vient du fichier texte pas totalement fermé (ou mal).
Pouvez-vous m'aider pour trouver comment faire pour vérifier la bonne fermeture du fichier texte ?
Et avez-vous d'autre piste.
Etant novice ici je vais essayer de joindre mon code.
Je vous remercie pour votre aide à l'avance.
Puipuich
P.S : Désolée pour mon codage un peu brute et pas très propre je pense.
Pour sauver les arbres, manger des castors
Code :
Imports System.IO
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim num1 As String
Dim num2 As String
Dim num3 As String = "0"
Dim num4 As String
Dim ValTemp As String
Dim i As Boolean
Dim adrExport As String
Dim adrTarget As String
Dim adrTargetH As String
Dim res As MsgBoxResult
Me.Show()
Timer1.Interval = 1000
Timer1.Start()
Label1.Refresh()
Label2.Refresh()
adrExport = "\\10.65.2.2\sys\export.txt"
adrTarget = "\\10.65.2.2\sys\Target.txt"
adrTargetH = "\\10.65.2.2\sys\TargetH.txt"
'MsgBox(adrExport & Chr(13) & adrTarget)
i = False
While i = False
ValTemp = Label1.Text
num1 = lire_txt(adrExport, Label1.Text)
num2 = lire_txt(adrTarget, Label2.Text)
num4 = lire_txt(adrTargetH, Label5.Text)
'MsgBox(num)
If num1 <> "" And num2 <> "" And num4 <> "" Then
Label1.Text = -(num2 - num1)
Label2.Text = num2
Label5.Text = num4
'MsgBox(Microsoft.VisualBasic.Right(Microsoft.VisualBasic.Left(Label3.Text, 5), 2))
If Microsoft.VisualBasic.Right(Microsoft.VisualBasic.Left(Label3.Text, 5), 2) = "00" _
And num3 <> "0" Then
num3 = "0"
ElseIf ValTemp <> CStr(-(CInt(num2) - CInt(num1))) Then
num3 = CStr(CInt(num3) + 1)
End If
Label4.Text = num3
Label1.Refresh()
Label2.Refresh()
Label4.Refresh()
Label5.Refresh()
Call xWait(60000)
Else
res = MsgBox("There are no files for screening count", MsgBoxStyle.OkOnly)
If res = MsgBoxResult.Ok Then
End
End If
End If
'i = True
End While
End Sub
Function lire_txt(ByVal adr As String, ByVal temp As String) As String
Dim value As String = Nothing
Dim reader As String = String.Empty
Dim p() As Process
Dim r As Process
'kill the notepad process
p = Process.GetProcessesByName("notepad")
For Each r In p
r.CloseMainWindow()
Next
Try
Try
Try
Using sr As StreamReader = New StreamReader(adr)
reader = sr.ReadLine()
value = reader
End Using
Catch ex As System.IO.IOException
GoTo suite2
End Try
Catch ex As System.IO.DirectoryNotFoundException
GoTo suite
End Try
Catch ex As System.IO.FileNotFoundException
GoTo suite
End Try
Return value
Exit Function
suite:
value = temp
Return value
Exit Function
suite2:
' Let the user know that the directory did not exist.
value = temp
Using sr As Stream = File.OpenRead(adr)
sr.Close()
End Using
Return value
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Me.Close()
End
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label3.Text = Now.ToLongTimeString 'Affiche l'heure format long.
End Sub
End Class
Imports System.IO
Module Module1
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub xWait(ByVal MilsecToWait As Long)
Dim lngEndingTime As Long
lngEndingTime = GetTickCount() + (MilsecToWait)
Do While GetTickCount() < lngEndingTime
My.Application.DoEvents()
Loop
End Sub