0 Or InStr(currentoption,"SHIM")>0 Then MsgBox "INSTALLER SHIM ET/OU INTUMESCENT ( VOIR W.O. ET CARTABLE INSTRUCTION I" /> 0 Or InStr(currentoption,"SHIM")>0 Then MsgBox "INSTALLER SHIM ET/OU INTUMESCENT ( VOIR W.O. ET CARTABLE INSTRUCTION I" /> 0 Or InStr(currentoption,"SHIM")>0 Then MsgBox "INSTALLER SHIM ET/OU INTUMESCENT ( VOIR W.O. ET CARTABLE INSTRUCTION I"/>
If InStr(currentoption,"INTUM")>0 Or InStr(currentoption,"SHIM")>0  Then
  MsgBox "INSTALLER SHIM ET/OU INTUMESCENT ( VOIR W.O. ET CARTABLE INSTRUCTION INSTALLATION DE SHIM ET INTUMESCENT.)" ,vbExclamation
End If

everytime we have this option in the program it creates multiple msgbox pop ups as it reads all the lines. Is there a way to eliminate that . Please ask me if you need more information. I am really a beginner with this language and trying to learn own my own.

1

There are 1 best solutions below

0
Étienne Laneville On

Like @LesFerch suggested, you can create a variable that tracks if the warning has been shown or not. You initialize it as False and then, after showing the warning, you set it to True. Before displaying the warning (MsgBox), check the state of that variable to see if the warning has already been displayed:

Dim bWarningShown
Dim iUserResponse
Dim iLineCounter

' Initialize warning shown as false
bWarningShown = False

For iLineCounter = 1 To 10
    
    If InStr(currentoption, "INTUM") > 0 Or InStr(currentoption, "SHIM") > 0 Then
        If Not bWarningShown Then
            iUserResponse = MsgBox("INSTALLER SHIM ET/OU INTUMESCENT ( VOIR W.O. ET CARTABLE INSTRUCTION INSTALLATION DE SHIM ET INTUMESCENT.)", vbExclamation + vbOKCancel)
            bWarningShown = True
            If iUserResponse = vbCancel Then
                ' Exit line reading loop
                Exit For
            End If
        End If
        
    End If

Next

MsgBox iLineCounter

Going further, you can also give the user the option to cancel out of the line-reading loop so they can immediately fix the problem that triggers the warning. This is done by displaying Yes/Cancel buttons on the message box using vbOKCancel in addition to vbExclamation. Once the user has clicked Yes or Cancel, the button they clicked will be saved in the iUserResponse variable. You can then check if they clicked Cancel and exit your loop. In this sample, I created a simple For loop that goes from 1 to 10 to demonstrate how I would exit that loop. I display iLineCounter at the end of the loop to demonstrate that if you click OK, the loop will complete its 10 iterations but if you hit Cancel, it will exit right away (iLineCounter will be 1).