Solved

Problem with VBPJ code. (WithEvents)

Posted on 1998-06-25
11
208 Views
Last Modified: 2006-11-17
In the last Visual Basic Programmer's Journal (July), there is an article Titled Resize your forms automatically.  At the beginning of the article the talk about making an extended textbox class.  This is definitely a cool thing to due because the textbox control is lacking in several areas.

Now the problem:
in the declarations section I have the line
  Private Numbox as new ExtenededTextbox

then in the Form_Load event I have the line
  Set numbox.textbox = txtNumeric

On this line I get an textbox Method failed error.

My ExtendedTextbox is not exactly the same as what is shown in the VBPJ.  It contains code to due several types of validation depending on the Type that you set it to.  It also has an errorcolor for when someone screws up entering in the data and it does not meet the validation rules, but it still follows the same principal.  So can someone help me.  If needed I can paste in the full code of the ActiveX DLL.
0
Comment
Question by:Jagar
  • 5
  • 4
  • 2
11 Comments
 
LVL 4

Expert Comment

by:zsi
ID: 1464255
Jagar,

Go ahead and paste the code.  I don't feel like typing it all in.  :)
0
 
LVL 2

Author Comment

by:Jagar
ID: 1464256
Here's the code in my DLL

Public WithEvents TextBox As TextBox
Public Enum UDTBoxType
    None = 0
    NumericTextBox
    IntegerTextBox
    CurrencyTextBox
    DateTextBox
    EMailTextBox
    PhoneTextBox
End Enum

Private mBoxType As UDTBoxType 'local copy
Private mErrorColor As OLE_COLOR 'local copy

Public Property Let ErrorColor(ByVal vData As OLE_COLOR)
  mErrorColor = vData
End Property

Public Property Get ErrorColor() As OLE_COLOR
  ErrorColor = mErrorColor
End Property

Public Property Let BoxType(ByVal vData As Integer)
  mBoxType = vData
End Property

'Public Property Set BoxType(ByVal vData As Object)
'  Set mBoxType = vData
'End Property

Public Property Get BoxType() As Integer
  Set BoxType = mBoxType
End Property

Private Sub Class_Initialize()
  mBoxType = None
  ErrorColor = &HC0C0FF
End Sub

Private Sub Textbox_KeyPress(KeyAscii As Integer)
  On Local Error Resume Next
  If KeyAscii = 8 And txtInput.SelStart <> 0 Then
    If txtInput.SelLength > 0 Then
      txtInput.SelText = ""
      KeyAscii = 0
      Exit Sub
    End If
    txtInput.SelStart = txtInput.SelStart - 1
    txtInput.SelLength = 1
    txtInput.SelText = ""
  End If
  If KeyAscii = 8 And txtInput.SelStart = 0 And txtInput.SelLength > 0 Then
   txtInput.SelText = ""
  End If
  If mBoxType = CurrencyTextBox Then
    If KeyAscii = 36 Then
      If InStr(1, txtInput.Text, "$", vbTextCompare) Then KeyAscii = 0
    End If
    If KeyAscii = 46 Then
      If InStr(1, txtInput.Text, ".", vbTextCompare) Then KeyAscii = 0
    End If
    If KeyAscii = 44 Then
      If InStr(1, txtInput.Text, ".", vbTextCompare) < txtInput.SelStart And _
         InStr(1, txtInput.Text, ".", vbTextCompare) <> 0 Then KeyAscii = 0
    End If
    If KeyAscii < 48 Or KeyAscii > 57 Then
      If KeyAscii <> 36 And KeyAscii <> 46 And KeyAscii <> 44 Then KeyAscii = 0
    End If
  ElseIf mBoxType = DateTextBox Then
    Dim tmpPlacement As Integer
 
    If Style = dtShortDate Then
      If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
    End If
    If Len(TextBox.Text) = 1 Or Len(TextBox.Text) = 4 Then
      tmpPlacement = TextBox.SelStart
      TextBox.Text = TextBox.Text & Chr(KeyAscii) & "/"
      KeyAscii = 0
      TextBox.SelStart = tmpPlacement + 2
    End If
  ElseIf mBoxType = EMailTextBox Then
    If KeyAscii = 64 Then
      If InStr(1, TextBox.Text, "@", vbTextCompare) Then KeyAscii = 0
      If TextBox.SelStart = 0 Then KeyAscii = 0
    End If
    If KeyAscii = 46 Then
      If InStr(1, TextBox.Text, ".", vbTextCompare) Then KeyAscii = 0
      If TextBox.SelStart = 1 Then KeyAscii = 0
      If InStr(1, TextBox.Text, "@", vbTextCompare) = 0 Then KeyAscii = 0
      If InStr(1, TextBox.Text, "@", vbTextCompare) = TextBox.SelStart Then KeyAscii = 0
    End If
  ElseIf mBoxType = IntegerTextBox Then
    If KeyAscii > vbKey9 Or KeyAscii < vbKey0 Then
      KeyAscii = 0
    End If
  ElseIf mBoxType = NumericTextBox Then
    If KeyAscii > 57 Or KeyAscii < 48 Then
      If KeyAscii <> 46 Then
        KeyAscii = 0
      Else
        If InStr(1, txtInput.Text, ".", vbTextCompare) Then KeyAscii = 0
      End If
    End If
  ElseIf mBoxType = PhoneTextBox Then
    If KeyAscii = 40 Then
      If InStr(1, TextBox.Text, "(", vbTextCompare) Then KeyAscii = 0
    End If
    If KeyAscii = 41 Then
      If InStr(1, TextBox.Text, ")", vbTextCompare) Then KeyAscii = 0
      If InStr(1, TextBox.Text, "(", vbTextCompare) = 0 Then KeyAscii = 0
      If InStr(1, TextBox.Text, "(", vbTextCompare) > TextBox.SelStart Then KeyAscii = 0
    End If
    If KeyAscii = 69 Then KeyAscii = 101
    If KeyAscii = 88 Then KeyAscii = 120
    If KeyAscii = 84 Then KeyAscii = 116
    If KeyAscii = 101 Then
      If InStr(1, TextBox.Text, "e", vbTextCompare) Then KeyAscii = 0
    End If
    If KeyAscii = 120 Then
      If InStr(1, TextBox.Text, "x", vbTextCompare) Then KeyAscii = 0
    End If
    If KeyAscii = 116 Then
      If InStr(1, TextBox.Text, "t", vbTextCompare) Then KeyAscii = 0
    End If
    If (KeyAscii < 48 Or KeyAscii > 57) Then
      If (KeyAscii <> 32 And KeyAscii <> 46 And KeyAscii <> 101 _
         And KeyAscii <> 120 And KeyAscii <> 116 _
         And KeyAscii <> 40 And KeyAscii <> 41) Then KeyAscii = 0
    End If
  End If
