Results 1 to 9 of 9

Thread: Classes

  1. #1

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303

    Unhappy

    I'm having a bit of a problem with classes, now I've just started to use thes things.

    I've got a class that checks a text box to make sure that you have entered a correct date format. Now this works fine on a single textbox with no Control array on it. The minute I make it a controlled array my class fails. How if at all do I pass the index across or is there anyway of doing this.

    Please help
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You can pass a control array text box just like a normal text box.

    Code:
    Private Function validate(txtBox As TextBox) As Boolean
    
    End Function
    
    'then you pass a text box like so.
    myBoolean = validate(text1(1))
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    That doesn't seem to work for me for some reason.

    Here is the class itself
    Private WithEvents txtBox As TextBox

    Public Property Set TextCtl(OTextBox As TextBox)

    Set txtBox = OTextBox

    End Property

    Private Sub txtBox_LostFocus()

    'checks for a date format
    If txtBox <> "" Then
    If IsDate(txtBox) Then
    txtBox = Format(txtBox, "dd/mmm/yyyy")
    Else
    MsgBox "Not a correct date format", vbInformation, "Warning"
    txtBox.SetFocus
    End If
    End If

    End Sub

    And this is how a call it

    Sub Form_Load()
    Set clsTextbox = New clsCheckDate
    Set clsTextbox.TextCtl = txtTest
    'Now I want to be able to reference txtTest as txtTest(0)

    End Sub
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Eugh, this is a messy little problem. The error message I get is "Object does not support this set of events," Is that what you're getting?

    If so then the reason this is happening is that when a textbox is part of an array it's events have an extra parameter called Index, this is raised as part of their events, your class does not support this version of the event, it only supports the type with no index parameter.

    unfortunatley I can't think of a solution to this problem, but I can explain what's happening and maybe someone else will think of one.

    sorry

  5. #5

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303

    Unhappy

    Yes thats the same error I keep getting. I figured it had something to do with the index, but I've no idea how to transfer the index with it
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Just an idea, i haven't really thought this through, but could you have a collection of the Class?
    Iain, thats with an i by the way!

  7. #7

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    I've no idea. I haven't really been using classes all that long.
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Iain unfortunatley that isn't the problem, the problem is that if a textbox is part of a control array it raises different events than if it was not part of a control array, we can't find a way to handle the events of an element of a textbox array from inside a class module.


    By the way, have you thought of using a usercontrol? just open up a usercontrol project and stick a textbox inside it, usercontrols have properties methods and events just like classes but have to be placed on the form, if you have a textbox placed on a usercontrol then you automaticly have a textbox and some date validation code with it as soon as you place one of these down. although haveing said that have you thought about the DTPicker control?

  9. #9

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    Many thanks for all your comments, I'll that date picker might sort a few problems
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

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