CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    1

    Count data in a Textbox

    Can someone tell me how to code a textbox to count the number of letters or characters that a user inputs into that textbox? Then I need to calculate the letters, if letters >= to 100 then charge $4.20, and .02 for each letter over 100.
    I have a label to enter the number of characters and a label that displays the cost.I don't know how to do the Dim part or the count.


  2. #2
    Join Date
    Apr 2001
    Posts
    95

    Re: Count data in a Textbox

    In the event you want to calculate this, put something like:


    Dim fLetters as Single ' This goes just before your sub declaration i.e "private Sub ....."
    Dim fCharge as Single

    ' This assumes there is a label called lblLetters
    ' and a label called lblCharge
    ' it also assumes that lblLetters contains the amount of letters in the textbox

    fLetters = CSng(lblLetters.Caption) ' get number of letters from label and convert to single

    If fLetters >= 100 then
    fCharge = 4.20 + ((fLetters - 100) * .02)
    End If





    Hope that this is something like what you're looking for... if not reply again.
    Best of Luck,
    slcotten :-)


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Count data in a Textbox


    private sub command1_click()
    dim numLetters as integer
    dim amt as single
    numLetters = len (text1.text)
    amt = 4.2
    if numletters >= 100 then
    amt = 4.2 + 0.02 * (numletters - 100)
    end if
    label1.caption = numletters
    label2.caption = amt
    end sub





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

Featured