Results 1 to 8 of 8

Thread: [RESOLVED] Logic jam....

  1. #1

    Thread Starter
    Addicted Member sRLS's Avatar
    Join Date
    Mar 2010
    Location
    Ladson SC
    Posts
    175

    Resolved [RESOLVED] Logic jam....

    I am trying to make some logic that will evaluate a set of rules and then report via msgbox or a userform (which ever is best) the variables that are "False".

    Code:
            If sLbFlag1 = False OrElse
                sTbFlag2 = False OrElse
                sTbFlag3 = False OrElse
                sTbFlag4 = False OrElse
                sTbFlag5 = False Then
                MsgBox("Incomplete data on form.")
            Else
                'Code removed cause its TSNS (Top Secret Ninja Stuff).
            End IF
    In the above once a user submits via button on a form any of the flags that are set to "False" I would want to display what needs to be taken care of.
    sLbFlag1 = ListBox1
    sTbFlag2 = TextBox2
    sTbFlag3 = TextBox3
    sTbFlag4 = TextBox4
    sTbFlag5 = TextBox5

    Such as assuming; sTbFlag2 and sTbFlag5 are "False" then the message would be something like:
    "TextBox2 and TextBox5 must be completed to continue."

    Any hints, tips or examples are appreciated.
    Regards

    Rick
    VS 2022, Office365, Win10
    I became insane, with long bouts of horrible sanity!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Logic jam....

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim msg As String = ""
    3.     msg &= If(ListBox1.Items.Count = 0, "Listbox1, ", "")
    4.     msg &= If(TextBox2.Text = "", "TextBox2, ", "")
    5.     msg &= If(TextBox3.Text = "", "TextBox3, ", "")
    6.     msg &= If(TextBox4.Text = "", "TextBox4, ", "")
    7.     msg &= If(TextBox5.Text = "", "TextBox5, ", "")
    8.     If msg <> "" Then MsgBox(msg & " need to be completed", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, My.Application.Info.Title)
    9. End Sub

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Logic jam....

    It is unlikely that there is any way around this. You would just have to run through it in some fashion like this:
    Code:
    If sLbFlag1 = False Then
     'Set the message for this one.
    ElseIf sLbFlag2 = False Then
     'Set the message for this one.
    'etc.
    Alternatively, you could build a more complicated result by testing each one in turn:

    Code:
    Dim sb as New StringBuilder
    If sLbFlag1 = False Then
     sb.Append(<your message> & Environment.NewLine)
    End If
    If sLbFlag2 = False
      sb.Append('etc)
    End If
    This would build a string with ALL the issues.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Addicted Member sRLS's Avatar
    Join Date
    Mar 2010
    Location
    Ladson SC
    Posts
    175

    Re: Logic jam....

    Quote Originally Posted by .paul. View Post
    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim msg As String = ""
    3.     msg &= If(ListBox1.Items.Count = 0, "Listbox1, ", "")
    4.     msg &= If(TextBox2.Text = "", "TextBox2, ", "")
    5.     msg &= If(TextBox3.Text = "", "TextBox3, ", "")
    6.     msg &= If(TextBox4.Text = "", "TextBox4, ", "")
    7.     msg &= If(TextBox5.Text = "", "TextBox5, ", "")
    8.     If msg <> "" Then MsgBox(msg & " need to be completed", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, My.Application.Info.Title)
    9. End Sub
    Thats cool!
    I made a minor change:
    Code:
    msg &= If(ListBox1.Items.Count = 0, "Listbox1, ", "")
    is now
    Code:
    msg &= If(ListBox1.SelectedItem = "", "Listbox1, ", "")
    It works with my If, Else, then stuff to set the flag status.
    Regards

    Rick
    VS 2022, Office365, Win10
    I became insane, with long bouts of horrible sanity!

  5. #5

    Thread Starter
    Addicted Member sRLS's Avatar
    Join Date
    Mar 2010
    Location
    Ladson SC
    Posts
    175

    Re: [RESOLVED] Logic jam....

    To understand what Paul did, the "msg &=" is what appends any and or all of the instances in the msgbox?
    Regards

    Rick
    VS 2022, Office365, Win10
    I became insane, with long bouts of horrible sanity!

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [RESOLVED] Logic jam....

    the msg &= part either appends the control name or nothing to the string depending on the conditional part of the if

    if(conditional part, truePart, falsePart)

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] Logic jam....

    Try this:
    vb.net Code:
    1. Dim flags() As Boolean = {sLbFlag1, sLbFlag2, sLbFlag3, sLbFlag4, sLbFlag5}
    2. Dim controls() As Control = {ListBox1, TextBox2, TextBox3, TextBox4, TextBox5}
    3. If flags.Contains(False) Then
    4.     Dim msg As String = "Following must be completed to continue:" & vbCrLf
    5.     For i = 0 To flags.Count - 1
    6.         If Not flag Then msg &= controls(i).Name & vbCrLf
    7.     Next
    8.     MessageBox.Show(msg)
    9. Else
    10.     'Code removed cause its TSNS (Top Secret Ninja Stuff).
    11. End If
    (NB: freehand typed untested code; might contain typos)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8

    Thread Starter
    Addicted Member sRLS's Avatar
    Join Date
    Mar 2010
    Location
    Ladson SC
    Posts
    175

    Re: [RESOLVED] Logic jam....

    Thanks to all who contributed!

    Pradeep1210
    I'm going to check out your code as well, no harm in learning something new.
    Regards

    Rick
    VS 2022, Office365, Win10
    I became insane, with long bouts of horrible sanity!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width