Author Topic: Embedded variables  (Read 12179 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Embedded variables
« Reply #15 on: August 23, 2018, 10:05:41 PM »
I am not completely sure about this one but the code below might be working.

Add the "Else" part to the Private Sub PLCDS_DataChanged inside the ctrlMultiState control:

Code: [Select]
    Private Sub PLCDS_DataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)

        If Not Me.DesignMode Then

            For i = 0 To m_EmbeddedVariables.Count - 1
                If m_EmbeddedVariables.Count > 0 Then
                    If e.PlcAddress = m_EmbeddedVariables(i).Name Then

                        If e.Values(0) IsNot Nothing Then

                            If m_EmbeddedVariables(i).Type = AHMI_v1.PLCItems.DataType.PartialString Then
                                m_EmbeddedVariables(i).Value = ExtractString(e.Values(0))
                            Else
                                m_EmbeddedVariables(i).Value = e.Values(0)
                            End If

                        Else

                            If m_EmbeddedVariables(i).Type = AHMI_v1.PLCItems.DataType.PartialString OrElse m_EmbeddedVariables(i).Type = AHMI_v1.PLCItems.DataType.FullString Then
                                m_EmbeddedVariables(i).Value = " "
                            End If

                        End If
                    End If
                    Update_Embedded_Variables()
                End If
            Next

        End If

    End Sub


« Last Edit: August 28, 2018, 11:52:19 PM by Godra »

Arvanoss

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Embedded variables
« Reply #16 on: August 27, 2018, 08:46:44 AM »
Godra,

Thanks for looking at this, I added the Else statement then put a breakpoint in the routine.  Looking at the Code the Else statement would never be seen as I believe that the "e.Values(0) IsNot Nothing" is never nothing even if the value is a blank field.

I single stepped through more of the program and found in the "Update_Embedded_Variables()" is where what gets displayed is updated per the data from the field.  I single stepped around in this loop until I was able to catch what was happening.
In the following code the FinalString does get set to the Blank data as expected but on the next loop is set back to the OriginalString because it is Blank.

Code: [Select]
                    If FinalString = "" Then
                        FinalString = OriginalString.Replace("{#" & i & "}", m_EmbeddedVariables(i).Value)
                    Else
                        FinalString = FinalString.Replace("{#" & i & "}", m_EmbeddedVariables(i).Value)
                    End If
                    MessageStrings(index) = FinalString

To fix the issue I added this code to the Else portion of the statement. 

Code: [Select]
                        If FinalString = "" Then FinalString = " "

So far it appears to be working, I used a few characters for the testing but the " " is the end result I needed.

Thanks
Randy

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Embedded variables
« Reply #17 on: August 29, 2018, 12:00:21 AM »
Cool.

I didn't test it properly so my code probably isn't working.
At least it got you started and, with the smart stepping through the code, find a proper solution.

jimtech1967

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Embedded variables
« Reply #18 on: November 30, 2020, 09:20:24 AM »
I am looking to display values from a SLC500 and embed in in my MessageDisplayByValue message collection
Registers like N7:1, N7:2 Etc..
How do i set up the .ini file and where do I put it ??
I am electrician that works with PLCs Not Visual Studio.
I have the AdvancedHMI working and communicating to my plcs but would like to
embed variables in the MessageDisplayByValue

MajorFault

  • Guest
Re: Embedded variables
« Reply #19 on: November 30, 2020, 01:22:23 PM »
The MessageDisplayByValue can't do what you want.  You will either need to use a custom control, which already exist and are on this forum, or will need to just use a label and create your own text using subscriptions and lookup tables.  If you don't have experience with VS this may be a tough one.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Embedded variables
« Reply #20 on: November 30, 2020, 01:37:04 PM »
jimtech1967,

Each of the messages is displayed depending on the predetermined value so since you know what the value is then just include it in the message itself.
It is the easiest approach and doesn't require any special knowledge of Visual Studio.
« Last Edit: November 30, 2020, 06:23:42 PM by Godra »

MajorFault

  • Guest
Re: Embedded variables
« Reply #21 on: November 30, 2020, 04:02:57 PM »
One of us is confused. 😁

An embedded variable is not predetermined and changes so you can't enter ahead of time. So I guess the question is does the value you want to enter change constantly?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Embedded variables
« Reply #22 on: November 30, 2020, 06:23:11 PM »
It could be me but let's wait for jimtech1967 to confirm what he wants exactly.