Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 140211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:34:26+00:00 2026-05-11T07:34:26+00:00

I have this bit of code that is being converted from vb6 to vb.net.

  • 0

I have this bit of code that is being converted from vb6 to vb.net. I need to know what LenB is doing in this bit of code.

Dim singleValue As Single 'var for conversion use(4byte -> 1single)' Dim bytes() As Byte Dim valueB() As Byte 'this gets set elsewhere and is redim-d to its size'  For n = 0 To CDbl(ItemNumberCombo.Text) - 1     'bytes() -> single'     'UPGRADE_ISSUE: LenB function is not supported.'     ReDim bytes(LenB(singleValue) - 1)     bytes(3) = valueB(n * 4)     bytes(2) = valueB(n * 4 + 1)     bytes(1) = valueB(n * 4 + 2)     bytes(0) = valueB(n * 4 + 3)     'UPGRADE_ISSUE: LenB function is not supported.'     'UPGRADE_ISSUE: VarPtr function is not supported. '     Call memcpy(VarPtr(singleValue), VarPtr(bytes(0)), LenB(singleValue))     'display the result'     DText(n).Text = VB6.Format(singleValue, '0.000000E+00') 'CStr(singleValue)'     If DataSaveCheckBox.CheckState = 1 And FileNameText.Text <> '' Then         csvOutput = csvOutput & DText(n).Text & ','     End If Next n 

Am I right in thinking that bytes is always ReDim’ed to the same size? By the looks of it 4 elements.

Why then use LenB to ReDim if you could just use a number? And why ReDim in the loop at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:34:26+00:00Added an answer on May 11, 2026 at 7:34 am

    LenB() returns the length in bytes of a variable. The most common example is for strings, where it returns the size of the string in bytes rather than the number of characters, regardless of character encoding. For other types it returns the size of an object- the size of a single being 4. The reason they would do this is that they wanted the code to survive if a future version of visual basic ever changed the size of a single (never mind hard-coding the number 4 when assigning to the byte array).

    When upgrading LenB() to .Net, for strings use System.Text.Encoding.Unicode.GetBytes() to get an array already populated with your string text bytes. Remember that .Net always uses Unicode for strings internally. If you really need a different encoding there are a number of alternatives in the Encoding namespace. For other types use the BitConverter class. Either way, don’t go line by line as the newer methods take away a lot of the busy work.

    Here — I’ll help you out with the conversion some:

    (earlier)

    Dim csvOutput As New StringBuilder() 

    (later)

    Dim valueB() As Byte 'this gets set elsewhere and is redim-d to its size' Dim singleValue As Single 'var for conversion  ' Included because the original developer was concerned the size of a single could change Dim singleSize As Integer = BitConverter.GetBytes(singleValue).Length   Dim NumberItems As Double If Double.TryParse(ItemNumberCombo.Text, NumberItems) Then     For n As Integer = 0 To NumberItems - 1         singleValue = BitConverter.ToSingle(valueB, n * singleSize)          'display the result         DText(n).Text = singleValue.ToString('E6') 'CStr(singleValue)         If DataSaveCheckBox.CheckState = 1 AndAlso Not String.IsNullOrEmpty(FileNameText.Text) Then             csvOutput.Append(DText(n).Text & ',')         End If     Next n Else     ' Handle Invalid ComboBox value here- may not be an issue for you End If 

    Note that this code also demonstrates a StringBuilder as a much better way to build your csv data, the AndAlso operator, the .TryParse() methods, String.IsNullOrEmpty(), and Standard Format Strings, all of which are intended to replace constructs or techniques from vb6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.