Inefficient Updating

gin
01-26-2003, 08:16 PM
Hello all,

I'm making a small rename program for fun. My program is such that parts of the form are only enabled when doing something else. Example below:

Private Sub cboAdd_Click()
If cboAdd.Text = "at position" Then
txtAddPos.Enabled = True
txtAddPos_Change
Else
txtAddPos.Enabled = False
End If
Update '====update
End Sub

Private Sub txtAddPos_Change()
If txtAddPos.Text <> "" Then 'do some stuff
strTemp = txtAddPos.Text
ErrCheck strTemp, errAddPos, errPosInt
If arrError(errAddPos) = 0 Then intAddPos = CInt(strTemp)
Else
intAddPos = 0
End If
Update '====update
End Sub

After any change, a preview of the changed filenames is automatically shown (called by Update). However, if you'll look at the example above, an Update can be called multiple times when doing one change, which is redundant. How can I call just one update without repeating code or using an Update button? I'd really appreciate any ideas.

Thinker
01-26-2003, 09:29 PM
Use a module level boolean, set it to True, and check it for True
in the txtAddPos_Change event sub. Only call Update there if still
True. Set it to False at the start of cboAdd_Click, and set it back
to True at the end of the sub.

gin
01-27-2003, 11:59 PM
Thank you, this works quite well in with the given example. However, my situation is a little more complicated. Say I have procedure A which calls B and C. C in turn calls D. All of them have to be able to call an Update, since almost any combination of them may be enabled and triggered independantly. I tried to apply your suggestion, but ran afoul with where to reset the boolean to true. The C -> D run, set up as per your suggestion, would mess with an A -> C -> D run.

loquin
01-28-2003, 12:37 AM
Take a look at the DataChanged property of a textbox or other control. If the data has changed, this should be true. You will need to set this property to false after interrogating it. See the example, below .

Private Sub Command1_Click()
Me.Cls
If Me.Text1.DataChanged Then
Me.Print "Data Changed"
Else
Me.Print "Data was not changed..."
End If
Me.Text1.DataChanged = False
End Sub



Add a single textbox and a single button to a form & paste the above code into the form code.

gin
01-29-2003, 04:14 AM
Thank you, this works perfectly. The only remaining oddness is that a nested checkbox will return True for DataChanged if it was already checked before being enabled. But since I only have one instance of that, I shall happily ignore it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum