10 Replies - 1468 Views - Last Post: 12 December 2012 - 08:35 PM Rate Topic: -----

#1 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Text History Window

Posted 10 December 2012 - 04:23 PM

I'm making a program to keep incoming calls organized. Sort of like for a secretary to keep a record of who calls in and who they wish to speak to, etc. I wanted to make a history window that exports the information from the main page to a secondary window to keep track of all the notes during the day. The export functions properly. Resetting the form clears the data and pastes it onto the other window. The only problem is that when the window is opened the first time, it displays all the information accurately, but once the history window is closed, all data in the textbox is erased.

Is there a way to keep the info in the textbox even after closing the window. (Note: The main page of the program remains open during the entire process. Only the history window is opened and closed.)

Is This A Good Question/Topic? 0
  • +

Replies To: Text History Window

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Text History Window

Posted 10 December 2012 - 05:23 PM

Perhaps you should leave history the window open, but hide it (Me.Hide).

You should probably write a history file as well, and in the case of the history window or the main program suffering an unexpected unload, you could repopulate the data from the file.
Was This Post Helpful? 1
  • +
  • -

#3 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Re: Text History Window

Posted 10 December 2012 - 06:05 PM

Thanks for the help again. I ended up loading the data to an invisible text box on the main window and transferring the data whenever the history window is loaded. A bit inefficient, but it works. Due to security reasons, I wouldn't want the data actually written to a file that would be saved to the HDD.

However, I am interested in the concept of writing the data to a file. How exactly would you set it up to write to like a txt file and load from there. Additionally, is there an option to write it to a temporary file that deletes after a set amount of time or at program close?
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Text History Window

Posted 10 December 2012 - 06:42 PM

View Postdschwartz, on 10 December 2012 - 07:05 PM, said:

Thanks for the help again. I ended up loading the data to an invisible text box on the main window and transferring the data whenever the history window is loaded. A bit inefficient, but it works. Due to security reasons, I wouldn't want the data actually written to a file that would be saved to the HDD.

However, I am interested in the concept of writing the data to a file. How exactly would you set it up to write to like a txt file and load from there. Additionally, is there an option to write it to a temporary file that deletes after a set amount of time or at program close?

Well, you could encrypt it. If you want to do that, there are various ways to do so that may not be the strongest envryption in the world, but that would be fine 99% of the time, and certainly for a temporary file. Check out the TripleDES Class.

As for writing the file, you could do that each time the history form closes, and reloead it when it opens. Check out the .Closing handler (Me.Closing). That will activate every time the form is about to close, and will execute anything in there before the form actually closes.

So, when the History form closes, you can write the file, then close. When the Main form closes, you could delete the file in the .Closing, or even further encrypt it, renaming it to something that indicates a double encryption, in case you want to reload it.

Just a few ideas.
Was This Post Helpful? 0
  • +
  • -

#5 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Re: Text History Window

Posted 11 December 2012 - 08:47 PM

That actually sounds perfect, but what would the actual code look like for saving the data to a .txt file at X location?
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Text History Window

Posted 11 December 2012 - 11:30 PM

Well, depending on where you want to save the file, and the name of it, you would use:
Dim sr As New StreamWriter("history.txt")
sr.Write(textBox1.Text)
sr.Dispose()


The Dispose is unnecessary if you are closing the program.
Was This Post Helpful? 0
  • +
  • -

#7 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Text History Window

Posted 12 December 2012 - 04:17 PM

Don't forget to specify a path there in that StreamWriter(parameter).
Was This Post Helpful? 0
  • +
  • -

#8 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Re: Text History Window

Posted 12 December 2012 - 06:50 PM

View Postlar3ry, on 11 December 2012 - 11:30 PM, said:

Well, depending on where you want to save the file, and the name of it, you would use:
Dim sr As New StreamWriter("history.txt")
sr.Write(textBox1.Text)
sr.Dispose()


The Dispose is unnecessary if you are closing the program.


So if I understand this correctly the code should look like:

Dim sr as New StreamWriter(C:\Users\*username*\Desktop\history.txt)
sr.Write(textbox1.text)



I looking to have this happen on button click as kind of an export function in case some error outside the program itself occurs and the info could be saved momentarily while the computer would reboot and then delete the file manually as needed. So would this function work for that, or would I need a different command entirely. (As a side note, is it possible to make the name of the file a variable such as the Date.Now to show when the file was created in the name itself?)
Was This Post Helpful? 0
  • +
  • -

#9 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Re: Text History Window

Posted 12 December 2012 - 07:36 PM

Okay. I've got it to work like I want. The code looks like this:

Private Sub Button16_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        Dim History As IO.StreamWriter = New IO.StreamWriter("C:\Users\dschwartz\Desktop\History.txt")
        History.Write(TextBox8.Text)
        History.Dispose()
    End Sub



Now this works, but that is using the directory on the computer I am using now. If a different user is using it, the file path will be different. Is there a way to set up a relative path so that it will save to the desktop regardless of who is logged in?
Was This Post Helpful? 0
  • +
  • -

#10 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Text History Window

Posted 12 December 2012 - 07:50 PM

View Postdschwartz, on 12 December 2012 - 08:36 PM, said:

Okay. I've got it to work like I want. The code looks like this:

Private Sub Button16_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        Dim History As IO.StreamWriter = New IO.StreamWriter("C:\Users\dschwartz\Desktop\History.txt")
        History.Write(TextBox8.Text)
        History.Dispose()
    End Sub



Now this works, but that is using the directory on the computer I am using now. If a different user is using it, the file path will be different. Is there a way to set up a relative path so that it will save to the desktop regardless of who is logged in?


Application.startuppath
Was This Post Helpful? 0
  • +
  • -

#11 dschwartz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 26-March 12

Re: Text History Window

Posted 12 December 2012 - 08:35 PM

Thank you. That worked perfectly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1