Results 1 to 11 of 11

Thread: [RESOLVED] Edit conundrum on RTB. Should be simple

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Resolved [RESOLVED] Edit conundrum on RTB. Should be simple

    I have a Rich Text Box and the user enters data for an engineering app. The data consists of a series of statements and commands which can subsequently be file saved if the data has changed.

    I had problems with too many Change events occurring so I am only using the key_press event to set the flag that the data needs to be saved.

    To my chagrin, I did a copy from another source, & paste using the mouse, and, the save flag didn't get set. Horrors! What to do?

    What's a simple way to detect new data input via the mouse/paste?
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Edit conundrum on RTB. Should be simple

    Yeah...since no keys were pressed, the keypress event won't fire... try the Changed event instead.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Edit conundrum on RTB. Should be simple

    What's a simple way to detect new data input via the mouse/paste?
    you could have a variable with the opening content, that you can compare with the closing content
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Re: Edit conundrum on RTB. Should be simple

    There isn't a closing event. The edit stays open. Only when the Save button is visible/highlited does the data get processed.
    What about mouse down/mouse up?
    Last edited by VB-only; Jan 7th, 2021 at 10:31 AM.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: Edit conundrum on RTB. Should be simple

    Check the mousedown/up event and then check whether the content has changed.
    But you need to store a reference text somewhere.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Edit conundrum on RTB. Should be simple

    Well, there is always TOM for this stuff:

    Code:
    Option Explicit
    
    'Reference to "tom" type library in RICHED20.DLL.
    
    Private Const RTF_FILE As String = "test.rtf"
    
    Private Const CP_ACP As Long = 0 'System default.
    Private Const WM_USER As Long = &H400&
    Private Const EM_GETOLEINTERFACE As Long = WM_USER + 60
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private TextDocument As tom.ITextDocument
    Private FormatDefault As tom.ITextFont
    
    Private Sub Form_Load()
        Dim Unknown As stdole.IUnknown
    
        SendMessage RichTextBox1.hWnd, EM_GETOLEINTERFACE, 0, VarPtr(Unknown)
        Set TextDocument = Unknown
        Set FormatDefault = TextDocument.Selection.Font.Duplicate
    
        ChDir App.Path
        ChDrive App.Path
        TextDocument.Open RTF_FILE, tomShareDenyWrite Or tomOpenAlways Or tomRTF, 0
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If UnloadMode = vbFormControlMenu Then
            If TextDocument.Saved = tomFalse Then
                If MsgBox("Discard unsaved changes?", vbQuestion Or vbYesNo) = vbYes Then
                    TextDocument.Saved = tomTrue 'Discard.
                Else
                    Cancel = True
                End If
            End If
        End If
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Sub mnuFormatBold_Click()
        TextDocument.Selection.Font.Bold = tomToggle
    End Sub
    
    Private Sub mnuFormatClear_Click()
        TextDocument.Selection.Font = FormatDefault
    End Sub
    
    Private Sub mnuFormatRed_Click()
        TextDocument.Selection.Font.ForeColor = vbRed
    End Sub
    
    Private Sub mnuSave_Click()
        TextDocument.Save vbNull, 0, 0
    End Sub
    The Text Object Model is a COM-based alternative access model for RichEdit, HTML, and Word controls. RichTextBox controls are thin wrappers around a RichEdit control, presenting a TextBox-like access model for compatibility with old 16-bit VB. TOM is superior in most ways.
    Attached Files Attached Files
    Last edited by dilettante; Jan 7th, 2021 at 02:30 PM.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Edit conundrum on RTB. Should be simple

    Note that TOM is documented in the MSDN CD docs that came with VB6, at least the later editions such as October 2001. That was the final free update for VS/VB 6.0 customers and the one you really want installed.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Edit conundrum on RTB. Should be simple

    There isn't a closing event.
    you could test in the form unload event
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Re: Edit conundrum on RTB. Should be simple

    What I meant was the cmdSave updates the file, while the cmdExit closes the form. The user decides when to do both.
    Last edited by VB-only; Jan 7th, 2021 at 08:22 PM.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Edit conundrum on RTB. Should be simple

    Why would you need any "exit" button?

    A normal Form already has a "close" button, and there is also the control menu as well as Alt-F4.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Re: Edit conundrum on RTB. Should be simple

    The exit only removes the form from view. There can be too much 'form' clutter to deal with.

    Well, I decided to go back to using the Change event to make the red "Save" button visible when any data is changed.
    I had hoped to just use the RTB.enable=false property during load and Save processes, but it seems that any Font changes ignore the disable. Since I have a colorization scheme process it caused false positives. I ended up using booleans to prevent execution in the change event.
    Anything to keep it simple. Thanks for all the good ideas.

    ps: First I've ever run across that TOM thing. But too complicated at this point.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

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