Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Counting character in textbox in userform

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Counting character in textbox in userform

msgbox len(tb.text) - len(replace(tb.text,"@","")

Replace was added in xl2k.

use application.substitute() in xl97.

Gert-Jan wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Counting character in textbox in userform

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.


"Dave Peterson" schreef in bericht
...
msgbox len(tb.text) - len(replace(tb.text,"@","")

Replace was added in xl2k.

use application.substitute() in xl97.

Gert-Jan wrote:

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


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Counting character in textbox in userform

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


Gert-Jan wrote:

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.

"Dave Peterson" schreef in bericht
...
msgbox len(tb.text) - len(replace(tb.text,"@","")

Replace was added in xl2k.

use application.substitute() in xl97.

Gert-Jan wrote:

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


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Character limit in textbox Ashley Excel Worksheet Functions 1 September 10th 08 01:33 AM
limit character in textbox Steph[_6_] Excel Programming 2 October 6th 05 09:55 PM
textbox character limits dok112[_38_] Excel Programming 3 June 26th 05 04:48 PM
how to put tab character into textbox? Dirk[_2_] Excel Programming 7 February 11th 04 09:23 AM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 11:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"