• Recent Posts

  • Meta

  • Tags

    #ziplib .net getfilename .net no titlebar 7-zip adding a splash screen in visual basic.net adding textbox autocomplete addition adjusttokenprivileges adware application filename application position applications path audio library autocomplete autocomplete combobox avi mpg basic math bass.dll bass sound system beep benchmark data calculator cdrom tray change unix to windows directory exists disable beep on enter doevents excel file exists getinputstate high cpu usage linq mcisendstring no doevents open webpage pinging play mp3 play wave scroll textbox shell stop beep on enter textbox vb ping visual studio windows mci
  • « | Home | »

    How to Create/Make a String Buffer using VB.NET

    By admin | January 22, 2008

    Click Star to Rate Post
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...


       
    Bookmark and Share

     


     
      This is a simple Tip on how to create a string with a specific sized buffer. Unfortunately, the traditional way alot of the VB 5.0 and VB 6.0 programmers used to created a string variable with a specific size buffer as shown below, it Not supported in .net.

    ------------------------------------------------------------------------------

    '

    'This method works just fine with Classic VB (5.0/6.0), but Visual Basic.NET unfortunately does not support this somewhat traditional string buffer code.

    Dim buf As String * 128

      

      That code will create the string variable "buf" with a buffer of 128 spaces. IF you try running that code in Visual Basic.NET, then you should get a "End of statement expected." Error.

      There is another way, that I used even with VB 6.0 which will work with VB.NET as well. That is by using the Space (Space$) Function.

      

    Public Function Space(ByVal Number As Integer) As String

      

      The Space() Function above will make the variable a String with a 128 space Buffer. If your using Visual Basic 6.0 (or 5.0) then use the Space$ Function which will return the value as a actual String. String$ is supported in .NET but the Space() returns a String variable no matter which format you use.

      

    '

    'Visual Basic.NET AND Visual Basic 5.0/6.0 supports this way of creating a String with a specific sized buffer.

    Dim buf As String

    buf = Space(128)

      

    '

    'This should throw a message with the size of the buffered string variable.

    MsgBox(Len(buf), MsgBoxStyle.OKOnly, " The size of the String")

      

    Results of the codes above

    ------------------------------------------------------------------------------

      Thats all you have to do in DotNET to make a String buffer. This code will work in all versions of VB.NET and even Visual Basic 2005, and VB 2008. Obviously you need to set the number of spaces you want to be.

      Anyways, hopefully this small little Tip helped :)

                 Jason

     


     

    Topics: - (.NET All + 05/08), - .All VB (Related to All) | No Comments »

    Comments