End Sub

Private Sub Textbox_LostFocus()
  If mBoxType = CurrencyTextBox Then
    Dim curValue As Currency
    Err.Clear
    curValue = TextBox.Text
    If Err.Number Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
    End If
  ElseIf mBoxType = DateTextBox Then
    If Not IsDate(TextBox.Text) Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
    End If
  ElseIf mBoxType = EMailTextBox Then
    Dim PeriodSymbol As Integer
    Dim AtSymbol As Integer
 
    TextBox.Tag = TextBox.BackColor
    PeriodSymbol = InStr(1, TextBox.Text, ".", vbTextCompare)
    AtSymbol = InStr(1, TextBox.Text, "@", vbTextCompare)
    If PeriodSymbol = 0 Then TextBox.BackColor = ErrorColor
    If AtSymbol = 0 Then TextBox.BackColor = ErrorColor
    If PeriodSymbol = Len(TextBox.Text) Then TextBox.BackColor = ErrorColor
    If AtSymbol = Len(TextBox.Text) Then TextBox.BackColor = ErrorColor
  ElseIf mBoxType = IntegerTextBox Then
    If Not IsNumeric(TextBox.Text) Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
    End If
  ElseIf mBoxType = NumericTextBox Then
    If Not IsNumeric(TextBox.Text) Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
    End If
  ElseIf mBoxType = PhoneTextBox Then
    If Right(TextBox.Text, 1) < "0" And Right(TextBox.Text, 1) < "9" Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
      Exit Sub
    End If
    If Len(TextBox.Text) < 7 Then
      TextBox.Tag = TextBox.BackColor
      TextBox.BackColor = ErrorColor
    End If
  End If
End Sub

Private Sub Textbox_GotFocus()
  On Local Error Resume Next
  TextBox.SelStart = 0
  TextBox.SelLength = Len(TextBox.Text)
  If Len(TextBox.Tag) Then
    TextBox.BackColor = TextBox.Tag
    TextBox.Tag = ""
  End If
End Sub

0
 
LVL 4

Expert Comment

by:zsi
ID: 1464257
Jagar,

The code will not compile as it is imcomplete.  Why don't you send your project to me at expert@zs.com?


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:Jagar
ID: 1464258
Edited text of question
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1464259
Jagar, can you send it to me too

aecornetto@sai2000.com
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1464260
How did that work out for ya?
0
 
LVL 2

Author Comment

by:Jagar
ID: 1464261
I still get the error:

  Method 'TextBox' of object '_ExtendedTextBox' failed

I get this error on the line that says:

  Set TextNone.Textbox = Text1
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1464262
jagar:

I used your code, and it worked fine.  There is NO problem with your DLL.  It is probably with the way you have created a copy of it.  Send me the extended textbox project again ALONG with your testproject.

Anthony
0
 
LVL 2

Author Comment

by:Jagar
ID: 1464263
It still did not work.
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 50 total points
ID: 1464264
dude...   You do not know how to test an ActiveX DLL that's why it is not working.  The code works.
0
 
LVL 2

Author Comment

by:Jagar
ID: 1464265
Thanks for sticking with me it works now.
You know what I have tested other DLLs within 2 VB processes.  That's why I continued to do it the way I had before.
Again thanks for your help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question