Recent Posts

Pages: [1] 2 3 ... 10
1
Support Questions / Re: Read string in UDT
« Last post by Larry Griffin on September 20, 2017, 03:19:54 PM »
It worked perfect, first time.  I also added an override for ToString() so I can easily read values back out of it.

Code: [Select]
    public class String20
    {
        public int Length;
        public System.SByte[] Characters;

        public String20()
        {
            Characters = new System.SByte[20];
        }

        public String20(string value) : this()
        {
            Length = Math.Min(20, value.Length);
            if (value.Length > 20)
            {
                value = value.Substring(0, 20);
            }
            byte[] TmpArray = new byte[20];
            System.Text.ASCIIEncoding.ASCII.GetBytes(value).CopyTo(TmpArray, 0);
            Characters = (sbyte[])(Array)TmpArray;
        }

        public override string ToString()
        {
            return System.Text.Encoding.ASCII.GetString(Array.ConvertAll(Characters, a => (byte)a));
        }
    }

Thank you so much for the help.  Would be nice if custom strings could be automatically handled by .WriteUDT, but this is workable for now.
Looking forward to .ReadUDT too.  Soon?

LarGriff
2
Support Questions / Re: Read string in UDT
« Last post by Archie on September 19, 2017, 07:10:22 PM »
Treat you custom strings as nested UDTs. Here is an example class for String20 that will make things easier:
Code: [Select]
   class String20
    {
        public int Length;
        public System.SByte[] Characters;

        public String20()
            {
            Characters = new System.SByte[20];
            }

        public String20(string value) : this()
        {
            SetValue(value);
        }


        public void SetValue(string value)
        {
            Length =Math.Min(20, value.Length);
            if (value.Length >20)
                    {
                value = value.Substring(0, 20);
            }
            // WriteUDT does not support byte, so we have to do a little rework here
            byte[] TmpArray= new byte[20];
            System.Text.ASCIIEncoding.ASCII.GetBytes(value).CopyTo(TmpArray, 0);
            Characters = (sbyte[])(Array)TmpArray;
        }

    }

Then in your class, you would change this:
Code: [Select]
public String20 ProductID { get; set; };

Then you can set the value as such:
Code: [Select]
ProductID = new String20("TheValue");

I have not tested this, so it may not work the first try, but should get quite close.
3
Support Questions / Re: Read string in UDT
« Last post by Larry Griffin on September 19, 2017, 05:50:26 PM »
Not VB.  C#.

Code: [Select]
    // Work Order Structure
    public class WO
    {
        public int Sequence { get; set; }
        public string Description { get; set; } = "";  // STRING82
        public string ProductID { get; set; } = "";  // STRING20
        public string CustWO { get; set; } = "";  // STRING20
        public string ThisWO { get; set; } = "";  // STRING20
        public float CasingLen { get; set; }
        public float TubingLen { get; set; }
        public int Qty { get; set; }
        public int Priority { get; set; }
    }
4
Support Questions / Re: Read string in UDT
« Last post by Archie on September 19, 2017, 12:53:41 PM »
That is, I can't do a complete .WriteUDT to a UDT that contains multiple custom strings shorter than 82.  The first custom string gets written, but subsequent strings are empty.
And if I try to .WriteUDT to one custom string member of the UDT I get a "Not Enough Data" error.
How did you define the structures in VB for writing?

You may have to create a structure for the custom string (since it is technically a UDT), then use that structure in the main UDT structure.
Code: [Select]
Public Structure CustomString
    Dim Length As Integer
    Dim Characters() As Byte
End Structure

Public Structure MyUDT
    Dim s1 As CustomString
    Dim s2 As CustomString
End Structure

Then something like this to
Code: [Select]
        Dim MyString As String = "ABC"
        Dim s1a As CustomString
        s1a.Length = 20 '* the size as defined in RSLogix
        Dim c(s1a.Length-1) As Byte
        System.Text.ASCIIEncoding.ASCII.GetBytes(MyString).CopyTo(c, 0)
        s1a.Characters = c

        MyUDT.s1 = s1a
5
Support Questions / Re: Read string in UDT
« Last post by Larry Griffin on September 19, 2017, 12:17:12 PM »
This works okay for reading.
Is there a fix for writing?

That is, I can't do a complete .WriteUDT to a UDT that contains multiple custom strings shorter than 82.  The first custom string gets written, but subsequent strings are empty.
And if I try to .WriteUDT to one custom string member of the UDT I get a "Not Enough Data" error.

LarGriff
6
Open Discussion / Re: Any bugs in VS2017?
« Last post by Archie on September 19, 2017, 07:46:41 AM »
I've been using it since it first came available and everything has been good so far. The only thing I found different is the need to more frequently close design view windows when modifying the code of components. It does offer updates about once a month, so you should watch for the notification flag in the upper right to turn yellow to know when updates are available.
7
Open Discussion / Re: Visual Basic tutorials
« Last post by Vlad on September 19, 2017, 05:20:49 AM »

http://www.vbtutor.net/ by Dr. Liew Voon Kiong

http://www.visual-basic-tutorials.com/  - VB 2013 Lessons
8
Open Discussion / Any bugs in VS2017?
« Last post by MrPike on September 18, 2017, 11:31:31 PM »
Hello AHMI community.  I am wondering if there have been any issues found with vs2017?  I avoided going to vs2015 due to some bugs Archie found and stuck with vs2013 which seems pretty stable.  Just your thoughts on upgrading, thanks. 
9
Open Discussion / Re: Visual Basic tutorials
« Last post by Archie on September 18, 2017, 07:26:59 AM »
Visual Basic (200 Videos) - UPDATE: This link no longer works as of (17-SEP-17)
http://www.thenewboston.org/list.php?cat=39


This link works:
https://thenewboston.com/videos.php?cat=39
Thank you for the corrected link
10
Open Discussion / Re: Copy 500 element array to Excel?
« Last post by Archie on September 17, 2017, 12:40:22 PM »
Here is another resource for useful tutorials:

http://advancedhmi.com/forum/index.php?topic=298.msg1056#msg1056
Pages: [1] 2 3 ... 10