11 Replies - 2701 Views - Last Post: 10 January 2013 - 01:05 PM Rate Topic: -----

#1 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 142
  • Joined: 21-January 12

label max length

Posted 10 January 2013 - 08:04 AM

how many character can be hold by a label, can we make it no limit?
Is This A Good Question/Topic? 0
  • +

Replies To: label max length

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3516
  • View blog
  • Posts: 12,005
  • Joined: 12-December 12

Re: label max length

Posted 10 January 2013 - 08:15 AM

A label doesn't have a MaxLength property as it is not an editable region of a form. I suspect a form may have a maximum height somewhere.. but haven't investigated this too deeply.

Assuming you are dynamically changing the label-text, then just count the number of characters before you change the text.

A label has a MaximumSize property, but this is not the same as a maximum-length of characters.

This post has been edited by andrewsw: 10 January 2013 - 08:22 AM

Was This Post Helpful? 0
  • +
  • -

#3 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 142
  • Joined: 21-January 12

Re: label max length

Posted 10 January 2013 - 08:21 AM

i try make something like scrolling banner announcement with that, so number of char/word is vary, depend on user input. can we make it no limit?

This post has been edited by artemix22: 10 January 2013 - 08:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: label max length

Posted 10 January 2013 - 09:28 AM

So I did some experimenting to see if there's an upper limit to the number of characters a label control can take, and while there doesn't seem to be a built in limit, if you try to go over 131,072 characters, the .text property of the label seems to lose its value somehow. The actual number might not be 131,072, but I was increasing the number of characters in the .text property using a geometric progression, and 131,072 was the last number of digits it would display before losing its value.

So, my question to you becomes: Isn't that enough characters? The average person, reading in English as their native language can read about 300 words per minute. If you take an average of about 4.5 letters per word, that means the average person can process about 1350 characters per minute. There are 34,164,000 minutes in the life of a 65-year old person, so, if that person did nothing but read your scrolling message box, 24 hours a day every day from birth to death, they'd have time to process 46,121,400,000 characters before their untimely death from acute eyestrain. There are 11 digits in 46,121,400,000, so that means you have another 131,061 digits available in your label object to display the remainder of your text to the dessicated corpse of your end user. Remind me again why you need it to be unlimited?
Was This Post Helpful? 0
  • +
  • -

#5 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 142
  • Joined: 21-January 12

Re: label max length

Posted 10 January 2013 - 09:54 AM

it's not 131,072 (if it is as much like you said, i will not question it bro), it is 6,856 character (including space), here is what i do for experiment :

in a form i add 1 RichTextBox, 1 Button, 1 Timer and 1 Label.

button code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = RichTextBox1.Text
        Timer1.Start()
End Sub



timer code :

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Left -= 1
        If Label1.Right < Me.Left Then
            Label1.Left = Me.Right
        End If
End Sub



run and try to add 6,857 character on RTB, label will not show text from RTB, but if you add 6,856 character it will show the text.

here is character counter to make it easy on counting : character counter

it's for government announcement bro, sure i need it no limit.

This post has been edited by artemix22: 10 January 2013 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#6 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: label max length

Posted 10 January 2013 - 10:09 AM

View Postartemix22, on 10 January 2013 - 09:54 AM, said:

it's not 131,072 (if it is as much like you said, i will not question it bro), it is 6,856 character (including space), here is what i do for experiment :

in a form i add 1 RichTextBox, 1 Button, 1 Timer and 1 Label.

button code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = RichTextBox1.Text
        Timer1.Start()
End Sub



timer code :

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Left -= 1
        If Label1.Right < Me.Left Then
            Label1.Left = Me.Right
        End If
End Sub



run and try to add 6,857 character on RTB, label will not show text from RTB, but if you add 6,856 character it will show the text.

here is character counter to make it easy on counting : character counter

it's for government announcement bro, sure i need it no limit.


Well isn't that interesting? You're correct that the label won't display over 6,856, but the .text value will hold way more characters than that, so it's not a problem with the limit to what it can hold, only a limit of what it can display.

The way I would fix this is to stop trying to display the entire message at once; instead, just read the RTB character by character and add each character to the end of the string displayed by your label until you hit however many characters the label can display, then drop the oldest character from the beginning of the string and add the next character to the end of the string until you've displayed the whole message, then loop back to the beginning and start it again.

Also, I didn't mean to say that the .text property maxes out at 131,072 characters above, I meant to say it maxes out at a number of characters with 131,072 zeros, for which I'm pretty sure no one has invented a word.

This post has been edited by C.Andrews: 10 January 2013 - 10:12 AM

Was This Post Helpful? 1
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3516
  • View blog
  • Posts: 12,005
  • Joined: 12-December 12

Re: label max length

Posted 10 January 2013 - 10:14 AM

I think it might also make a difference whether the characters are assigned before the label is rendered.
Was This Post Helpful? 0
  • +
  • -

#8 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: label max length

Posted 10 January 2013 - 10:25 AM

View Postandrewsw, on 10 January 2013 - 10:14 AM, said:

I think it might also make a difference whether the characters are assigned before the label is rendered.


I thought about that too, but I threw in a refresh after the value changes each time to rule that out in my experimental code, so I don't think that's it. The label just refuses to display its value after a certain point, and loses its value completely after a later point.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3516
  • View blog
  • Posts: 12,005
  • Joined: 12-December 12

Re: label max length

Posted 10 January 2013 - 10:28 AM

..could use a TextBox and make it resemble a Label I suppose..

Edited: Scrub this, it would probably stutter.

This post has been edited by andrewsw: 10 January 2013 - 10:29 AM

Was This Post Helpful? 1
  • +
  • -

#10 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 142
  • Joined: 21-January 12

Re: label max length

Posted 10 January 2013 - 10:33 AM

textbox, maybe that is the only other way i guess, at least it will hold 32,767 of char, much better than label.

btw thanks for your reply guys, i appreciate it.

This post has been edited by artemix22: 10 January 2013 - 10:38 AM

Was This Post Helpful? 0
  • +
  • -

#11 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: label max length

Posted 10 January 2013 - 12:46 PM

So, I banged out a solution like I mentioned here a few minutes ago, and I decided it doesn't animated as smoothly as I'd like. I used the following in a form with 1 textbox and 1 ~50 character wide label:

Public Class Form1
    Dim strToDisplay As String
    Dim intStep As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If intStep > Len(TextBox1.Text) - 1 Then intStep = 0
        strToDisplay = TextBox1.Text.Substring(intStep, 1)
        Label1.Text = Label1.Text & strToDisplay
        If Len(Label1.Text) > 50 Then Label1.Text = Label1.Text.Substring(1, 50)
        Label1.Update()

        intStep += 1
    End Sub
End Class



While looking for a simple solution to make it animated better, I came across this thread. I tried to attach their solution to this message (in case the link goes dead), but I keep getting a non-specific server error when I try to attach it. Sorry

-C
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3516
  • View blog
  • Posts: 12,005
  • Joined: 12-December 12

Re: label max length

Posted 10 January 2013 - 01:05 PM

That link indicates a solution. Alternatively, WPF may have better rendering(?) and perhaps offer a control similar to a marquee. There's a ScrollViewer; no idea what it does though :).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1