Bonjour,
Je suis en train de réaliser un logiciel de test d'équipement en VB. Pour tester chaque équipement je dois réaliser deux tests. Le premier test consiste à faire un "ping" vers l'équipement et le deuxième test consiste à faire une inspection visuelle. Pour ce dernier test, l'utilisateur est guidé via une windows form qui lui permet de cocher si tout est OK ou NOK et il peut laisser un commentaire. Si c'est deux tests sont correct, il y a une case d'une checklistbox qui se coche sur la windows form principale.
Le code d’exécution du ping étant codé dans la winform principale, je récupére facilement ce résultat pour le stocker dans une variable. Mon problème provient de la deuxième winform. En effet j'aimerai récupérer la variable qui contient le résultat du test visuelle et le ramener vers la winform principale.
Ce que je voudrais c'est que l'éxécution de mon code de la winform principale soit mis en pause jusqu'à la fermeture de la deuxième winform pour qu'il y ait une sorte de synchro et que je récupère correctement la variable.
Voici le code de la winform principale:
Voici le code de la 2nd winform:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 Private Function Test_Front_Switch() Dim boucle As Boolean = True Dim output As Boolean = False Dim ping_result As Boolean = False Dim buffer As String = "KO" Dim flag As Boolean = True WriteInLog("Starting Front Switch test ...") ProgressTextBox.Text = ProgressTextBox.Text & "Starting Front Switch test ..." & System.Environment.NewLine MsgBox("Please check if the system is powered and linked." & Environment.NewLine & "If it's ok, click Ok", vbInformation, "Prerequisites") WriteInLog("Ping Front Switch...") ProgressTextBox.Text = ProgressTextBox.Text & "Ping Front Switch..." & System.Environment.NewLine While boucle If flag = True Then Try BluetoothPort.Write("Ping Front Switch") flag = False Catch ex As Exception WriteInLog(ex) End Try End If Try buffer = BluetoothPort.ReadExisting() Catch ex As Exception WriteInLog(ex) End Try If buffer = "OK" Then WriteInLog("Front Switch pinged successfully.") ProgressTextBox.Text = ProgressTextBox.Text & "Front Switch pinged successfully." & System.Environment.NewLine MsgBox("Front Switch pinged successfully.", vbInformation, "Test result") boucle = False ping_result = True ElseIf buffer = "KO" Then WriteInLog("Ping Request timed out.") ProgressTextBox.Text = ProgressTextBox.Text & "Ping Request timed out." & System.Environment.NewLine If MsgBox("Ping Failed !" & Chr(13) & Chr(10) & "Check if the system is powered and linked." & Chr(13) & Chr(10) & "Do you want to retry?", vbRetryCancel + MsgBoxStyle.Exclamation) = vbCancel Then boucle = False ping_result = False Else flag = True For x = 2 To 0 Step -1 ProgressTextBox.Text = ProgressTextBox.Text & "Waiting " & x & " seconds..." & System.Environment.NewLine Pause(1) ProgressTextBox.Undo() Next End If End If End While MsgBox("You will begin the Visual Inspection of the Front Switch. Please fill the formular.", vbInformation, "Visual Inspection") inspection_window.Equipment_textbox.Text = "Front switch" '2nd winform inspection_window.Show() 'winform principale Me.Hide() 'Mettre l attente éventuellement ici If ping_result = True And visual_inspection_result = True Then output = True Test_Sum.SetItemChecked(0, True) End If Return output End Function
En attente de vos réponses ou questions si vous avez besoin de plus de précision car je ne sais pas si c'est très clair.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Public Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click If (Pos_box_nok.Checked = True Or Fix_box_nok.Checked = True Or Quality_box_nok.Checked = True Or Ergo_box_nok.Checked = True) And Remarks_textbox.Text = "" Then MsgBox("Please fill the remarks before validation", vbCritical, "Be careful") flag = False ElseIf (Pos_box_nok.Checked = True Or Fix_box_nok.Checked = True Or Quality_box_nok.Checked = True Or Ergo_box_nok.Checked = True) And Len(Remarks_textbox.Text) < 5 Then MsgBox("min. 5 characters", vbCritical, "Be careful") flag = False ElseIf Pos_box_ok.Checked = True And Fix_box_ok.Checked = True And Quality_box_ok.Checked = True And Ergo_box_ok.Checked = True Then flag = True visual_inspection_result = True Bus_10M.Show() Me.Close() End If End Sub
Partager