Results 1 to 12 of 12

Thread: bringing up previous text in a text box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90

    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.

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90

    Smile


    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

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb 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

  5. #5
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    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.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb

    I think the SendMessage API is engough for this problem and it save to declare one more variable call TmpText and write extra code to store the previous text on each time the TextBox text change.

  7. #7
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282

    Question 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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90

    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90
    Why did my message
    turn out like that?
    It's messy. Change it quick.

  10. #10
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    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

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    France
    Posts
    90
    Yeh Mih,

    I think it works,

    Thanks. And now I'm going to analyse how it works.

  12. #12
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    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
  •  



Click Here to Expand Forum to Full Width