Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Convert from C#

Convert from C#

Scheduled Pinned Locked Moved Visual Basic
helpcsharp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeeOvEngland
    wrote on last edited by
    #1

    I have a function that I need to convert from C# to VB. C# public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while((b1=theStream.ReadByte())!=-1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } My VB So far... Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte() Dim b1 As Integer Dim tempStream As New System.IO.MemoryStream While ((b1 = theStream.ReadByte()) <> -1) tempStream.WriteByte(((byte)b1)) End While Return tempStream.ToArray() End Function i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement. Please can someone help me to convert the function Thank You

    T 1 Reply Last reply
    0
    • L LeeOvEngland

      I have a function that I need to convert from C# to VB. C# public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while((b1=theStream.ReadByte())!=-1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } My VB So far... Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte() Dim b1 As Integer Dim tempStream As New System.IO.MemoryStream While ((b1 = theStream.ReadByte()) <> -1) tempStream.WriteByte(((byte)b1)) End While Return tempStream.ToArray() End Function i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement. Please can someone help me to convert the function Thank You

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      You have only one error in the line tempStream.WriteByte(((byte)b1)). The VB equivelent of (byte)b1 is CType(b1, Byte). The full VB code should be

      Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
      Dim b1 As Integer
      Dim tempStream As New System.IO.MemoryStream
      While Not ((b1 = theStream.ReadByte) = -1)
      tempStream.WriteByte(CType(b1, Byte))
      End While
      Return tempStream.ToArray
      End Function

      G S 2 Replies Last reply
      0
      • T The Man from U N C L E

        You have only one error in the line tempStream.WriteByte(((byte)b1)). The VB equivelent of (byte)b1 is CType(b1, Byte). The full VB code should be

        Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
        Dim b1 As Integer
        Dim tempStream As New System.IO.MemoryStream
        While Not ((b1 = theStream.ReadByte) = -1)
        tempStream.WriteByte(CType(b1, Byte))
        End While
        Return tempStream.ToArray
        End Function

        G Offline
        G Offline
        Gavin Jeffrey
        wrote on last edited by
        #3

        here is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out - http://www.developerfusion.com/utilities/convertvbtocsharp.aspx

        T 1 Reply Last reply
        0
        • G Gavin Jeffrey

          here is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out - http://www.developerfusion.com/utilities/convertvbtocsharp.aspx

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #4

          Personaly I use SharpDevelop[^] which has a built in C# to VB.Net and VB.Net to c# converter. I use it a lot as I write in VB.Net as work and C# at home. It is quicker to convert whole classes than to rewrite from scratch, even though the conversion is only 99% perfect.

          1 Reply Last reply
          0
          • T The Man from U N C L E

            You have only one error in the line tempStream.WriteByte(((byte)b1)). The VB equivelent of (byte)b1 is CType(b1, Byte). The full VB code should be

            Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
            Dim b1 As Integer
            Dim tempStream As New System.IO.MemoryStream
            While Not ((b1 = theStream.ReadByte) = -1)
            tempStream.WriteByte(CType(b1, Byte))
            End While
            Return tempStream.ToArray
            End Function

            S Offline
            S Offline
            Steven Campbell
            wrote on last edited by
            #5

            Note that this function is not very efficient. Why is b1 an integer to begin with? And as for reading a single byte at a time...


            my blog

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups