Limit String Length

Lachy
05-23-2003, 06:33 PM
I need to limit the length of a string in my program.

Dim Calculator(1 To 14, 1 To 150, 1 To 3) As String

That is the current declaration for an array my program uses, which (apparently) takes a lot of memory; people are getting 'Runtime Error 7 Out of Memory' when they start.

Dim Calculator(1 To 14, 1 To 150, 1 To 3) As String * 64

I tried that (to limit the length of each string to 64 characters), but I am getting all these annoying spaces at the end (which cause bugs in my program), and I can't get them to go away. I have tried Trim ect.

How can I fix this? Or is there a better way to limit the length of a string?

Squirm
05-23-2003, 06:40 PM
You've got 6300 strings there so the first declaration you have there will require 63000 bytes of memory initially then more as the strings are allocated. The second declaration will require 403200 bytes permanently. This is not including the data required for the array details, as that will be constant for both. If the users are getting memory issues when the application starts your method will not fix it.

I wouldnt have expected 63000 bytes to kill an app, its not a great deal after all. Are you certain it is this which causes the error? Do you really need so many strings?

Lachy
05-23-2003, 06:47 PM
This Array is entirely filled up when the program starts, I can't think of anything else that would cause it (unless ActiveX controls do?).

Squirm
05-23-2003, 07:10 PM
Ok, if the array is being filled then that may explain it. You're correct that fixed-length strings are padded out with spaces, so we need to use RTrim$() to remove them.

Dim x As String * 64
Dim y As String

x = "foo"
Debug.Print Len(x) 'Returns 64
x = RTrim$(x)
Debug.Print Len(x) 'Still returns 64

y = x
Debug.Print Len(y) 'Returns 64
y = RTrim$(x)
Debug.Print Len(y) 'Returns 3

You just need to be careful and meticulous thats all.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum