OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 25-10-2004, 16:13
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Letter and Number Counter

I am trying to write a macro that will count every instance of every letter and number in a page or text file and then return the quantities as a new document or text file that I can print. (See sample jpg below).

For instance, I would want it to count every letter and number in the document and return values such as...

A=10
B=4
C=...
9=13

so on and so forth.

For asthetics, I would like to create a template document that I put the info into, but I already know how to do that.
Attached Images
 
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 25-10-2004, 18:21
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Letter and Number Counter

Here is some code for you:

Code:
Sub CountLetters()
    Dim LetterArray(33 To 255) As Long
    Dim n As Long
    Dim s As Shape
    Dim strText As String
    Dim c As Integer
    
    For n = 33 To 255
        LetterArray(n) = 0
    Next n
    
    For Each s In ActivePage.FindShapes(Type:=cdrTextShape)
        strText = s.Text.Frame.Range.Text
        For n = 1 To Len(strText)
            c = Asc(Mid$(strText, n, 1))
            If c > 32 And c < 256 Then
                LetterArray(c) = LetterArray(c) + 1
            End If
        Next n
    Next s
    
    strText = "Letter occurence statistics:" & vbCrLf
    For n = 33 To 255
        If LetterArray(n) > 0 Then
            strText = strText & Chr$(n) & " = " & LetterArray(n) & vbCrLf
        End If
    Next n
    
    With CreateDocument
        .ActiveLayer.CreateParagraphText 0, 0, .ActivePage.SizeWidth, .ActivePage.SizeHeight, strText
    End With
End Sub
It currently treats each letter sepratarely, including the case, so "a" and "A" will be counted as different letters, but this can be fixed too if needed...
Reply With Quote
  #3  
Old 26-10-2004, 07:46
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Thanks Alex. I got an IM from Shelby and what he told me is true... It is amazing that you can always find a solution with so little code.

Currently, most of my banners are all upper case letters, so I can just disregard the lowercase count. But just in case I might need the option in the future, how do I turn off lower case via code?
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #4  
Old 26-10-2004, 13:34
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

In the line where you determine the character code:

Code:
c = Asc(Mid$(strText, n, 1))
just add a call to UCase$ which will convert any lower case characters to uppercase:

Code:
c = Asc(UCase$(Mid$(strText, n, 1)))
Reply With Quote
  #5  
Old 27-10-2004, 11:04
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

O.K. Alex, now, how do I put each value in a specific place on the resulting page? For instance, formating the page so that I can make a 6x6 grid and place the values in each cell.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #6  
Old 05-11-2004, 14:27
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Any Ideas?
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 23:03.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com