Home All Groups Group Topic Archive Search About

Build a Program Now! VB2005

Author
20 Sep 2006 2:49 AM
Joy M
Hi -

On page 78 of the book
Build a program Now!
Microsoft Visual Basic 2005
Express Edition

I was following the instructions, the book told me to insert code using
code snippets.  However the code that got inserted looks different from
the code on the listing in the text.  Just wondering if the book is
wrong or I am...would appeciate someone's opinion...

If this isn't the right forum, could someone tell me where to post?

Thanks!

Joy



*** Sent via Developersdex http://www.developersdex.com ***

Author
20 Sep 2006 3:54 AM
Cor Ligthert [MVP]
Joy,

There is maybe something in the book from a Beta version. But what is the
problem, the snippets can be changed everytime with every update as well by
yourself.

Because most of us are not reading beginner books or it are those who cannot
help you, has it in my idea no sense to tell us on what page from a beginner
book something is.

Just show the code as it is in the book and is in the snippet, than we can
tell you if it hurts or just is a newer implementation.

Cor

Show quoteHide quote
"Joy M" <ab***@ns.sympatico.ca> schreef in bericht
news:%23vC7X9F3GHA.4164@TK2MSFTNGP05.phx.gbl...
> Hi -
>
> On page 78 of the book
> Build a program Now!
> Microsoft Visual Basic 2005
> Express Edition
>
> I was following the instructions, the book told me to insert code using
> code snippets.  However the code that got inserted looks different from
> the code on the listing in the text.  Just wondering if the book is
> wrong or I am...would appeciate someone's opinion...
>
> If this isn't the right forum, could someone tell me where to post?
>
> Thanks!
>
> Joy
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
20 Sep 2006 10:00 AM
Joy
Hi Cor -

Thanks for writing.

The book has 'finished code' for all the problems. 

Here is the 'finished code' supposedly supplied when you hit Insert
Snippet > Processing Drives, Folders and Files > Write Text to a File :

=-=-=-=-

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object,
ByVal e As _
        System.ComponentModel.CancelEventArgs) Handles
SaveFileDialog1.FileOk
        Try
            ' The property FileName from the first argument in
WriteAllText refers to
            ' the FileName selected by the user in the SaveFileDialog1
            ' Then we are passing the content of each TextBox and
concatenating the
            ' Carriage Return-Line Feed constant
            ' The last parameter indicated if we should append to a file
if it
            ' exists. False will not and therefore recreate the file
each time.
            ' In order to add the content of the first box we need to
put true for
            ' the 2d and 3rd write otherwise only the last one would be
there
            ' if they were both true.

My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
                Me.tbMessage.Text & vbCrLf, False)

My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
                Me.TextBox2.Text & vbCrLf, True)

My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
                Me.TextBox3.Text & vbCrLf, True)
        Catch fileException As Exception
            Throw fileException
        End Try
    End Sub

=-=-=-=

As for me, this is the code snippet that was pasted when I created the
application

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
SaveFileDialog1.FileOk
        My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Text", True)
    End Sub

=-=-=-=

What the application does is save the contents of 3 textboxes to a file,
so you can see it. 

Something is weird.  I hope you can help me straighten this out!

Thanks for helping,

Joy



*** Sent via Developersdex http://www.developersdex.com ***
Author
20 Sep 2006 5:14 PM
Chris Dunaway
Joy wrote:
Show quoteHide quote
> Hi Cor -
>
> Thanks for writing.
>
> The book has 'finished code' for all the problems.
>
> Here is the 'finished code' supposedly supplied when you hit Insert
> Snippet > Processing Drives, Folders and Files > Write Text to a File :
>
> =-=-=-=-
>
>     Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object,
> ByVal e As _
>         System.ComponentModel.CancelEventArgs) Handles
> SaveFileDialog1.FileOk
>         Try
>             ' The property FileName from the first argument in
> WriteAllText refers to
>             ' the FileName selected by the user in the SaveFileDialog1
>             ' Then we are passing the content of each TextBox and
> concatenating the
>             ' Carriage Return-Line Feed constant
>             ' The last parameter indicated if we should append to a file
> if it
>             ' exists. False will not and therefore recreate the file
> each time.
>             ' In order to add the content of the first box we need to
> put true for
>             ' the 2d and 3rd write otherwise only the last one would be
> there
>             ' if they were both true.
>
> My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
>                 Me.tbMessage.Text & vbCrLf, False)
>
> My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
>                 Me.TextBox2.Text & vbCrLf, True)
>
> My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
>                 Me.TextBox3.Text & vbCrLf, True)
>         Catch fileException As Exception
>             Throw fileException
>         End Try
>     End Sub
>
> =-=-=-=
>
> As for me, this is the code snippet that was pasted when I created the
> application
>
>     Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object,
> ByVal e As System.ComponentModel.CancelEventArgs) Handles
> SaveFileDialog1.FileOk
>         My.Computer.FileSystem.WriteAllText("C:\Test.txt", "Text", True)
>     End Sub
>
> =-=-=-=
>
> What the application does is save the contents of 3 textboxes to a file,
> so you can see it.
>
> Something is weird.  I hope you can help me straighten this out!
>

There is no way the snippet could know you have any text boxes to
output so it shows a basic example of how to write text to a file and
it seems fine to me.  You probably need to just add the code for the
text boxes.

Don't get bogged down by what the book says you should see or if the
snippet is slightly different.  If you understand the concepts then, if
the book is wrong, you will be able to correct the code yourself.  You
may have to go to sources outside the book on occaision if something
doesn't look right to you.
Author
21 Sep 2006 4:44 AM
Cor Ligthert [MVP]
Joy,

>
> The book has 'finished code' for all the problems.
>
Completely agreeing with Chris; I only will add that you will probably have
much disappointments in your future life as developer. Almost every good
developer tells that he knows no problems, only challenges but on the route
to the solution to that the will always meet a lot of problems to be solved.

(And therefore he is a developer and not a bookkeeper.)

:-)

Just my thought,

Cor