Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 25th, 2005, 05:12 AM
Authorized User
 
Join Date: Mar 2005
Location: , , Finland.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Suomi
Default Counting number of spaces in a line

I need to count number of spaces in a line. Can anybody help me in this regards.
Suomi

Reply With Quote
  #2 (permalink)  
Old August 25th, 2005, 09:20 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Dim intCount as Integer, strLine as String

strLine = "This is a test."

intCount = 0
For intCount = 1 to Len(strLine)
    If Mid(strLine, intCount, 1) = " " Then
        intCount = intCount + 1
    End If
Next intCount

If intCount = 1 Then
    MsgBox "There is " & intCount " space in the test string.", _
    vbInformation, "Space Count"
Else
    MsgBox "There are " & intCount " spaces in the test string.", _
    vbInformation, "Space Count"
End If
Reply With Quote
  #3 (permalink)  
Old August 25th, 2005, 09:28 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Oops... the For Loop should end with "Next intCount". My brain was on automatic pilot. I fixed the code.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #4 (permalink)  
Old September 9th, 2005, 02:34 PM
Authorized User
 
Join Date: Jul 2004
Location: clapton-in-gordano, n.somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Whilst I have no doubt that the code will work, isn't it simpler to use the Split method and just count the number of lines in the resulting array using Ubound?





Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
line number in xml using xsl and html link mrame XSLT 3 June 17th, 2008 01:36 PM
XSLT - xml difference with line number mrame XSLT 1 June 4th, 2008 05:49 PM
How to find line number FileFound Visual Studio 2005 2 June 15th, 2007 05:19 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 07:17 AM
Prime Number Counting. Help!! ajm235 C++ Programming 3 August 27th, 2004 12:00 PM



All times are GMT -4. The time now is 03:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.