Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting fixed length to a variable

Status
Not open for further replies.

Laurelin

Programmer
Jan 24, 2002
29
0
0
US
I've looked everywhere to find out to set a variable to a fixed length but I am having no luck.

I am using VB 2008.

Dim variable as string * 18
- this is the method that most sources say is the correct method to define the fixed length of a variable but this gives me errors when tying this in VB 2008.

What is the best method to declare a variable and give it a fixed length?
 

I don't think you have fixed length strings in VB.NET
You can go around and do something like - add some Spaces at the end of your string to make it fixed length:
Code:
Dim variable As String
variable = [blue]"Some Text"[/blue] & Space([red]18[/red] - Strings.Len([blue]"Some Text"[/blue]))
Debug.Print("*" & variable & "*")
So you get:
[tt]
*Some Text *[/tt]

Have fun.

---- Andy
 
I found that you can only use <VBFixedString(18)> only Public variables so that is the route that I used and it is working great.

Interesting method you have Andy, I am going to give it a shot as well just to see how well it works. Thanks for sharing that.

Appreciate the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top