Объединить несколько строк в один msgbox - PullRequest
0 голосов
/ 12 марта 2019

с помощью приведенного ниже кода у меня есть ряд шагов проверки.В настоящее время, если пользователь пропускает 1 или более входных данных и / или вводит неверные данные, он получает несколько сообщений.Не очень хороший пользовательский интерфейс, я собираюсь объединить эти строки в один msgbox.Имейте в виду, что я не могу сделать это, используя System.Text и т. Д. Для генерации строителя строк с использованием append.

Я относительно новичок в vba, поэтому, если вы оставите какие-либо комментарии или отзывы, если вы сможете это объяснитькак можно полнее.

Public Function ValidateMe(strAccNum As String, iDte As Integer, strTRS As String, strPrem As String) As Boolean
    ' Function tests each input passed to it and validates it. If there is an issue the user is notified with a message box.
    Dim blnValAcc As Boolean
    Dim blnValDte As Boolean
    Dim blValTRS As Boolean
    Dim blnValPrem As Boolean
    Dim blnValidOverall As Boolean

    ' Default to Invalid
    blnValAcc = False
    blnValDte = False
    blnValTRS = False
    blnValPrem = False
    blnValidOverall = False

    ' Validate Account Number
    Dim strMessage As String
    Dim strSortCode As String
    strMessage = ""
    strSortCode = Left(strAccNum, 6)

    ' AccNum must be 14 characters long and all characters must be numeric
    If (Len(strAccNum) = 14 And (IsNumeric(strAccNum) = True)) Then
        blnValAcc = True
    Else:
        strMessage = strMessage & vbNewLine & "Account Number must be 14 characters long and contain only numeric characters."
    End If

    ' 8 and 10 digit account nubmers cannot have a due date change
    If (Len(strAccNum) = (8 Or 10) And (IsNumeric(strAccNum) = True)) Then
        blnValAcc = False
        strMessage = strMessage & vbNewLine & "8 and 10 digit account numbers cannot have a due date change."
    End If

    ' Checks sort code against list of sort codes if the accout number has already passed previous tests
    If blnValAcc = True Then
        blnValAcc = CheckSortCode(strSortCode)
        If blnValAcc = False Then
            strMessage = strMessage & "Check sort code."
        End If
    End If

    If blnValAcc = False Then
        MsgBox strMessage, , "Check Account Number"
    End If

    ' Validate new Due Date
    If (iDte >= 1 And iDate <= 31) Then
        blnValDte = True
    Else:
        blnValDte = False
        MsgBox "Please enter a valid due date, a number between 1 and 31", , "Invalid Date"
    End If

    If ((strTRS = "Yes") Or (strTRS = "No")) Then
        blnValTRS = True
    End If

    ' Validate strPrem
    If strPrem = "Yes" Then
        blnValPrem = True
    Else:
        MsgBox "Customer must be advised of how change may affect premiums.", , "Premium Changes"
    End If

    ' Validate strTRS
    If strTRS = "" Then
        valTRS = False
        MsgBox "Please select an option from the drop down menu.", , "Customer has been advised of TRS implications?"
    End If

    If ((blnValAcc = True) And (blnValDte = True) And (blnValTRS = True) And (blnValPrem = True)) Then
        blnValidOverall = True
    End If

    ' Function returns true or false
    ValidateMe = blnValidOverall

End Function

1 Ответ

2 голосов
/ 12 марта 2019

Базовая модель:

Dim msg as string

If someProblem1 then
    msg = msg & iif(len(msg) > 0, vbLf, "") & "Problem1 description"
end if

if someProblem2 then
    msg = msg & iif(len(msg) > 0, vbLf, "") & "Problem2 description"
end if

'etc etc


'done testing...
if len(msg) > 0 then
    msgbox "There are some problems with your submission:" & vbLf & vbLf & msg,, "Oops"

end if

ValidateMe = (Len(msg) = 0)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...