473,507 Members | 13,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting commas in a text field

I have a text field on a form which has names with a comma between them like
this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put the
number into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?

dixie
Nov 13 '05 #1
6 7439
On Thu, 16 Sep 2004 09:52:27 +1000, dixie wrote:
I have a text field on a form which has names with a comma between them like
this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put the
number into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?

dixie


Air code:
In a module:
Function CountCommas(StringIn as String) as String
Dim intX as Integer
Dim intY as integer
intX = InStr(StringIn,",")
Do While intX <> 0
intY = intY + 1
intX = InStr(intX + 1,StringIn,",")
Loop
CountCommas = intY
End Function

You can call it from a query.
Words: CountCommas([FieldName]) + 1
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #2
Easiest way is to use the Split function:

Public Function CountStringItems( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItems = ArrayCount(varaItems)
End Function

Public Function ArrayCount(varArray As Variant)
ArrayCount = UBound(varArray) - LBound(varArray) + 1
End Function

On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail.com> wrote:
I have a text field on a form which has names with a comma between them like
this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put the
number into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?

dixie


Nov 13 '05 #3
On Thu, 16 Sep 2004 02:41:48 GMT, fredg wrote:
On Thu, 16 Sep 2004 09:52:27 +1000, dixie wrote:
I have a text field on a form which has names with a comma between them like
this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put the
number into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?

dixie


Air code:
In a module:
Function CountCommas(StringIn as String) as String
Dim intX as Integer
Dim intY as integer
intX = InStr(StringIn,",")
Do While intX <> 0
intY = intY + 1
intX = InStr(intX + 1,StringIn,",")
Loop
CountCommas = intY
End Function

You can call it from a query.
Words: CountCommas([FieldName]) + 1


I gave you information on how to count commas in a field, but your
basic quest is to separate text into various fields.
You don't need to count the commas.
Look up the Split() function in VBA help.
It will parse the field without need for this counting function.

Public Function ParseText(TextIn As String, X) As Variant
On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)
End Function
============
Call it from a query:
Name1:ParseText([Fullfield],0)
Name2:ParseText([FullField],1)
etc.

Note that the array is zero based.

You get 2 functions today for the price of one. :-)
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #4
I am a little at a loss as to how to run this on my form to count the names
in the text box txtNames which has names separated by commas. Sorry, but
I'm not good with public functions. I have put it into the main module, but
how do I use it on the form?

dixie

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:dp********************************@4ax.com...
Easiest way is to use the Split function:

Public Function CountStringItems( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItems = ArrayCount(varaItems)
End Function

Public Function ArrayCount(varArray As Variant)
ArrayCount = UBound(varArray) - LBound(varArray) + 1
End Function

On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail.com> wrote:
I have a text field on a form which has names with a comma between them likethis: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put thenumber into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?

dixie

Nov 13 '05 #5
Well, where does the value get used, and how? Do you mean it's displayed in
another control on the form? If so, you could set the Control Source property
of that control to =CountStringItems([txtNames] & "", ",").

The [txtNames] & "" part converts the value to a blank string if it is Null.
Ichecked, and the function correctly returns 0 for a blank string.

On Fri, 17 Sep 2004 13:57:46 +1000, "dixie" <di****@dogmail.com> wrote:
I am a little at a loss as to how to run this on my form to count the names
in the text box txtNames which has names separated by commas. Sorry, but
I'm not good with public functions. I have put it into the main module, but
how do I use it on the form?

dixie

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:dp********************************@4ax.com.. .
Easiest way is to use the Split function:

Public Function CountStringItems( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItems = ArrayCount(varaItems)
End Function

Public Function ArrayCount(varArray As Variant)
ArrayCount = UBound(varArray) - LBound(varArray) + 1
End Function

On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail.com> wrote:
>I have a text field on a form which has names with a comma between themlike >this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
>procedure that will count the number of people in this text box and putthe >number into another text box (4 in the case above). If I could count the
>number of commas + 1, this would do it. Can anyone please help me with a
>way to achieve this?
>
>dixie
>


Nov 13 '05 #6
Steve, your a genius. That worked straight away. I can even see it
dynamically updating on the screen as I add people to the text box. Thanks
for your kind help.

dixie

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:2c********************************@4ax.com...
Well, where does the value get used, and how? Do you mean it's displayed in another control on the form? If so, you could set the Control Source property of that control to =CountStringItems([txtNames] & "", ",").

The [txtNames] & "" part converts the value to a blank string if it is Null. Ichecked, and the function correctly returns 0 for a blank string.

On Fri, 17 Sep 2004 13:57:46 +1000, "dixie" <di****@dogmail.com> wrote:
I am a little at a loss as to how to run this on my form to count the namesin the text box txtNames which has names separated by commas. Sorry, but
I'm not good with public functions. I have put it into the main module, buthow do I use it on the form?

dixie

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:dp********************************@4ax.com.. .
Easiest way is to use the Split function:

Public Function CountStringItems( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItems = ArrayCount(varaItems)
End Function

Public Function ArrayCount(varArray As Variant)
ArrayCount = UBound(varArray) - LBound(varArray) + 1
End Function

On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail.com> wrote:

>I have a text field on a form which has names with a comma between them
like
>this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
>procedure that will count the number of people in this text box and
putthe
>number into another text box (4 in the case above). If I could count

the >number of commas + 1, this would do it. Can anyone please help me with a >way to achieve this?
>
>dixie
>

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2259
by: Mike N. | last post by:
Hello: I have a form that contains a multiple-select field that has 12 options in it. I would like the user to be able to select UP TO FOUR of those options. If they select more than four, I...
7
8293
by: AES | last post by:
Encountered a URL containing a comma the other day -- the first time I've ever noticed that, so far as I can recall. It worked fine, however, and I gather commas are legal in URLs. Out of...
8
3836
by: DrNoose | last post by:
Hi! I'm writing a program that is supposed to read a line of input, count the words and the number of occurrences of each letter. Then it should prints the number of occurrences of each letter...
3
1952
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
4
2477
by: striker | last post by:
I have a comma delimited text file that has multiple instances of multiple commas. Each file will contain approximatley 300 lines. For example: one, two, three,,,,four,five,,,,six one, two,...
4
1909
by: Dado | last post by:
I have a next situation with the textbox field: A - B = C 1. How to fill the A fill with the data from my previous recordset ? Can I do it with the expression builder ? 2. I want that every...
4
23476
by: MLH | last post by:
MyString = "All men are created equal" Debug.PrintLen(MyString) Now that's easy. But how about just counting the letter "e"? Or, if I were curious to know how many commas were in the string....
14
7050
by: Adrienne Boswell | last post by:
Although this is a client side issue, I am also posting to asp.general in case there is someway to do this only server side (which I would prefer). Here's my form: <form method="post"...
11
10426
by: Dooza | last post by:
Using ASP/VB I need to remove unwanted commas from the end of a field that will be use in an array. There are items in the field that are comma separated, so I don't want to remove them, just the...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.