• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

VB 2005 fixed length fields

I need to pass a string of fixed length fields to an AS400 from my Visual Studio 2005 / Visual Basic program.

Dim strFieldName as string * 18         receives an error for the "* 18" in 2005 VB.

How do I define a string field in VB 2005 with a fixed length value of 18?
0
RussBurns
Asked:
RussBurns
  • 2
1 Solution
 
davidrichardsonCommented:
.NET does NOT support Fixed length strings.

From the help file

"Note   The VBFixedStringAttribute is informational and cannot be used to convert a variable length string to a fixed string. The purpose of this attribute is to modify how strings in structures and non-local variables are used by methods or API calls that recognize the VBFixedStringAttribute. Keep in mind that this attribute does not change the actual length of the string itself."


0
 
davidrichardsonCommented:
0
 
bruintjeCommented:
Hi RussBurns,
----------

in addition you could use the stringbuilder class but even when declaring the capacity it will expand when you insert larger strings then 18 but it will be fixed length so if you need 18 spaces

      Dim sb As New StringBuilder(8)
      sb.Insert(0, "this") ' < the sb will be 8 in length
      sb.Insert(0, "this is a test") ' the sb will be 14 in length


you can also pad a string like
      s.PadRight(18," ")

but again this string will be 24 in length if you put in a string larger then 18
----------
bruintje
share what you know, learn what you don't
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now