Reputation: 51
I'm running a script that performs multiple checks on a Windows machine before running a program. I'm running a VBScript script that checks things such as patch status, firewall status, and antivirus software status. After the script runs, the information needs to be output so the end user can fix any issues that arise. This needs to be output in a single message box that shows everything that is not compliant on the end users machine.
Right now after the script runs I'm getting multiple boxes for output, and none of them are displaying the names of what needs to be fixed. I'm just getting the information in quotes in the dialog box.
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
Else
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End if
Next
Upvotes: 1
Views: 1340
Reputation: 614
I think you need to get the return value from the msgbox, i.e., tempresponse = Msgbox("")
. The link is here
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix, tempresponse
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
Else
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
End if
Next
As @Tomalak has said, after each iteration you will need to clear the msgbox. Would a popup
work better, as it will clear the message after x seconds.
Upvotes: 1
Reputation: 338208
My suggestion is to avoid arrays altogether and use the much more convenient dictionaries instead.
If nothing else you will create much more readable code that way, but they are also a lot more powerful than arrays.
Option Explicit
Dim errors
Set errors = CreateObject("Scripting.Dictionary")
' fill the dictionary troughout your program. Fill in just the
' actionables and don't insert the stuff that's okay.
errors("Firewall Status") = "Off"
errors("This other thing") = "Missing"
If errors.Count = 0 Then
MsgBox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", vbOkOnly, "Moka 5 Compliance Check"
Else
Dim item, toFix
For Each item In errors
toFix = toFix & " - " & item & " is " & errors(item) & vbNewLine
Next
Msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention:" & vbNewLine & _
toFix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End If
Upvotes: 1