Equivalent of “Dim As String * 1” VB6 to VB.NET

calendar_today Asked Mar 6, 2012
thumb_up 10 upvotes
history Updated April 14, 2026

Direct Answer

That's known as a "fixed-length" string. There isn't an exact equivalent in VB.NET. Edit: Well, OK, there's VBFixedStringAttribute, but I'm pretty sure that exists solely so that…. This is a 7-line VBA Core snippet, ranked #49th of 95 by community upvote score, from 2012.


The Problem (Q-score 6, ranked #49th of 95 in the VBA Core archive)

The scenario as originally posted in 2012

I have some VB6 code that needs to be migrated to VB.NET, and I wanted to inquire about this line of code, and see if there is a way to implement it in .NET

Dim strChar1 As String * 1

Intellisense keeps telling me that an end of statement is expected.

Why community consensus is tight on this one

Across 95 VBA Core entries in the archive, the accepted answer here holds solid answer (above median) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — solid answer (above median) (+10)

7-line VBA Core pattern (copy-ready)

That’s known as a “fixed-length” string. There isn’t an exact equivalent in VB.NET.

Edit: Well, OK, there’s VBFixedStringAttribute, but I’m pretty sure that exists solely so that automated migration tools can more easily convert VB6 code to VB.NET for you, and it’s not really the “.NET way” to do things. Also see the warnings in the article for details on why this still isn’t exactly the same thing as a fixed-length string in VB6.

Generally, fixed-length strings are only used in VB6 if you are reading fixed-size records from a file or over the network (i.e. parsing headers in a protocol frame).

For example, you might have a file that contains a set of fixed-length records that all have the format (integer, 1-character-string, double), which you could represent in VB6 as a user-defined type:

Public Type Record
   anInteger As Integer
   aSingleCharacter As String * 1
   aDouble As Double
End Type

This way, VB6 code that reads from the file containing records in this format can read each fixed-sized record stored in the file, and in particular, it will only read 1 byte for aSingleCharacter. Without the * 1, VB6 would have no idea how many characters to read from the file, since a String can normally have any number of characters.

In VB.NET, you can do one of the following, depending on your needs:

  • If the length matters (i.e. you need to read exactly one byte from some data source, for example) consider using an array instead, such as

    Dim aSingleByteArray(1) As Byte

  • Alternatively, you could use one of the Stream classes. In particular, if you are reading data from a network socket or a file, consider using NetworkStream or FileStream, respectively. A Stream is meant for byte-for-byte access (i.e. raw binary access). StreamReader is a related class that simplifies reading data when it is text-based, so that might be good if you are reading a text file, for example. Otherwise (if dealing with binary data), stick with one of the Stream classes.

  • If the length doesn’t matter, you could just use a “normal” String. That is to say:

    Dim aNormalString As String

Which answer is “correct” really depends on why it was declared that way in the original VB6 code.


When to Use It — vintage (14+ years old, pre-2013)

Ranked #49th in its category — specialized fit

This pattern sits in the 92% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.

What changed between 2012 and 2026

The answer is 14 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Is this above-median answer still worth copying?
expand_more

Answer score +10 vs the VBA Core archive median ~4; this entry is solid. The score plus 6 supporting upvotes on the question itself (+6) means the asker and 9 subsequent voters all validated the approach.

Does the 7-line snippet run as-is in Office 2026?
expand_more

Yes. The 7-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

This answer is 14 years old. Is it still relevant in 2026?
expand_more

Published 2012, which is 14 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #48?
expand_more

The pattern one rank above is “Creating a new Excel File based on a template in VBA”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 6, Answer-score 10, original post 2012, ranked #49th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba