Home All Groups Group Topic Archive Search About

Add a document to my project?

Author
17 Oct 2005 10:25 AM
Chris
I've got a text document which I display in a text box in my project.  The
document is fairly long so I read it in from a file at run-time by doing:-

Open App.Path & "\MyFile.txt" For Input As #FileNumber
.... etc

This is much easier than me converting the document to a long string in VB
as this would take ages to convert to:-

MyString = MyString & "Some sample text " & vbCrLf & _
                   "More sample text"
.... etc

Plus my document often changes (each time I do a new version of my project),
so reading the file in at run-time is a much quicker process.  However I
would like to know whether it is possible to import the whole document into
the project and simply read the contents of this when I run the project.
This would mean I would not have to distribute a seperate file.  Is
something like this possible?

Thanks

Author
17 Oct 2005 12:14 PM
Dave
One way to do this would be to add your file to a resource file as a "Custom
Resource". Note that VB will store the file as unicode so you have to
convert it back when the file is retrieved.

So for a custom resource called "101" this will extract the file: (untested
air code)

FileInAString = StrConv(LoadResData("101", "CUSTOM"), vbUnicode)

Regards
Dave O.

Show quoteHide quote
"Chris" <cw@community.nospam> wrote in message
news:%23GjfjUw0FHA.1168@TK2MSFTNGP10.phx.gbl...
> I've got a text document which I display in a text box in my project.  The
> document is fairly long so I read it in from a file at run-time by doing:-
>
> Open App.Path & "\MyFile.txt" For Input As #FileNumber
> ... etc
>
> This is much easier than me converting the document to a long string in VB
> as this would take ages to convert to:-
>
> MyString = MyString & "Some sample text " & vbCrLf & _
>                   "More sample text"
> ... etc
>
> Plus my document often changes (each time I do a new version of my
> project), so reading the file in at run-time is a much quicker process.
> However I would like to know whether it is possible to import the whole
> document into the project and simply read the contents of this when I run
> the project. This would mean I would not have to distribute a seperate
> file.  Is something like this possible?
>
> Thanks
>
Author
17 Oct 2005 2:52 PM
Mike D Sutton
Show quote Hide quote
> I've got a text document which I display in a text box in my project.  The
> document is fairly long so I read it in from a file at run-time by doing:-
>
> Open App.Path & "\MyFile.txt" For Input As #FileNumber
> ... etc
>
> This is much easier than me converting the document to a long string in VB
> as this would take ages to convert to:-
>
> MyString = MyString & "Some sample text " & vbCrLf & _
>                   "More sample text"
> ... etc
>
> Plus my document often changes (each time I do a new version of my
> project), so reading the file in at run-time is a much quicker process.
> However I would like to know whether it is possible to import the whole
> document into the project and simply read the contents of this when I run
> the project. This would mean I would not have to distribute a seperate
> file.  Is something like this possible?

Have a look at using a resource file, then use LoadResData() or
LoadResString (depending on what format the document is in) at runtime to
load it.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
18 Oct 2005 8:22 AM
J French
On Mon, 17 Oct 2005 11:25:44 +0100, "Chris" <cw@community.nospam>
wrote:

<snip>

>This would mean I would not have to distribute a seperate file.  Is
>something like this possible?

There is a very neat old fashioned trick that works very nicely

Append the text file to the end of the EXE with a footer describing it
in the last few bytes.

While developing read it in from a file into one long string

When compiled write a utility (maybe in the App) that appends the file
to a new copy of the EXE.
Author
18 Oct 2005 3:11 PM
Ralph
Show quote Hide quote
"J French" <erew***@nowhere.uk> wrote in message
news:4354af7d.242352704@news.btopenworld.com...
> On Mon, 17 Oct 2005 11:25:44 +0100, "Chris" <cw@community.nospam>
> wrote:
>
> <snip>
>
> >This would mean I would not have to distribute a seperate file.  Is
> >something like this possible?
>
> There is a very neat old fashioned trick that works very nicely
>
> Append the text file to the end of the EXE with a footer describing it
> in the last few bytes.
>
> While developing read it in from a file into one long string
>
> When compiled write a utility (maybe in the App) that appends the file
> to a new copy of the EXE.
>

A minor point, but Be aware while developing and especially on a target
machine, that 'modifying' the .exe will drive some realtime VirusCheckers
nuts. <g>

-ralph
Author
18 Oct 2005 4:08 PM
J French
On Tue, 18 Oct 2005 10:11:19 -0500, "Ralph"
<nt_consultin***@yahoo.com> wrote:

<snip>

>> When compiled write a utility (maybe in the App) that appends the file
>> to a new copy of the EXE.

>A minor point, but Be aware while developing and especially on a target
>machine, that 'modifying' the .exe will drive some realtime VirusCheckers
>nuts. <g>

>-ralph

Very true
- but little will work on a development machine with that stuff
activated
Author
18 Oct 2005 6:35 PM
Ralph
Show quote Hide quote
"J French" <erew***@nowhere.uk> wrote in message
news:43551b76.269997725@news.btopenworld.com...
> On Tue, 18 Oct 2005 10:11:19 -0500, "Ralph"
> <nt_consultin***@yahoo.com> wrote:
>
> <snip>
>
> >> When compiled write a utility (maybe in the App) that appends the file
> >> to a new copy of the EXE.
>
> >A minor point, but Be aware while developing and especially on a target
> >machine, that 'modifying' the .exe will drive some realtime VirusCheckers
> >nuts. <g>
>
> >-ralph
>
> Very true
> - but little will work on a development machine with that stuff
> activated
>

I should have said a very, very, minor point, but I felt worth mentioning,
as depending on the VirusChecker used and its configuration, subsequent
problems can be rather puzzling the first time you run across it.

-ralph
Author
19 Oct 2005 12:11 PM
J French
On Tue, 18 Oct 2005 13:35:13 -0500, "Ralph"
<nt_consultin***@yahoo.com> wrote:

<snip>

>> Very true
>> - but little will work on a development machine with that stuff
>> activated


>I should have said a very, very, minor point, but I felt worth mentioning,
>as depending on the VirusChecker used and its configuration, subsequent
>problems can be rather puzzling the first time you run across it.

Understood - the main thing is that this would all be run on a
development machine.

I have to confess that I've little faith in virus checkers
- idiot users install malware regardless
- also viruse are always ahead of the checkers
  (unless, as some suspect, the viruse come from the virus checkers)
Author
19 Oct 2005 1:26 PM
Ralph
Show quote Hide quote
"J French" <erew***@nowhere.uk> wrote in message
news:4356360e.3969534@news.btopenworld.com...
> On Tue, 18 Oct 2005 13:35:13 -0500, "Ralph"
> <nt_consultin***@yahoo.com> wrote:
>
> <snip>
>
> >> Very true
> >> - but little will work on a development machine with that stuff
> >> activated
>
>
> >I should have said a very, very, minor point, but I felt worth
mentioning,
> >as depending on the VirusChecker used and its configuration, subsequent
> >problems can be rather puzzling the first time you run across it.
>
> Understood - the main thing is that this would all be run on a
> development machine.
>
> I have to confess that I've little faith in virus checkers
> - idiot users install malware regardless
> - also viruse are always ahead of the checkers
>   (unless, as some suspect, the viruse come from the virus checkers)
>

Funny you should mention that. VirusCheckers and their ilk are the new
target. And guess who is the worse at protecting themselves -
Norton/Symantec. But then I guess that doesn't really surprise anyone. <g>

-ralph
Author
18 Oct 2005 10:57 AM
Chris
Thanks for all the replies.

Chris


Show quoteHide quote
"Chris" <cw@community.nospam> wrote in message
news:%23GjfjUw0FHA.1168@TK2MSFTNGP10.phx.gbl...
> I've got a text document which I display in a text box in my project.  The
> document is fairly long so I read it in from a file at run-time by doing:-
>
> Open App.Path & "\MyFile.txt" For Input As #FileNumber
> ... etc
>
> This is much easier than me converting the document to a long string in VB
> as this would take ages to convert to:-
>
> MyString = MyString & "Some sample text " & vbCrLf & _
>                   "More sample text"
> ... etc
>
> Plus my document often changes (each time I do a new version of my
> project), so reading the file in at run-time is a much quicker process.
> However I would like to know whether it is possible to import the whole
> document into the project and simply read the contents of this when I run
> the project. This would mean I would not have to distribute a seperate
> file.  Is something like this possible?
>
> Thanks
>
Author
19 Oct 2005 2:36 PM
Someone
To read the entire file into a string variable, use the following:

MyString = String(LOF(FileNumber), 0)
Get FileNumber, , MyString



Show quoteHide quote
"Chris" <cw@community.nospam> wrote in message
news:%23GjfjUw0FHA.1168@TK2MSFTNGP10.phx.gbl...
> I've got a text document which I display in a text box in my project.  The
> document is fairly long so I read it in from a file at run-time by doing:-
>
> Open App.Path & "\MyFile.txt" For Input As #FileNumber
> ... etc
>
> This is much easier than me converting the document to a long string in VB
> as this would take ages to convert to:-
>
> MyString = MyString & "Some sample text " & vbCrLf & _
>                   "More sample text"
> ... etc
>
> Plus my document often changes (each time I do a new version of my
> project), so reading the file in at run-time is a much quicker process.
> However I would like to know whether it is possible to import the whole
> document into the project and simply read the contents of this when I run
> the project. This would mean I would not have to distribute a seperate
> file.  Is something like this possible?
>
> Thanks
>