08-07-2008, 08:30 AM
|
#1
|
|
Registered User
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
Max length of a string?
I have a string in VBA (it's dim as string), and it's truncating everything longer than 252 characters or so... Is there a length limit on a string?
|
|
|
08-07-2008, 08:39 AM
|
#2
|
|
I cant find the any key..
Join Date: Feb 2007
Location: New York
Posts: 3,028
Thanks: 1
Thanked 6 Times in 6 Posts
|
255 char usually
|
|
|
08-07-2008, 08:50 AM
|
#3
|
|
AWF VIP
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,862
Thanks: 0
Thanked 5 Times in 5 Posts
|
Hmmm. I've had VB strings much longer than 255 bytes. What are you doing with the string?
I have had problems copying data longer than 255 bytes from Access to Excel, but it is not because of the limitation of a String's size.
__________________
Thanks,
George Wilkinson To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 08:51 AM
|
#4
|
|
Registered User
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
Is there anyway to get around it....it's blowing up my app right now
|
|
|
08-07-2008, 10:27 AM
|
#5
|
|
Registered User
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
How to have a string longer than 255 chars
I have a string right now which needs to hold about 1000 characters or so. But, VBA limits it to only 255 characters. What can I do to make it hold more? (the string holds a SQL string which then gets passed to: db.openrecordset(sqlstr, dbopensnapshot)
Thanks
|
|
|
08-07-2008, 10:40 AM
|
#6
|
|
AWF VIP
Join Date: Feb 2001
Location: New Orleans, LA, USA
Posts: 7,611
Thanks: 10
Thanked 43 Times in 42 Posts
|
Strictly speaking, I don't recall that VBA limits string size to 255. I thought it was 65535 or something like that. But some of the interfaces that pass strings DO limit string size. If you could create an SQL query separately and THEN open it by name, that might be one workaround. I think you can build a long query, you just can't pass one.
__________________
I'm a certified grandpa and proud of it.
Not quite so valuable after the MVP status expired.
CompTIA Security+ certified.
|
|
|
08-07-2008, 10:43 AM
|
#7
|
|
AWF VIP
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,862
Thanks: 0
Thanked 5 Times in 5 Posts
|
__________________
Thanks,
George Wilkinson To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 10:49 AM
|
#8
|
|
AWF VIP
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,862
Thanks: 0
Thanked 5 Times in 5 Posts
|
I take it you no longer want this question answered since you created a new post.
__________________
Thanks,
George Wilkinson To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 11:51 AM
|
#9
|
|
I cant find the any key..
Join Date: Feb 2007
Location: New York
Posts: 3,028
Thanks: 1
Thanked 6 Times in 6 Posts
|
i dont read well, i thought it was to a text box..... i need to start paying attention
|
|
|
08-07-2008, 12:28 PM
|
#10
|
|
Registered User
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
Umm.... I'm not doing anything to it right now. If I just have a string, and assign it a value:
eg.
dim str1 as string
str1 = "[something 252 characters]"
It doesn't hold anything past the first 252 characters....
|
|
|
08-07-2008, 12:35 PM
|
#11
|
|
AWF VIP
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,862
Thanks: 0
Thanked 5 Times in 5 Posts
|
Can you post your entire code, including whatever code calls the code in question, if pertinent to the problem? I'd really love to see this resolved for you.
__________________
Thanks,
George Wilkinson To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 01:09 PM
|
#12
|
|
Registered User
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
Thanks very much!
This is how I have it:
Code:
dim var1 as string
var1 = "PUT A LONG LONG THING HERE"
when I look at the var1 under watches, it doesn't show the whole thing
|
|
|
08-07-2008, 01:41 PM
|
#13
|
|
AWF VIP
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,862
Thanks: 0
Thanked 5 Times in 5 Posts
|
The watches are limited in how much data they can show.
__________________
Thanks,
George Wilkinson To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 02:06 PM
|
#14
|
|
split with a cherry atop.
Join Date: Sep 2005
Posts: 6,319
Thanks: 0
Thanked 64 Times in 55 Posts
|
As mentioned earlier, some methods may truncate to first 255 characters, but the VBA string is definitely capable of holding much more than 255. This says that string can hold up to 2 billion characters (e.g. limited by a Long Integer, presumably.)
But! Text data type you used in table design only can hold up to 255 character. Using Memo will allow up to what I assume is limited by Integer (65,535 characters). Thanks, Allen..
Therefore, the effective limit is 65,535 characters per memo column, though VBA is perfectly capable of holding much more than that.
Also, I suspect that Immediate Windows will also truncate string if one used debug.print, but will have to test this.
You would be better off by testing something like this:
Pseduocode:
Code:
Dim stringer As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset ("SomefancypantqueryReturningAColumnOfMemo")
If Not rst.BOF And Not rst.EOF Then
stringer=rst.Fields(0)
Debug.Print Len(stringer) 'How long is this string?
Debug.print stringer 'See if we can read the whole string
End If
__________________
If relation-valued attributes and arbitrarily complex types are wrong, then I don't wanna to be right!
Founder of 'Blame the Developers First' crowd.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
08-07-2008, 03:04 PM
|
#15
|
|
Stuck On My Opinions
Join Date: Jan 2008
Posts: 585
Thanks: 0
Thanked 2 Times in 2 Posts
|
Code:
dim var1 as string
var1 = "PUT A LONG LONG THING HERE"
MsgBox "String Length = " & Len(var1) & vbCr & vbCr & var1
Even though the MsgBox will also truncate real long strings, it should be good enough to view most SQL Statements.
.
__________________
Self taught in all Environments.....and it shows To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
All times are GMT -8. The time now is 04:07 PM.
|
|