|
-
Feb 4th, 2011, 03:22 PM
#1
Thread Starter
Addicted Member
[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!
-
Feb 4th, 2011, 03:42 PM
#2
Re: Logic jam....
try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim msg As String = ""
msg &= If(ListBox1.Items.Count = 0, "Listbox1, ", "")
msg &= If(TextBox2.Text = "", "TextBox2, ", "")
msg &= If(TextBox3.Text = "", "TextBox3, ", "")
msg &= If(TextBox4.Text = "", "TextBox4, ", "")
msg &= If(TextBox5.Text = "", "TextBox5, ", "")
If msg <> "" Then MsgBox(msg & " need to be completed", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, My.Application.Info.Title)
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 4th, 2011, 03:48 PM
#3
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
 
-
Feb 4th, 2011, 03:56 PM
#4
Thread Starter
Addicted Member
Re: Logic jam....
 Originally Posted by .paul.
try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim msg As String = "" msg &= If(ListBox1.Items.Count = 0, "Listbox1, ", "") msg &= If(TextBox2.Text = "", "TextBox2, ", "") msg &= If(TextBox3.Text = "", "TextBox3, ", "") msg &= If(TextBox4.Text = "", "TextBox4, ", "") msg &= If(TextBox5.Text = "", "TextBox5, ", "") If msg <> "" Then MsgBox(msg & " need to be completed", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, My.Application.Info.Title) 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!
-
Feb 4th, 2011, 04:09 PM
#5
Thread Starter
Addicted Member
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!
-
Feb 4th, 2011, 04:28 PM
#6
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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 4th, 2011, 04:59 PM
#7
Re: [RESOLVED] Logic jam....
Try this:
vb.net Code:
Dim flags() As Boolean = {sLbFlag1, sLbFlag2, sLbFlag3, sLbFlag4, sLbFlag5} Dim controls() As Control = {ListBox1, TextBox2, TextBox3, TextBox4, TextBox5} If flags.Contains(False) Then Dim msg As String = "Following must be completed to continue:" & vbCrLf For i = 0 To flags.Count - 1 If Not flag Then msg &= controls(i).Name & vbCrLf Next MessageBox.Show(msg) Else 'Code removed cause its TSNS (Top Secret Ninja Stuff). End If
(NB: freehand typed untested code; might contain typos)
-
Feb 5th, 2011, 10:03 AM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|