Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

String Truncated to 250 characters in VB6

Posted on 2009-02-10
8
Medium Priority
?
1,356 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

0
Comment
Question by:tchak12
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 1500 total points
ID: 23606337
Try using & for string building rather than +
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 23608964
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

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 23608983
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.

 

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:c0ldfyr3
ID: 23613813
Is it just me or is lb_FirstBank never set to False?
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 23613920
Yes, I hadn't looked at the code around the string concatenation. The string will only be ever equal to the first records details
0
 

Author Comment

by:tchak12
ID: 23614918
'&' 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

0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 23615132
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?
0
 

Author Comment

by:tchak12
ID: 23615200
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!!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question