|
-
Jun 8th, 2000, 04:47 AM
#1
Thread Starter
Lively Member
Hi,
There are various command buttons on my form. When clicked, they load text into a textbox.
For example,
Command1_click()
Text1.text="Welcome to part one"
end sub
So there are a lot of buttons like this that can be clicked in any order.
I want a different button, a 'Back' button, that when clicked will make the text that was previously in the textbox, before they clicked the command button, appear.
Does anybody know how I could do this?
Thanks.
-
Jun 8th, 2000, 04:50 AM
#2
Store the Previous string in a variable.
For example
Code:
Private Sub Command1_Click()
TmpText = Text1
Text1 = "Hello!"
End Sub
Code:
Private Sub cmdBack_Click()
Text1 = TmpText
End Sub
-
Jun 8th, 2000, 04:16 PM
#3
Thread Starter
Lively Member
Like this? All I get, when I click Commandback, is a blank box. I'll try more stuff, but if you have any code in the meantime....
Private Sub Command1_Click()
TmpText = Text1
Text1 = "Hello!"
End Sub
Private Sub Command2_Click()
TmpText = Text1
Text1 = "Bonjour!"
End Sub
Private Sub Command3_Click()
TmpText = Text1
Text1 = "Conas ata tu!"
End Sub
Private Sub Command4_Click()
TmpText = Text1
Text1 = "Como estas?"
End Sub
Private Sub Commandback_Click()
Text1.Text = TmpText
End Sub
-
Jun 8th, 2000, 05:08 PM
#4
PowerPoster
WM_UNDO
How about using the SendMessage API + WM_UNDO Constant?
Assume you have a TextBox Control call Text1 and an Undo button call CmdUndo on your project.
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_UNDO = &H304
Private Sub CmdUndo_Click()
SendMessage Text1.hwnd, WM_UNDO, 0, 0
End Sub
-
Jun 8th, 2000, 05:13 PM
#5
Addicted Member
In christophe's example, you need to put 'Dim TmpText as string' in the General section of your form code, otherwise it won't work.
-
Jun 8th, 2000, 05:20 PM
#6
-
Jun 8th, 2000, 06:00 PM
#7
Hyperactive Member
Tag
You could always use the textbox.tag property to save the value and then you wouldn't need to bother with module scoped variables or an API call. You can also implement one proc. to reverse all form changes.
Try :
Private Sub Command1_Click()
Text1.Tag = Text1
Text1 = "Hello!"
End Sub
Private Sub cmdUndo_Click()
Dim cDummy as Control
For Each cDummy In Form1.Controls
If TypeOf(cDummy) Is Textbox Then
cDummy.Text = cDummy.Tag
End If
Next
End Sub
That's Mr Mullet to you, you mulletless wonder.
-
Jun 9th, 2000, 08:49 PM
#8
Thread Starter
Lively Member
Chris, I tried your code, but it only seems to change textbox if textbox has the focus. (When a command button is clicked the button has the focus, so it doesn't alter the textbox).
Paul Warren, I tried your code and it worked somewhat (after I changed (cDummy) to cDummy.
But it only works once. If I have 5 command buttons and I click through them all (which changes text1 as the clicks occur), and then I click cmdUndo, it only returns it to the text of the last clicked command button.
Is it possible to have it so that, for example if CmdUndo is clicked 3 times, it will return the text of that command button etc...?
Thanks.
-
Jun 9th, 2000, 08:52 PM
#9
Thread Starter
Lively Member
Why did my message
turn out like that?
It's messy. Change it quick.
-
Jun 9th, 2000, 09:19 PM
#10
Addicted Member
Try this,,
in a form add 6 command buttons, named like this :
command1(0), command1(1), command1(2), command1(3), command1(4)
and command2 which is for "Back" and 1 textbox names text1
then pase the following code
Code:
Dim MyText(4), CurText
Private Sub Command1_Click(Index As Integer)
Text1.Text = MyText(Index)
CurText = Index
If Index = 0 Then
Command2.Enabled = False
Else
Command2.Enabled = True
End If
End Sub
Private Sub Command2_Click()
If CurText <> 0 Then
Text1.Text = MyText(CurText - 1)
CurText = CurText - 1
End If
If CurText = 0 Then Command2.Enabled = False
End Sub
Private Sub Form_Load()
MyText(0) = "Hello"
MyText(1) = "Welcome"
MyText(2) = "Bye"
MyText(3) = "See ya"
MyText(4) = "It works"
End Sub
let me know if it works or not
-
Jun 10th, 2000, 01:24 AM
#11
Thread Starter
Lively Member
Yeh Mih,
I think it works,
Thanks. And now I'm going to analyse how it works.
-
Jun 10th, 2000, 01:31 AM
#12
Addicted Member
hehehehehe
you don't need to analyze any thing,,,just read the code and you will see how easy and powerfull it is,,,,,
Any help i'm ready,,,you can e-mail me if you want
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|