Page 1 of 2
Check if Richtextbox saved?
Posted: Sun Feb 27, 2011 5:00 am
by zachman61
ok before we start,
im using a tabcontrol and generating the richtextbox.
rtb = richtextbox
so how would i check if the tab's rtb has saved?
and have it save every 5 minutes or so?
Re: Check if Richtextbox saved?
Posted: Sun Feb 27, 2011 5:20 am
by GoodGuy17
EDIT: Do you want auto-save too?
Under Public Class Form1,
Code: Select allPublic rtbArray() As Boolean
Public tabCount As Integer
In a save event,
Code: Select allDim tabInt As Integer
tabInt = TabControl1.SelectedIndex
rtbArray(tabInt) = True
In the new tab event,
(add this alongside your new tab functions)
Code: Select alltabCount += 1
ReDim Preserve rtbArray(tabCount)
In a timer with it's interval at 300000,
Code: Select allFor i = 0 To UBound(rtbCount)
If rtbCount(i) = False Then
CType(TabControl1.TabPages.Item(i).Controls(0), RichTextBox).SaveFile(path)
End If
Next i
NOTE FOR TIMER: Change path to the path you want it to save to, and if you want to save it as a specific file type, put a comma after the path. If you get an error on this line:
For i = 0 To UBound(rtbCount)
then add "- 1" after the closing parenthesis.
If I helped, +rep please

Re: Check if Richtextbox saved?
Posted: Sun Feb 27, 2011 6:33 pm
by zachman61
ok, the autosave seems to work, ill try the other things now.
EDIT:
i get an error in this sub
Code: Select allPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 0 To UBound(rtbCount)
If Count(i) = False Then
CType(TabControl1.TabPages.Item(i).Controls(0), RichTextBox).SaveFile(path)
End If
Next i
End Sub
Error1: rtbCount is not declared.
Error2: Count is not declared.
Re: Check if Richtextbox saved?
Posted: Sun Feb 27, 2011 11:04 pm
by GoodGuy17
Code: Select allPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 0 To UBound(rtbCount)
If rtbCount(i) = False Then
CType(TabControl1.TabPages.Item(i).Controls(0), RichTextBox).SaveFile(path)
End If
Next i
End Sub
Fixed. Make sure rtbCount() is declared under Public Class Form1.
Re: Check if Richtextbox saved?
Posted: Sun Feb 27, 2011 11:56 pm
by MasterComputer
you can make it save the path when the user saves it and then on exit make it open the file and compare it
Re: Check if Richtextbox saved?
Posted: Mon Feb 28, 2011 1:44 am
by zachman61
GoodGuy17 wrote:Code: Select allPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 0 To UBound(rtbCount)
If rtbCount(i) = False Then
CType(TabControl1.TabPages.Item(i).Controls(0), RichTextBox).SaveFile(path)
End If
Next i
End Sub
Fixed. Make sure rtbCount() is declared under Public Class Form1.
Im not the brightest with declaring.
I declared it as
is this what i was supposed to declare as?
Re: Check if Richtextbox saved?
Posted: Mon Feb 28, 2011 1:51 am
by GoodGuy17
Hmm...
Redo my steps above and see if you missed something. I cannot see why it would tell you rtbCount is not declared unless you didn't put it under Public Class Form1.
Re: Check if Richtextbox saved?
Posted: Mon Feb 28, 2011 2:13 am
by zachman61
GoodGuy17 wrote:Hmm...
Redo my steps above and see if you missed something. I cannot see why it would tell you rtbCount is not declared unless you didn't put it under Public Class Form1.
in your steps above rtbCount is not mentioned.
and i did rtbCount as Boolean
and i got this error when opening the debugging the form
Code i got Error From:
Error i got from this code:
Code: Select allValue cannot be null.
Parameter name: Argument 'Array' is Nothing.
Re: Check if Richtextbox saved?
Posted: Mon Feb 28, 2011 2:26 am
by GoodGuy17
Ooohh ouch lol. I got scrambled up and put rtbCount instead of rtbArray. Replace the timer's code with this:
Code: Select allFor i = 0 To UBound(rtbArray)
If rtbArray(i) = False Then
CType(TabControl1.TabPages.Item(i).Controls(0), RichTextBox).SaveFile(path)
End If
Next i
Re: Check if Richtextbox saved?
Posted: Mon Feb 28, 2011 2:27 am
by zachman61
ooh lol

EDIT:
Does Vb2010 have a autosave function like office 2007-2010?
because i was just working on this project and had a lot of work done and it crashed cryer;
and it hasn't seemed to have saved an autorecovery like word.