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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initialize a fixed length string

Status
Not open for further replies.

TheZombie

Programmer
Jul 10, 2001
17
US
I am using a class that uses a UDT that contains fixed length strings. When the class is initialized, the strings are assigned characters that look like little bars. If I assign a string to the properties everything works fine. My problem is that if I do not assign anything to the property, when I write to the database using the class, the fields in the db get the bars. Does anyone know how to correct this? I would like the db fields to get <NULL> instead of the bars.
 
Don't use fixed length strings. Those bars are the actually ASCII null characters, i.e. Chr(0). Since a fixed length string has to have something in it (otherwise the length wouldn't be fixed), it's initialized with null characters by default.
The way to fix this would probably be to do some checking before writing to the database. For example, something along the lines of the following would probably do the trick:
Code:
If yourclass.fixedstr = String(len_of_str, Chr(0)) Then
   DB.Field(whatever) = NULL  'or whatever you'd use for null
Else
   DB.Field(whatever) = yourclass.fixedstr
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top