Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
725
Faking an overstrike mode
posted

Background:

I'm using a WinGrid to display some tabular data. One field is a 20 character (Max) field. The data in this colum (call it a PID) is based on fixed length data for various parts.

Ex the first 8 characters mean sometinh, the next 3 mean something, etc. thus it's VERY important to maintain the character spacing.

 I have coded a "overstrike" mode for pretty much every action including a backspace key.

 

If the user hit backspace - the ideal behavior wouldb e to erase the character just to the left of the cursor, replace it with a space, and move the cursor one space left.

EX. (Using the | character to represent the cursor)  NORT|ON  when the backspace key was pressed would end up being NOR| ON

I had previously coded this and now for some (as of yet) unexplained reason it's behaving oddly - it either moves to far, or throws an error that I've attempted to go beyond a start of 0 (i.e. 0-1)

The code is old and crappy and I honestly have no idea today why I did it this way 2 years ago but - here's a portion of what I have now.

 

This fires in the _KeyDown event.

With ugPIDdata.ActiveCell
                Select Case e.KeyValue
                    Case Is = 8 ' Backspace key
                        If .SelStart > 0 Then .SelStart = .SelStart - 1
                        .SelLength = 1
                        .SelText = "  "
                        .SelStart = .SelStart - 1

. . .

End Case

End With

 

Any suggestions on why this suddenly stopped working or for way to handle it better would be greatly appreciated.

I know it should be simple but I can't seem to wrap my head around it today for some reason.

 

Thanks

  • 725
    Verified Answer
    Offline posted

    Nevermind - I finally figured out the problem wasn't in the code, but rather the data being handled.

    It was throwing errors when the user "backspaced" ina numeric field & it was left with spaces inthe "middle" of the number when it tried to convert back to a numeric value.

    I added a quick check for "isnumeric" to skip this code & all is well.