Dim a string to a fixed size during runtime 
Author Message
 Dim a string to a fixed size during runtime

Is there a way of dimensioning a string to a fixed length using a
variable during runtime instead of declaring the length as a constant
during design time. The GET and PUT commands require fixed length
variables, but I want to create a dll to for simple file manipulation
with different record lengths.

This works
dim strSomething as string * 100

This also works
const RECSIZE=100
dim strSomething as string * RECSIZE

What I want to do is something like the following

function OpenFile (byref strFile as string, byref RecSize as integer) as
boolean
dim strSomething as string * RecSize

Thanks.



Fri, 07 May 2004 14:43:21 GMT  
 Dim a string to a fixed size during runtime
Get does NOT require fixed length strings. It only requires that the
buffer(string) be set to the correct size beforehand. The example below will
do what you want.

Function OpenFile (byref strFile as string, byref RecSize as integer) as
boolean

Dim iFile As Integer
Dim strSomething as string

    strSomething = String$(RecSize, " ")

    iFile = FreeFile
    Open strFile For Binary Access Read As #iFIle
        Get #iFile, , strSomething
    Close #iFile

End Function

HTH, Rocky Clark (Kath-Rock Software)


Quote:
> Is there a way of dimensioning a string to a fixed length using a
> variable during runtime instead of declaring the length as a constant
> during design time. The GET and PUT commands require fixed length
> variables, but I want to create a dll to for simple file manipulation
> with different record lengths.

> This works
> dim strSomething as string * 100

> This also works
> const RECSIZE=100
> dim strSomething as string * RECSIZE

> What I want to do is something like the following

> function OpenFile (byref strFile as string, byref RecSize as integer) as
> boolean
> dim strSomething as string * RecSize

> Thanks.



Fri, 07 May 2004 20:24:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie Question: Dim A() as String /Dim A as String()

2. Huge array and fixed sized strings

3. VBA Word, data stored in strings during runtime, and after closing

4. Executing a string as a VB cmd during runtime

5. How to set CR8 connection string during runtime in VB6

6. dim string to dim form

7. Fixed String and Fixed Array

8. Passing fixed length string to API and is returning nulls in string

9. Matrix size, Dim question

10. Matrix Size, Dim question

11. How to name and dim array at runtime

12. Fixed-size text box

 

 
Powered by phpBB® Forum Software