Solved

Problem with VBPJ code. (WithEvents)

Posted on 1998-06-25
11
189 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now