Results 1 to 7 of 7

Thread: [2.0] Len Property???[RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question [2.0] Len Property???[RESOLVED]

    From what i have seen in the msdn C# only contains a Len Property compared to VB.NET that has a boat load, for Len...Now this is fairly new Arena for me,dealing with Len and Char Strings...So here is the VB.NET Code section that i'm currently working on..

    VB Code:
    1. Public Function Header(ByVal PacketType As String, ByVal pck As String) As String
    2.         Dim i As Short
    3.         Dim x As Short
    4.         x = 0
    5.         i = Len(pck) /* Here is the Len part*/
    6.         Do While i > 255
    7.             i = i - 256
    8.             x = x + 1
    9.         Loop
    10.         Header = Name & Chr(0) & Chr(Ver) & New String(Chr(0), 2) & Chr(x) & Chr(i) & Chr(0) & Chr(CInt("&H" & PacketType)) & New String(Chr(0), 8) & pck
    11.         Debug.Print(Header)
    12.     End Function

    Now i'm not even sure where to begin with the Len,because theirs hardly any information about it for C#..Only thing i have managed to find is a Len Property using a { get; set; }... Only other part of the Code above i havent moved to C# is the the section below::
    VB Code:
    1. Header = Name & Chr(0) & Chr(Ver) & New String(Chr(0), 2) & Chr(x) & Chr(i) & Chr(0) & Chr(CInt("&H" & PacketType)) & New String(Chr(0), 8) & pck

    Thxs in Advance for the help on this quiet interesting section
    Last edited by Rattlerr; Aug 9th, 2006 at 01:42 PM.

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: [2.0] Len Property???

    Won't this work?

    i = pck.Length;

    i would have to be declared as int though.

    Edit: Removed brackets.
    Last edited by sevenhalo; Aug 9th, 2006 at 01:00 PM.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Len Property???

    VB Code:
    1. Do While i > 255
    2.             i = i - 256
    3.             x = x + 1
    4.         Loop
    What is the point of this. It's elementary maths, using a construct is just bloat

  4. #4

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Resolved Re: [2.0] Len Property???[RESOLVED]

    Thxs Sevenhalo that works out pretty good..

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Len Property???[RESOLVED]

    You're going about this the wrong way. Looking in C# documentation for information about Len (which is a function by the way, not a property) will get you nothing because it doesn't exist. You need to ask yourself "what does Len do?", and you would answer yourself "it gets the length of a string". As I posted in a previous thread, if you want to do something to a String object then chances are it will be done with a member of the String class. That means you should go to the MSDN documentation and read the member listing for the String class. I think that the Length property would jump out pretty quickly as the thing to use, and that's whether you're using C# or VB. It's a member of a class in the Framework class library, which means it can be used in any .NET language. You should follow these same steps for all VB Runtime functions. Ignore the function itself and just ask yourself what task you're trying to achieve and then find a way to achieve that task.

    For the other section you should follow similar methodology. Ask yourself what you're trying to achieve. Firstly, you need to concatenate strings. That's done with the "+" operator in C#. Secondly, I already told you in a previous thread that null characters are represented with the '\0' escape sequence. Thirdly, you need to convert an integer to the Char it represents. That's should be done in VB or C# using the Convert.ToChar method. Fourthly, you need to create a hexadecimal string and convert that to a Char. The hex prefix in C# id "0x" and, again regardless of language, you should convert a hex string to an integer using Convert.ToInt32. This all leads you to:
    Code:
    header = name + '\0' + Convert.ToChar(ver) + "\0\0" + Convert.ToChar(x) + Convert.ToChar(i) + '\0' + Convert.ToChar(Convert.ToInt32("0x" + packetType, 16)) + "\0\0\0\0\0\0\0\0" + pck;
    or better:
    Code:
    header = string.Format("{0}\0{1}\0\0{2}{3}\0{4}\0\0\0\0\0\0\0\0{5}",
                           name,
                           Convert.ToChar(ver),
                           Convert.ToChar(x),
                           Convert.ToChar(i),
                           Convert.ToChar(Convert.ToInt32("0x" + packetType, 16)),
                           pck);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: [2.0] Len Property???[RESOLVED]

    Ok,I follow you on that...

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Len Property???[RESOLVED]

    I'm so sorry that my comment was "non-constructive" and didn't have a solution for you. I will remember not to try helping in future.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width