Question:

How do you make a save button in visual basic 2008 express?

by  |  earlier

0 LIKES UnLike

I'm basically making a very basic paste and save program. What i have done so far is the window itself (premade) text box, and a button that when clicked brings up the save dialog defalt window. What i want it to do it that when i paste text into the box i can hit the save button and save the file as a .txt file extention with out actually opening note pad.

somthing that i also want to know how to do is make it so there is no window open at the bottem of the screen by the start bar.

"Note: I'm very new to visual basic but i intend on learning the language"

 Tags:

   Report

2 ANSWERS


  1. Add a textbox, button and a SaveFileDialog...

    Cut and paste this into the code pane:

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim filename As String

            Try

                With SaveFileDialog1

                    

                    .AddExtension = True

                    .CheckPathExists = True

                    .CreatePrompt = False

                    .OverwritePrompt = True

                    .ValidateNames = True

                    .ShowHelp = True

                    .DefaultExt = "txt"

                    .FileName = filename

                    .Filter = _

                    "Text files (*.txt)|*.txt|" & "All files|*.*"

                    .FilterIndex = 1

                    If .ShowDialog() = Windows.Forms.DialogResult.OK Then

                        My.Computer.FileSystem.WriteAllText(.Fil... TextBox1.Text, False)

                    End If

                End With

            Catch ex As Exception

                MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)

            End Try

        End Sub

    End Class

    : )


  2. Assuming your textbox is named TextBox1, your button is named Button1 and you want to save the text to a file named file.txt, here is your Button1 OnClick event handler:

    Sub SaveToTextFile() Handles Button1.Click

    Dim objWriter As New StreamWriter( "file.txt" )

    objWriter.Write( TextBox1.Text )

    objWriter.Close()

    End Sub

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.