very stupid question

Discussion in 'MCSD' started by Jaime, Sep 21, 2003.

  1. Jaime

    Jaime Guest

    Private Sub Button1_Click(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    Button1.Click
    TextBox1.MaxLength = 2
    TextBox1.Text = "Hello"

    End Sub
    End Class

    why when I run this does it display hello instead of he?
     
    Jaime, Sep 21, 2003
    #1
    1. Advertising

  2. Jaime

    maria Guest

    Not stupid, but maybe a little lazy?
    You can find answers to this kind of question by searching
    msdn - as I just did ;o))

    Check out these two pages

    http://msdn.microsoft.com/library/default.asp?
    url=/library/en-
    us/vbcon/html/vberrmaxlengthpropertybehaviorhaschanged.asp

    http://msdn.microsoft.com/library/default.asp?
    url=/library/en-
    us/vbcon/html/vbconcontrolpropertymethodeventchangesinvisua
    lbasicnet.asp

    Happy hunting

    >-----Original Message-----
    > Private Sub Button1_Click(ByVal sender As
    >System.Object, ByVal e As System.EventArgs) Handles
    >Button1.Click
    > TextBox1.MaxLength = 2
    > TextBox1.Text = "Hello"
    >
    > End Sub
    >End Class
    >
    >why when I run this does it display hello instead of he?
    >.
    >
     
    maria, Sep 21, 2003
    #2
    1. Advertising

  3. Jaime

    Jay Walters Guest

    I didn't look it up - but if you think about it, the
    answer is pretty easy. (not meaning to insult).

    We commonly use MaxLength to limit the input to a text
    box right? -- So my guess would be that MaxLength only
    affects input (internally on KeyDown). Hence writing any
    code that sets the text would by-pass this check, which
    is by design and not a bug.

    Hope this helps.



    >-----Original Message-----
    > Private Sub Button1_Click(ByVal sender As
    >System.Object, ByVal e As System.EventArgs) Handles
    >Button1.Click
    > TextBox1.MaxLength = 2
    > TextBox1.Text = "Hello"
    >
    > End Sub
    >End Class
    >
    >why when I run this does it display hello instead of he?
    >.
    >
     
    Jay Walters, Sep 22, 2003
    #3
  4. Jaime

    Jaime Guest

    Yes that helps a whole lot, thank you so much.
    >-----Original Message-----
    >I didn't look it up - but if you think about it, the
    >answer is pretty easy. (not meaning to insult).
    >
    >We commonly use MaxLength to limit the input to a text
    >box right? -- So my guess would be that MaxLength only
    >affects input (internally on KeyDown). Hence writing any
    >code that sets the text would by-pass this check, which
    >is by design and not a bug.
    >
    >Hope this helps.
    >
    >
    >
    >>-----Original Message-----
    >> Private Sub Button1_Click(ByVal sender As
    >>System.Object, ByVal e As System.EventArgs) Handles
    >>Button1.Click
    >> TextBox1.MaxLength = 2
    >> TextBox1.Text = "Hello"
    >>
    >> End Sub
    >>End Class
    >>
    >>why when I run this does it display hello instead of he?
    >>.
    >>

    >.
    >
     
    Jaime, Sep 22, 2003
    #4
  5. The reason is that the internal code which states to display *hello* is
    overriding the keyword *MaxLength* even though that line of code occurs
    after rather than before.

    ---
    Sign up to get free daily practice questions at: http://www.QoD.US/i-54.htm
    View this thread: http://www.examnotes.net/article1022871.html
    Helen of Troy

    ------------------------------------------------------------------------
    Helen of Troy's Profile: http://www.examnotes.net/forums/member.php?action=getinfo&userid=173331
     
    Helen of Troy, Sep 22, 2003
    #5
  6. Jaime

    Kline Sphere Guest

    >So my guess would be that MaxLength only
    >affects input (internally on KeyDown)


    .... Or on a paste the internal text is set as supplied, although only
    maxlength characters are shown (as the doughtier of Tyndarecus has
    already said). Using setwindowtext will cause the whole of the text to
    be shown, thus ignoring the value of maxlength.
     
    Kline Sphere, Sep 22, 2003
    #6
  7. Jaime

    Hassan anwr Guest

    þþÊã ßÊÇÈÉ Jay Walters <> Ýí ÃÎÈÇÑ
    ÇáÑÓÇáÉ:c0ff01c381e6$9b2c78b0$...
    > - doughtier of Tyndarecus - You're too funny. :)
    >
    > >-----Original Message-----
    > >>So my guess would be that MaxLength only
    > >>affects input (internally on KeyDown)

    > >
    > >.... Or on a paste the internal text is set as supplied,

    > although only
    > >maxlength characters are shown (as the doughtier of

    > Tyndarecus has
    > >already said). Using setwindowtext will cause the whole

    > of the text to
    > >be shown, thus ignoring the value of maxlength.
    > >.
    > >
     
    Hassan anwr, Oct 6, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kpg

    stupid stupid stupid

    kpg, Oct 26, 2004, in forum: MCSE
    Replies:
    17
    Views:
    874
    T-Bone
    Nov 26, 2004
  2. Thomas Reed

    Quick Book file access very very very slow

    Thomas Reed, Apr 9, 2004, in forum: Computer Support
    Replies:
    7
    Views:
    811
    Palindrome
    Apr 9, 2004
  3. =?ISO-8859-1?Q?R=F4g=EAr?=
    Replies:
    6
    Views:
    816
  4. Michael P Gabriel

    Stupid is as Stupid Does!

    Michael P Gabriel, Jun 24, 2004, in forum: Digital Photography
    Replies:
    3
    Views:
    413
    stewy
    Jun 26, 2004
  5. john
    Replies:
    0
    Views:
    670
Loading...

Share This Page