VB code for Form EventClick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB code for Form EventClick

    I created a form that has the CMM Operators enter in their information at the beginning of a program. Since some of this information is used for filenames, I do not want to allow special characters. In the EventClick section of the Continue button, I added this code...

    Code:
    Dim s As String
    Set s = EditBox1.Text
    If InStr(s,"*") = 0 Then
    
    MsgBox "hello"
    
    End If
    ...I get an error message each time I try it. I did this for testing so I only included "*" but finalized I would like to check if the edit boxes contain "\ / : * ? " < > |" if it does, then display a message and not let them continue until it is fixed. Anyone have any ideas?
    Thanks again for the help.

  • #2
    You can capture at key press.

    It's been a while, but in the text box for the keypress event, evaluate the ASCII code in a Select statement.

    Select Keyascii
    Case (all the ascii codes you want to allow)
    Case Else
    Keyascii=""
    End case

    You can even throw a counter in there for dashes (only one allowed) and periods (likewise)

    EDIT: As I recall now, I think it's actually a key down event

    Comment


    • #3
      I do not see a key press event. I see EventChange and EventPumpData. The rest are Mouse or drag events..

      Comment


      • DJAMS
        DJAMS commented
        Editing a comment
        All of the controls on your form have events an properties. The textbox would have the key down event and a text changed event you could trap invalid characters in either one.

    • #4
      DJAMS RandomJerk I attached a snippet of all available events for an edit box. I do not see anything like a keydown event. Event change maybe?
      Attached Files

      Comment


      • RandomJerk
        RandomJerk commented
        Editing a comment
        Nope, definitely a KeyPress. Odd, as I see mouse click in your options... Is that definitely the dropdown for the TextBox? It now occurs to me that you're trying to capture it from a PC-DMIS dialog? If so, do a Basic dialog instead if feasible....

        https://docs.microsoft.com/en-us/off...-event-example

    • #5
      I'm actually working with an edit box. I figured out my issue and it was an oversight on my end. Pretty stupid mistake actually.
      Code:
      Dim eBox1, strSearch, strSearchFor
      Set strSearch = This.Text
      Set strSearchFor = "*"
      
      If InStr(1,strSearch,strSearchFor,vbTextCompare) <> 0 Then
      
      MsgBox "hello"
      
      End If
      This code works. I originally had it =0 so anytime it opened or typed anything, it was true. I only want something to happen it the character shows up so if it does not return 0, it becomes true. I also didn't have a 1 in the first section of my InStr. I used this code in EventChange and it worked perfectly.

      Comment


      • DJAMS
        DJAMS commented
        Editing a comment
        Glad you got it working. I use the text changed event in our pc-dmis startup form. For the same reason. It's the serial number input field, which becomes part of the filename on the network drive.

    Related Topics

    Collapse

    Working...
    X