AdvancedHMI Software
General Category => Support Questions => Topic started by: Cowboy1 on August 23, 2015, 03:27:08 PM
-
I have a list of additions of boil addition that are made up of labels. I want them to display in a message box when it is time for the add.
Count down timer is displayed by this code and a datasubscriber reading a register.
Private Sub DataSubscriber1_DataChanged_1(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
Dim ts As TimeSpan = TimeSpan.FromSeconds(e.Values(0))
Dim mydate As DateTime = New DateTime(ts.Ticks)
Label5.Text = mydate.ToString(("HH:mm:ss"))
End Sub
I tried the following code with no results:
Private L12 As String
Private L41 As String
Private L61 As String
Private Sub Label5_TextChanged(sender As Object, e As EventArgs) Handles Label5.TextChanged
L12 = Label12.Text
L41 = Label41.Text
L61 = Label61.Text
If Label51.Text > "" And Label51.Text = Label5.Text Then
System.Windows.Forms.MessageBox.Show("Perform" & L12 & L41 & L61, "1st. Boil Addition?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
I have attached a screenshot hopefully that will help with explanation.
What I want is when the time in label 5 = label 51 display a message box that states " Perform 1st Addition .75oz. Hallertauer Magnum"
I will need this to happen for each of the additions below as long as they are not blank. I have 0 minute additions when brewing.
Any Help would be greatly appreciated. I hope I'm not to far off with the code above. I'm really trying to learn but it doesn't have any reaction when the times are met.
Thanks,
David
-
Ok I got it and I'm sure this isn't the cleanest solution but I muddled through it. If anybody knows how to clean this up a bit that would be very useful. I have to do this 10 more times. Thanks.
[/ Private Sub Label5_TextChanged(sender As Object, e As EventArgs) Handles Label5.TextChanged
'Create a variable to store your Date'
Dim previousDate As DateTime
Dim currentDate As DateTime
Dim L12 As String
Dim L12a As String
Dim L41 As String
Dim L41a As String
Dim L61 As String
L12 = Label12.Text
L12a = " "
L41 = Label41.Text
L41a = " of "
L61 = Label61.Text
'Attempt to read the value from your Date and ensure it is correct'
If DateTime.TryParse(Label51.Text, previousDate) AndAlso DateTime.TryParse(Label5.Text, currentDate) Then
'The dates could be read successfully, so compare them'
If previousDate = currentDate Then
System.Windows.Forms.MessageBox.Show("Perform " & L12 & L12a & L41 & L41a & L61, "1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
End Subcode]
Attached screenshot
-
Just a quick look at the code in your first post and this is one thing I see that may be a problem:
If Label51.Text > "" And Label51.Text = Label5.Text Then
Try changing to :
If NOT String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
-
Just a quick look at the code in your first post and this is one thing I see that may be a problem:
If Label51.Text > "" And Label51.Text = Label5.Text Then
Try changing to :
If NOT String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
Archie thanks, I will try this tonight looks much cleaner then my route.
Is there a better way of getting all the labels and text into my message box?
I have been reading on arrays but don't have a good understanding of the function.
Is there a way I can force the input of a textbox to be time formatted? Example 00:00:00 if not in this format error.
I want to use a textbox on my Batch set-up screen to export boil additions to the labels on the boil screen.
-
Just a quick look at the code in your first post and this is one thing I see that may be a problem:
If Label51.Text > "" And Label51.Text = Label5.Text Then
Try changing to :
If NOT String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
Code works perfectly thanks for your help with this. I'm still working on getting the data formatted. I'm using a masked textbox and that allows me to set the format I want but having issues when I send it to other forms. I have a error break, it says check PLC connections. See attached code:
[/ Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PreCleanScreen.TextBox3.Text = TextBox1.Text
MainForm.TextBox3.Text = TextBox1.Text
MashScreen.TextBox3.Text = TextBox1.Text
SpargeScreen.TextBox3.Text = TextBox1.Text
BoilScreen.TextBox3.Text = TextBox1.Text
ChillScreen.TextBox3.Text = TextBox1.Text
FinishClean.TextBox3.Text = TextBox1.Text
PreCleanScreen.TextBox1.Text = TextBox2.Text & " Gallons"
MainForm.TextBox1.Text = TextBox2.Text & " Gallons"
MashScreen.TextBox1.Text = TextBox2.Text & " Gallons"
SpargeScreen.TextBox1.Text = TextBox2.Text & " Gallons"
BoilScreen.TextBox1.Text = TextBox2.Text & " Gallons"
ChillScreen.TextBox1.Text = TextBox2.Text & " Gallons"
FinishClean.TextBox1.Text = TextBox2.Text & " Gallons"
PreCleanScreen.TextBox2.Text = DateTimePicker1.Text
BoilScreen.Label41.Text = TextBox49.Text
BoilScreen.Label51.Text = MaskedTextBox1.Text
BoilScreen.Label61.Text = TextBox50.Text
End Subcode]
This code is on my batch set-up screen and sends data to the other forms.
-
Just a quick look at the code in your first post and this is one thing I see that may be a problem:
If Label51.Text > "" And Label51.Text = Label5.Text Then
Try changing to :
If NOT String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
Archie,
The code works perfect for the first addition but not for the second I will have up to 10 additions in a batch. Is there a way to make this work or do I need to change my process?
Private Sub Label5_TextChanged(sender As Object, e As EventArgs) Handles Label5.TextChanged
'Create a variable to store your Date'
Dim previousDate As DateTime
Dim currentDate As DateTime
Dim L12 As String
Dim L12a As String
Dim L41 As String
Dim L41a As String
Dim L61 As String
Dim L13 As String
Dim L40 As String
Dim L60 As String
L12 = Label12.Text
L12a = " "
L41 = Label41.Text
L41a = " of "
L61 = Label61.Text
L13 = Label13.Text
L40 = Label40.Text
L60 = Label60.Text
If NOT String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & L12 & L12a & L41 & L41a & L61, "1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
If Not String.IsNullOrEmpty(Label50.Text) AndAlso String.Compare(Label50.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & L13 & L12a & L40 & L41a & L60, "2nd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
-
I tried simplifying the code to help me understand exactly what you are trying to do. Does this look right:
'* Does Label51 (1st addition time) have a value? Is it equal to the time remaining?
If Not String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label12.Text & " " & Label41.Text & " " & Label61.Text,
"1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'* Does Label50 (2nd addition time) have a value? Is it equal to the time remaining?
ElseIf Not String.IsNullOrEmpty(Label50.Text) AndAlso String.Compare(Label50.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label13.Text & " " & Label40.Text & " " & Label60.Text,
"2nd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Also are you using a timer to update Label5? If so, what is the interval? If you are using 1000 interval, keep in mind the timers are non-deterministic, so they could skip seconds.
-
Archie,
What you have there looks right.
Couple of things that might need consideration:
1. I can have multiple additions that would be made at any time including 00:00:00.
2. I could have up to 10 additions in a batch.
Label 5 is updated by a datasubscriber:
Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs)
Dim ts As TimeSpan = TimeSpan.FromSeconds(e.Values(0))
Dim mydate As DateTime = New DateTime(ts.Ticks)
Label5.Text = mydate.ToString(("HH:mm:ss"))
End Sub
Driver Poll rate=500
Datasubscriber1 Poll rate=0
Thanks,
David
-
Archie,
I think this code will work but for some reason my poll rate is around 7 seconds? Do you think this code would slow it down that much? I have had great speed up until now.
Private Sub Label5_TextChanged(sender As Object, e As EventArgs) Handles Label5.TextChanged
If Not String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label12.Text & " " & Label41.Text & " " & Label61.Text, "1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label50.Text) AndAlso String.Compare(Label50.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label13.Text & " " & Label40.Text & " " & Label60.Text, "2nd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label49.Text) AndAlso String.Compare(Label49.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label14.Text & " " & Label39.Text & " " & Label59.Text, "3rd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label48.Text) AndAlso String.Compare(Label48.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label15.Text & " " & Label38.Text & " " & Label58.Text, "4th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label47.Text) AndAlso String.Compare(Label47.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label16.Text & " " & Label37.Text & " " & Label57.Text, "5th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label46.Text) AndAlso String.Compare(Label46.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label17.Text & " " & Label36.Text & " " & Label56.Text, "6th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label45.Text) AndAlso String.Compare(Label45.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label18.Text & " " & Label35.Text & " " & Label55.Text, "7th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label44.Text) AndAlso String.Compare(Label44.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label19.Text & " " & Label34.Text & " " & Label54.Text, "8th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label43.Text) AndAlso String.Compare(Label43.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label24.Text & " " & Label33.Text & " " & Label53.Text, "9th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not String.IsNullOrEmpty(Label42.Text) AndAlso String.Compare(Label42.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label20.Text & " " & Label29.Text & " " & Label52.Text, "10th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
-
I think this code will work but for some reason my poll rate is around 7 seconds? Do you think this code would slow it down that much? I have had great speed up until now.
7 seconds is extremely slow. Something is definitely not right. I would put an Exit Sub at the top of each one of your subroutines to see if the update rate gets better. If it doesn't then there could be some inefficiency in the communications. You may need to install a serial port monitor to see what is happening with the communications.
-
At one point in time, too many sequential ElseIf's didn't work properly for me.
You don't have anything to loose by trying to use a code like this:
Private Sub Label5_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Label5.TextChanged
If Not String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label12.Text & " " & Label41.Text & " " & Label61.Text, "1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label50.Text) AndAlso String.Compare(Label50.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label13.Text & " " & Label40.Text & " " & Label60.Text, "2nd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label49.Text) AndAlso String.Compare(Label49.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label14.Text & " " & Label39.Text & " " & Label59.Text, "3rd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label48.Text) AndAlso String.Compare(Label48.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label15.Text & " " & Label38.Text & " " & Label58.Text, "4th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label47.Text) AndAlso String.Compare(Label47.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label16.Text & " " & Label37.Text & " " & Label57.Text, "5th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label46.Text) AndAlso String.Compare(Label46.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label17.Text & " " & Label36.Text & " " & Label56.Text, "6th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label45.Text) AndAlso String.Compare(Label45.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label18.Text & " " & Label35.Text & " " & Label55.Text, "7th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label44.Text) AndAlso String.Compare(Label44.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label19.Text & " " & Label34.Text & " " & Label54.Text, "8th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label43.Text) AndAlso String.Compare(Label43.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label24.Text & " " & Label33.Text & " " & Label53.Text, "9th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If Not String.IsNullOrEmpty(Label42.Text) AndAlso String.Compare(Label42.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label20.Text & " " & Label29.Text & " " & Label52.Text, "10th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Sub
or like this:
Private Sub Label5_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Label5.TextChanged
If Not String.IsNullOrEmpty(Label51.Text) AndAlso String.Compare(Label51.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label12.Text & " " & Label41.Text & " " & Label61.Text, "1st. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label50.Text) AndAlso String.Compare(Label50.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label13.Text & " " & Label40.Text & " " & Label60.Text, "2nd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label49.Text) AndAlso String.Compare(Label49.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label14.Text & " " & Label39.Text & " " & Label59.Text, "3rd. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label48.Text) AndAlso String.Compare(Label48.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label15.Text & " " & Label38.Text & " " & Label58.Text, "4th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label47.Text) AndAlso String.Compare(Label47.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label16.Text & " " & Label37.Text & " " & Label57.Text, "5th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label46.Text) AndAlso String.Compare(Label46.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label17.Text & " " & Label36.Text & " " & Label56.Text, "6th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label45.Text) AndAlso String.Compare(Label45.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label18.Text & " " & Label35.Text & " " & Label55.Text, "7th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label44.Text) AndAlso String.Compare(Label44.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label19.Text & " " & Label34.Text & " " & Label54.Text, "8th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label43.Text) AndAlso String.Compare(Label43.Text, Label5.Text, True) = 0 Then
System.Windows.Forms.MessageBox.Show("Perform " & Label24.Text & " " & Label33.Text & " " & Label53.Text, "9th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If Not String.IsNullOrEmpty(Label42.Text) AndAlso String.Compare(Label42.Text, Label5.Text, True) = 0 Then System.Windows.Forms.MessageBox.Show("Perform " & Label20.Text & " " & Label29.Text & " " & Label52.Text, "10th. Boil Addition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Sub
You can remove all "Exit Sub" lines if you need each of these conditions to be checked.
-
Thanks Godra and Archie for the code provided. I know they both work but I had polling problems, so I have removed the code for batch additions believing it was causing long poll times since I noticed it after trying the code. After removing it and writing it into the PLC program, I still have long polling times @ >6 seconds. The PLC is very responsive just not the display. Is there any way you know that I can find my problem I have 8 forms in this project? If I should create another post for polling problem just let me know and I will start a new thread.
Thanks,
David
-
On the default MainForm, if you look at the code behind there is a code snippet that will pause communications for that form when it is hidden. If you have forms that do not need to update when hidden, putting that code with those forms will help the update rate.
About how many registers are you reading? Are they somewhat consecutive or scattered about different addresses?
-
Archie,
The pause forms from polling was a huge help.
On my 6 main screens
Batch Set-Up = 35 data points polling < 1sec
Fill and Heat = 46 data points polling < 1 sec
Mash = 85 data points polling 1 - 2 seconds -messagebox sound delayed
Sparge = 57 data points polling < 1 sec
Boil = 68 data points polling 1 - 2 seconds - message box sounds delayed.
Chill = 35 data points polling < 1 sec
Total running prior to pausing hidden forms was 326 guess that might slow updates.
Thanks for your help,
David