Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / June 2006

Tip: Looking for answers? Try searching our database.

Counting character in textbox in userform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gert-Jan - 20 Jun 2006 12:08 GMT
In a textbox in my userform only one @ is allowed. How can VBA see the
second @ and delete it?
Dave Peterson - 20 Jun 2006 12:28 GMT
msgbox len(tb.text) - len(replace(tb.text,"@","")

Replace was added in xl2k.

use application.substitute() in xl97.

> In a textbox in my userform only one @ is allowed. How can VBA see the
> second @ and delete it?

Signature

Dave Peterson

Gert-Jan - 20 Jun 2006 12:42 GMT
Sorry, but that doesn't work: it replaced al the mentioned characters. I
using this code for NOT WANTED characters:

Private Sub aantalpersonen2_Change()
   Dim i As Long
   For i = 1 To Len(Me.aantalpersonen2.Text)
   Select Case Asc(Mid(Me.aantalpersonen2.Text, i, 1))
   Case 46, 48 To 57
   Case Else
   Dim Msg, Style, Title, Response
   Msg = Range("error2").Value
   Style = vbInformation
   Title = Range("naam").Value
   Response = MsgBox(Msg, Style, Title)
   Me.aantalpersonen2.Value = Left(Me.aantalpersonen2.Text,
Len(Me.aantalpersonen2.Text) - 1)
   Exit For
   End Select
   Next i
End Sub

I suppose it should be possible to count the ASC 46, and if there is already
one the next one will be deleted.

> msgbox len(tb.text) - len(replace(tb.text,"@","")
>
[quoted text clipped - 4 lines]
>> In a textbox in my userform only one @ is allowed. How can VBA see the
>> second @ and delete it?
Dave Peterson - 20 Jun 2006 12:48 GMT
The msgbox didn't replace any characters.

It showed how many @'s were in the textbox.

if (len(tb.text) - len(replace(tb.text,"@","")) = 1 then
  'ok
else
  'too many or not enough
end if
 

> Sorry, but that doesn't work: it replaced al the mentioned characters. I
> using this code for NOT WANTED characters:
[quoted text clipped - 32 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.