469,286 Members | 2,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Reading Files with GET

Assume I have the following code:

Dim VarByte As Byte
Dim VarInt As Integer
Dim VarStr As String
Open gFileName For Binary As gFN
Get #gFN, , VarByte ' 1 byte
Get #gFN, , VarInt ' 2 bytes
Get #gFN, , VarStr ' ?? bytes

Since the first two Var's each have a fixed length, the first two GETs
together will successfully retrieve 3 bytes from the file. (I have
successfully done this, and it worked as expected.) But obviously, there
will be a problem with the fourth GET. I know that the next ten bytes in the
file are text, and I want to put them into VarStr. Is there a way to define
VarStr as always having a length of 10? Or is there a way to specify in the
GET to get 10 bytes? Or do I have to GET 10 bytes, one at a time, and
concatenate them? Thank for any help.
Jul 17 '05 #1
5 7798
Inline :-

On Sat, 13 Sep 2003 22:08:58 GMT, "William Bub"
<fa********@hotmail.com> wrote:
Assume I have the following code:

Dim VarByte As Byte
Dim VarInt As Integer
Dim VarStr As String
Open gFileName For Binary As gFN
Get #gFN, , VarByte ' 1 byte
Get #gFN, , VarInt ' 2 bytes VarStr = Space$( 10 ) ' Set its lengthGet #gFN, , VarStr ' ?? bytes

Since the first two Var's each have a fixed length, the first two GETs
together will successfully retrieve 3 bytes from the file. (I have
successfully done this, and it worked as expected.) But obviously, there
will be a problem with the fourth GET. I know that the next ten bytes in the
file are text, and I want to put them into VarStr. Is there a way to define
VarStr as always having a length of 10? Or is there a way to specify in the
GET to get 10 bytes? Or do I have to GET 10 bytes, one at a time, and
concatenate them? Thank for any help.


You could also used a Fixed Length String

Or even better a UDT containing all the variables, including a fixed
length string.
Jul 17 '05 #2
<snip>
Is there a way to define
VarStr as always having a length of 10?
<snip>
You could also used a Fixed Length String

Or even better a UDT containing all the variables, including a fixed
length string.


Thanks. That was my question. I guess the answer is "yes." New question:
How? How do you define a fixed length string?

Jul 17 '05 #3
> > > Is there a way to define
VarStr as always having a length of 10?

<snip>

You could also used a Fixed Length String

Or even better a UDT containing all the variables, including a fixed
length string.


Thanks. That was my question. I guess the answer is "yes." New question:
How? How do you define a fixed length string?


Pretty much the way it's described in the VB Help files. Look up Dim
Statement and check the section describing "type".

Rick - MVP
Jul 17 '05 #4
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:Cz********************@comcast.com...
> Is there a way to define
>VarStr as always having a length of 10?

<snip>

You could also used a Fixed Length String

Or even better a UDT containing all the variables, including a fixed
length string.


Thanks. That was my question. I guess the answer is "yes." New question: How? How do you define a fixed length string?


Pretty much the way it's described in the VB Help files. Look up Dim
Statement and check the section describing "type".

Rick - MVP

I'm using the "Working Model" Version of VB 6.0. There are no help files,
and the textbook doesn't mention fixed length strings. Is there a good web
site with this kind of info?


Jul 17 '05 #5
> > > How? How do you define a fixed length string?

Pretty much the way it's described in the VB Help files. Look up Dim
Statement and check the section describing "type".

Rick - MVP

I'm using the "Working Model" Version of VB 6.0. There are no help files,
and the textbook doesn't mention fixed length strings. Is there a good web
site with this kind of info?


Okay, the syntax is

Dim StringVariableName As String * FixedCharacterSize

where you put the string variable name in the obvious spot and replace the
FixedCharacterSize indicator with a hard-coded number, such as 10, to make a
fixed string of 10 characters. (You must use an actual number; a variable
won't work.)

Although it is somewhat cumbersome to use, you can view the entire MSDN Help
Files online at this link...

http://msdn.microsoft.com/library/default.asp

Specifically, open the "tree" to this...

Visual Tools and Languages
Visual Studio 6.0
Visual Basic 6.0
Product Documentation
Reference
Language Reference
Rick - MVP
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Olivier Maurice | last post: by
19 posts views Thread by Lionel B | last post: by
6 posts views Thread by Rajorshi Biswas | last post: by
2 posts views Thread by nnimod | last post: by
6 posts views Thread by arne.muller | last post: by
10 posts views Thread by Tyler | last post: by
4 posts views Thread by Miner Jeff | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.