Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Visual Basic 2010 Express access files during run?

I am trying to make a program for one of my teachers, he asked me to make a program where, while you run it, you can click on a box and it opens up a window that allows you to select a file from your computer and save it in the box. It would be nice, though not necessary, to also have it so that when the program closes, it saves what pictures are there. If someone could give me a step-by-step walkthrough for this I would appreciate it.

2 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Sure sounds more like a homework assignment to me. Regardless: http://msdn.microsoft.com/en-us/library/dd492135(V... There. Picture viewer walk through. If it is homework I don't advise you doing it this way, you'll probably get caught.

    Source(s): VB.NET Programmer
  • 9 years ago

    I have done this before but i don't have the code on me so im going to be helping you from my brain. so some of this might not work right away and you are probably going to have to tweak the code. Also i was programming in C#.Net not VB.

    First you want to look for a menu strip. In the Tools. listed under Menus & Toolbars. Next you want to add Open file dialog and save file dialog. You can find both of thouse in the Dialogs inside the toolstip.

    This is for the Open File.

    Dim SpaceHoldingReader As String = ""

    OpenFileDialog1.Title = "Open File"

    OpenFileDialog1.Filter = "txt Files (*.txt)|*.txt|All Files (*.*)|*.*"

    OpenFileDialog1.FileName = ""

    OpenFileDialog1.InitialDirectory = "MyDocuments"

    OpenFileDialog1.ShowDialog()

    SpaceHoldingReader = OpenFileDialog1.FileName

    Dim sr As New StreamReader(SpaceHoldingReader, True)

    RichTextBox1.Text = sr.ReadToEnd

    sr.Dispose()

    sr.Close()

    This is for the save

    Dim Savefile As String = ""

    SaveFileDialog1.OverwritePrompt = True

    SaveFileDialog1.FileName = Savefile

    SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

    SaveFileDialog1.ShowDialog()

    If SaveFileDialog1.FileName.Length = 0 Then

    MsgBox("Canceled")

    Else

    Dim sw As New StreamWriter(SaveFileDialog1.FileName, True)

    sw.Write(RichTextBox1.Text, True)

    sw.Dispose()

    sw.Close()

    End If

    To use images ill let you figer it out. Dont worry ill give you a good hint.

    use Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.* where the code says OpenFileDialog.filter = "txt Files (*.txt)|*.txt|All Files (*.*)|*.*" and add it to the code that is there so that it accepts thoughs types of files as well.

    Its not tuff i think you can do it.

    Good luck and try it out, it only takes a tiny amount of thought to make it work.

Still have questions? Get your answers by asking now.