5 Replies - 6810 Views - Last Post: 04 August 2011 - 07:21 AM Rate Topic: -----

#1 razordon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 11

How to save the contents of a windows form

Posted 02 August 2011 - 07:16 AM

Hi

Really grateful for a steer in the right direction.

I've created a windows form in VB Express 2005 with lots of combo boxes and print and save buttons.

I would like to be able to save the contents of the populated combo boxes, labels etc ie the whole form from the save button, preferably to excel 2003. However, would be just as happy to save it in the form format.

The only code behind the save button I have so far is this, which just navigates me to the directory. When I enter a filename and extension, the directory is empty:

Private Sub save_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Save.Click
' Displays a SaveFileDialog so the user can save the file assigned to the Save button.
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "All Files|*.*|Excel Files|*.xls|Word Files|*.doc"
saveFileDialog1.InitialDirectory = "R:\Clinical\General\Shifts"
saveFileDialog1.Title = "Save Shift File"
saveFileDialog1.FilterIndex = 1
saveFileDialog1.ShowDialog()
End Sub 


Many thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to save the contents of a windows form

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9057
  • View blog
  • Posts: 34,001
  • Joined: 12-June 08

Re: How to save the contents of a windows form

Posted 02 August 2011 - 07:34 AM

I am lost - what is the problem? You don't know how to save data? You need options to save? Do you need to load up this information later?

Saving data can be as simple as using the StreamWriter.

        Dim sFoo As String = "this is my data to save"
        Dim mySW As New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop + "\myfilename.txt")
        mySW.WriteLine(sFoo)
        sFoo = "more text!"
        mySW.WriteLine(sFoo)
        mySW.Close()




Reading data can be easy as StreamReader!

        sFoo = String.Empty
        Dim mySR As New StreamReader(My.Computer.FileSystem.SpecialDirectories.Desktop + "\myfilename.txt")
        sFoo = mySR.ReadToEnd
        mySR.Close()
        Console.Write(sFoo)



The format and how you want to represent your data locally is up to you. XML, a CSV file, a database, a plain old text.. what ever.
Was This Post Helpful? 0
  • +
  • -

#3 mgchild  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 19
  • Joined: 14-January 11

Re: How to save the contents of a windows form

Posted 02 August 2011 - 07:40 AM

You might also want to look at this as well.
Was This Post Helpful? 0
  • +
  • -

#4 razordon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 11

Re: How to save the contents of a windows form

Posted 02 August 2011 - 08:08 AM

Thanks for the quick replies modi123_1 and mgchild.

I tried mgchild's option and it's progress ie creates the excel instance but how do I get the form data into it?

Alternatively, how do I save the populated form as it appears when completed. I would like to reload it as well.

I've attached a screen capture of my form for info.

Thanks for taking the time.

Razordon.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 razordon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 11

Re: How to save the contents of a windows form

Posted 04 August 2011 - 04:46 AM

Hi

Any more suggestions please.

This is my form. Would like to save and reload it as it looks on screen, if that's possible.

Thanks for looking.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9057
  • View blog
  • Posts: 34,001
  • Joined: 12-June 08

Re: How to save the contents of a windows form

Posted 04 August 2011 - 07:21 AM

Save it with some delimiter to specify columns - like how a CSV file uses commas.

Each line is a line in the god awful screen! ;)

<val 1>, <val2>, <val3>, .... <val20>
<val 1>, <val2>, <val3>, .... <val20>
<val 1>, <val2>, <val3>, .... <val20>
<val 1>, <val2>, <val3>, .... <val20>



You save each record in some fashion that you know it is a distinct element. Throw semicolons between shit, at brackets, what ever. Then you write that out. You read each line back in, break a part the data per your scheme and load it back up.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1