After entering text in a text box how do i count the number of spa

G

Guest

This is the program and this is the way the instructor wants us to do i and i
don't know how to go about doing it. It states allow the user to enter
multiple lines in a text box. In the click event of the command button, use a
For loop and the Len function to iterate through each character in the text
box. Every time a space character is found, increment a porcedure-level
variable by 1. After the loop has completed, output the number of spaces
found in a message box. This is exactly how he wants it done and i don't know
how to do it. any suggestions would be helpful. Thanks Judith Spurlock
 
R

ruralguy via AccessMonster.com

Hi Judith,
If I were you, I would look into the Mid() function to walk through a string.
 
M

missinglinq via AccessMonster.com

As RuralGuy said, you need to use Mid$ in your loop to walk thru your field,
checking each character to see if it's a space. You need to use Access Help
to see exactly how the functions Mid and Asc work.

A standard Loop is:

For I = 1 To Whatever
'Do something here
Next I

The Whatever in this case is the number of characters in your field, so we
get that number by using

Len(YourFieldName)

Next we need to assign, in turn, each character to a variable; we'll call it
Char.

And finally we need to set up a variable as a counter; we'll call it
SpaceCounter.

So:

Private Sub YourCommandButton_Click()
Dim SpaceCounter as Integer 'Dim the counter
Dim Char as String 'Dim the variable that will hold the characters
SpaceCounter = 0 'Set your counter to zero

For I = 1 To Len(YourFieldName) 'Step thru the field one character at a time
Char = Mid(YourFieldName, I, 1) 'Assign each character to the variable
Char
If (Asc(Char)) = 32 Then 'The Asc function returns the code for the
character. The code for [Space]
'is 32.
SpaceCounter = SpaceCounter + 1 'If the Asc for the character is 32,
you add one to the
' SpaceCounter
End If
Next I 'Loop to the next character

If SpaceCounter > 0 Then 'If at least one character is a space
MsgBox("The Space Count is " & SpaceCounter) 'Throw up a message box
with the

' SpaceCounter's value in it
End If
End Sub
 
G

Guest

What do you mean by your feild name i guess i'm dense i tried to do this
program and it doesn't work. I guess because i don't understand what you mean
by the field name. and i don't understand the part If(Asc(Char)) = 32 Then
Why would you use 32? or is that just an example? I'm not understanding what
this part of the code does. Please help me again. Judith spurlock
 
R

ruralguy via AccessMonster.com

I think you need to hit the books a little harder than you have in the past.
MissingLinq gave you almost all of the answers and yet you are still baffeled?
I'll bet if you applied yourself, this stuff would be a snap. I'll give you
one more hint: the decimal value for the ASCII space character is 32.
What do you mean by your feild name i guess i'm dense i tried to do this
program and it doesn't work. I guess because i don't understand what you mean
by the field name. and i don't understand the part If(Asc(Char)) = 32 Then
Why would you use 32? or is that just an example? I'm not understanding what
this part of the code does. Please help me again. Judith spurlock
As RuralGuy said, you need to use Mid$ in your loop to walk thru your field,
checking each character to see if it's a space. You need to use Access Help
[quoted text clipped - 43 lines]
End If
End Sub
 
D

Dirk Goldgar

In
JudithSpurlock said:
This is the program and this is the way the instructor wants us to do
i and i don't know how to go about doing it. It states allow the user
to enter multiple lines in a text box. In the click event of the
command button, use a For loop and the Len function to iterate
through each character in the text box. Every time a space character
is found, increment a porcedure-level variable by 1. After the loop
has completed, output the number of spaces found in a message box.
This is exactly how he wants it done and i don't know how to do it.
any suggestions would be helpful. Thanks Judith Spurlock

The exact code for this was posted by Stefan Hoffman as the third of
three examples, in his reply to your earlier thread.
 
M

missinglinq via AccessMonster.com

When you use code that someone has posted on this or other forums, you have
to replace the names of controls in the code with the actual name of your own
controls! Replace YourFieldName with the actual name of the textbox control
you're entering the text in, and replace YourCommandButton with the name of
the button you're using.
 
G

Guest

JudithSpurlock said:
This is the program and this is the way the instructor wants us to do i and i
don't know how to go about doing it. It states allow the user to enter
multiple lines in a text box. In the click event of the command button, use a
For loop and the Len function to iterate through each character in the text
box. Every time a space character is found, increment a porcedure-level
variable by 1. After the loop has completed, output the number of spaces
found in a message box. This is exactly how he wants it done and i don't know
how to do it. any suggestions would be helpful. Thanks Judith Spurlock
 
G

Guest

Missingling Thank you very much for your help i couldn't have done it without
you. I really appreciate your help the only thing i didn't understand were
the fieldnames and now after you described what to do the program is working
correctly. thanks again Judith Spurlock
 
M

missinglinq via AccessMonster.com

What did you mean to say, Judith?
This is the program and this is the way the instructor wants us to do i and i
don't know how to go about doing it. It states allow the user to enter
[quoted text clipped - 4 lines]
found in a message box. This is exactly how he wants it done and i don't know
how to do it. any suggestions would be helpful. Thanks Judith Spurlock
 
G

Guest

Missingling,
what i meant to say was thank you very much for taking the time to help me
with the program and for explaining what feilds are so i could make the
program work. you've been very helpful and very patient with me as i'm new at
doing this and i don't understand a lot about it. I rate you as an excellent
source for answers to my questions. thanks for everything Judith Spurlock

missinglinq via AccessMonster.com said:
What did you mean to say, Judith?
This is the program and this is the way the instructor wants us to do i and i
don't know how to go about doing it. It states allow the user to enter
[quoted text clipped - 4 lines]
found in a message box. This is exactly how he wants it done and i don't know
how to do it. any suggestions would be helpful. Thanks Judith Spurlock
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top