We help IT Professionals succeed at work.

String Truncated to 250 characters in VB6

Medium Priority
1,584 Views
Last Modified: 2013-11-25
Hi,

I am using the given code to build a dynamic string.The problem is that my string variable is always limited to 250 characters.The string datatype has much larger length then 250.Does anyone has any idea about why is this occuring?
The string variable is defined as Private ms_BankFilterString As String
ms_BankFilterString = ""
Do While Not ars_CompanyBankNumbers.EOF
        If lb_FirstBank = True Then
            ms_BankFilterString = ars_CompanyBankNumbers("CompanyNumber") + "__" + CStr(ars_CompanyBankNumbers("BankNumber")) + "##" + CStr(ars_CompanyBankNumbers("BankID"))
        Else
            ms_BankFilterString = ms_BankFilterString + "," + ars_CompanyBankNumbers("CompanyNumber") + "__" + CStr(ars_CompanyBankNumbers("BankNumber")) + "##" + CStr(ars_CompanyBankNumbers("BankID"))
        End If
   ars_CompanyBankNumbers.MoveNext
Loop

Open in new window

Comment
Watch Question

Try using & for string building rather than +

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
It won't be a problem of your string-declaration
http://www.dotnetjunkies.com/WebLog/removable_thoughts/archive/2004/05/19/13955.aspx

Can you check the lengths of the fields in the database ?

By the way: for performances issues, I would suggest that you use the stringBuilder. It's faster for concatenating string and uses less resources than the string (in the way you are using it)
Dim ms_BankFilterString as StringBuilder = new StringBuilder
Do While Not ars_CompanyBankNumbers.EOF
        If lb_FirstBank = True Then
            ms_BankFilterString.append(ars_CompanyBankNumbers("CompanyNumber"))
            ms_BankFilterString.append("__")
            ms_BankFilterString.append(CStr(ars_CompanyBankNumbers("BankNumber"))
            ms_BankFilterString.append("##")
            ms_BankFilterString.append(CStr(ars_CompanyBankNumbers("BankID"))
        Else
            ms_BankFilterString.append(",")
            ms_BankFilterString.append(ars_CompanyBankNumbers("CompanyNumber"))
            ms_BankFilterString.append("__")
            ms_BankFilterString.append(CStr(ars_CompanyBankNumbers("BankNumber"))
            ms_BankFilterString.append("##")
            ms_BankFilterString.append(CStr(ars_CompanyBankNumbers("BankID"))
        End If
   ars_CompanyBankNumbers.MoveNext
Loop

Open in new window

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Sorry, above code is for .NET

If you are using vb6, there is a limitation of a string around the 2 biljoen chars.. (approx).

If you are concatenating strings, you should use the " & "


For more information: http://www.vb6.us/tutorials/joining-strings-vb6

& Operator

Used to force string concatenation of two expressions.

Remarks
If an expression is not a string, it is converted to a String variant. The data type of result is String if both expressions are string expressions; otherwise, result is a String variant. If both expressions are Null, result is Null. However, if only one expression is Null, that expression is treated as a zero-length string ("") when concatenated with the other expression. Any expression that is Empty is also treated as a zero-length string.
 
+ Operator

Remarks
When you use the + operator, you may not be able to determine whether addition or string concatenation will occur. Use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.

 

Top Expert 2008

Commented:
Is it just me or is lb_FirstBank never set to False?
Yes, I hadn't looked at the code around the string concatenation. The string will only be ever equal to the first records details

Author

Commented:
'&' didn't solved the problem.It still truncates to around 250 characters.

lb_FirstBank is set to false.I just missed that line in the code while pasting it here(pasting is again).
ms_BankFilterString = ""
Do While Not ars_CompanyBankNumbers.EOF
        If lb_FirstBank = True Then
            ms_BankFilterString = ars_CompanyBankNumbers("CompanyNumber") + "__" + CStr(ars_CompanyBankNumbers("BankNumber")) + "##" + CStr(ars_CompanyBankNumbers("BankID"))
        Else
            ms_BankFilterString = ms_BankFilterString + "," + ars_CompanyBankNumbers("CompanyNumber") + "__" + CStr(ars_CompanyBankNumbers("BankNumber")) + "##" + CStr(ars_CompanyBankNumbers("BankID"))
        End If
   lb_FirstBank = True 
   ars_CompanyBankNumbers.MoveNext
Loop

Open in new window

You have set it equal to True. This will not fix the issue.

Can you post the code as it is in your application. The end value of ms_BankFilterString would help as well, does it contain just the first record, or text from multiple records?

Author

Commented:
Sorry for being little over cautious.I was looking into my application while debugging. I was looking for the value of the variable in "Add Watch" window. It still shows 250 character but the string passed to the SP has the complete value.Thanks everyone for your help!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.