none
VB Table to C# Tabel how!? RRS feed

  • Question

  • Hi!

    I have a VB Table:

    Public WPFSuchTabelle() As WPFStandardSuchTabelle
    ...
    
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=100)> Public SuchArray() As WPFStandardSuchTabelle
    ...
    
        <StructLayout(LayoutKind.Sequential)> Public Structure WPFStandardSuchTabelle
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=10)> Public SuchNummer1 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=10)> Public SuchNummer2 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText1 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText2 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText3 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText4 As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=31)> Public SuchText5 As String
        End Structure

    Now I must put this Table in a C# Public Table...

    But How???

    Have anyone an idea?

    Best regards

    Bernd

    Monday, January 28, 2013 9:13 AM

Answers

  • When you call this method from C# code you will get a C# table object only. Nothing special to do to get it done. Just try it from C# code and let us know if you face any problem.

    Thanks, Durgesh Chaudhary. http://home.techphernalia.com

    • Marked as answer by Bernd Riemke Monday, January 28, 2013 11:12 AM
    • Unmarked as answer by Bernd Riemke Monday, January 28, 2013 11:12 AM
    • Marked as answer by Bernd Riemke Monday, January 28, 2013 5:23 PM
    Monday, January 28, 2013 10:49 AM

All replies

  • When you call this method from C# code you will get a C# table object only. Nothing special to do to get it done. Just try it from C# code and let us know if you face any problem.

    Thanks, Durgesh Chaudhary. http://home.techphernalia.com

    • Marked as answer by Bernd Riemke Monday, January 28, 2013 11:12 AM
    • Unmarked as answer by Bernd Riemke Monday, January 28, 2013 11:12 AM
    • Marked as answer by Bernd Riemke Monday, January 28, 2013 5:23 PM
    Monday, January 28, 2013 10:49 AM
  • Hi Bernd,

    the best way to convert vb code to c# code is by learning some basic c#syntax.

    For your help, I convert some of lines from your code in to c#

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
    public string SuchNummer1;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
    public string SuchNummer2;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
    public string SuchText1;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
    public string SuchText2;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
    public string SuchText3;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
    public string SuchText4;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
    public string SuchText5;
    

    you can use online tools which convert VB code to c# directly like below link

    VB to C#

    I am not sure How much this tools are reliable, but definitely it will help a lot for initial conversion. 

    may be it helps you.
    If anything is unclear feel free to ask me... :)

    Thanks,
    Nans11


    ENjoy ThE WorLD Of COdE

    Monday, January 28, 2013 10:56 AM
  • something like this

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    namespace ConsoleApplication1
    {
        class Program
        {
            Public WPFStandardSuchTabelle[] WPFSuchTabelle;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=100)] public WPFStandardSuchTabelle[] SuchArray;
        [StructLayout(LayoutKind.Sequential)] 
            struct WPFStandardSuchTabelle
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)] public string SuchNummer1; 
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)] public string SuchNummer2;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText1;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText2;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText3;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText4;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText5;
            }
              static void Main(string[] args)
            {
            }
      
        }
    }


    jdweng

    Monday, January 28, 2013 11:03 AM
  • I need a C# Table Code for this table:

    Public WPFSuchTabelle() As WPFStandardSuchTabelle

    at the End I will give the result to a ListView Element in a different window...

    Beest regards

    Bernd

    Monday, January 28, 2013 11:13 AM
  • This will not be working in a WPF C# Program...

            Public WPFStandardSuchTabelle[] WPFSuchTabelle;
            
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=100)] public WPFStandardSuchTabelle[] SuchArray;
       
            [StructLayout(LayoutKind.Sequential)] 
            struct WPFStandardSuchTabelle
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)] public string SuchNummer1; 
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)] public string SuchNummer2;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText1;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText2;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText3;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText4;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst=31)] public string SuchText5;
            }

    Best Regards

    Bernd

    Monday, January 28, 2013 11:17 AM
  • If the code is completely in C# then just use a structure without any Marshal directives.

            struct WPFStandardSuchTabelle
            {
                public fixed string SuchNummer1[10];
                public fixed string SuchNummer2[10];
                public fixed string SuchText1[31];
                public fixed string SuchText2[31];
                public fixed string SuchText3[31];
                public fixed string SuchText4[31];
                public fixed string SuchText5[31];
            }


    jdweng

    Monday, January 28, 2013 11:38 AM
  • something is wrong...

            public WPFStandardSuchTabelle[] WPFSuchTabelle;
    
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] 
            public WPFStandardSuchTabelle[] SuchArray;
       
            [StructLayout(LayoutKind.Sequential)] 
            struct WPFStandardSuchTabelle
            {
                public String SuchNummer1;
                public String SuchNummer2;
                public String SuchText1;
                public String SuchText2;
                public String SuchText3;
                public String SuchText4;
                public String SuchText5;
            }

    The Error means Fieldtype WPFSuchTabelle and SuchArray are missing...

    Monday, January 28, 2013 2:35 PM