Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Build a tag list of a database column

Reply
 
Old 12-17-2008   #1 (permalink)
HAL07


 
 

Build a tag list of a database column

Hello, I have a column called newstext in an access database.

I would like to build a Tag list that consist of most words in a textfile. I would like to count how many times they occur, and
maybe how many times they occur in relations to another tag.

Do anybody have any tips for how to proceed on this one?

--
-- HAL07, Engineering Services, Norway

My System SpecsSystem Spec
Old 12-17-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Build a tag list of a database column

HAL07 wrote:
Quote:

> Hello, I have a column called newstext in an access database.
>
> I would like to build a Tag list that consist of most words in a textfile.
> I would like to count how many times they occur, and maybe how many times
> they occur in relations to another tag.
>
> Do anybody have any tips for how to proceed on this one?
In VBScript I would use a dictionary object. The Exists method ensures
uniqueness. The key value would be the case insensitive word, the item value
would be the number of occurrences. Perhaps something similar to:
===========
Set objWordList = CreateObject("Scripting.Dictionary")
objWordList.CompareMode = vbTextCompare

strText = "This is a test consisting of a few lines" _
& vbCrLf & "of words. Words are delimited by spaces," _
& vbCrLf & "punctuation, and carriage returns. There are" _
& vbCrLf & "many possible punctuation marks, so it is" _
& vbCrLf & "important to account for all possibilities." _
& vbCrLf & "The expected result is a count of how many times" _
& vbCrLf & "Each word occurs in the text."

' Create array of lines delimited by carriage returns.
arrLines = Split(strText, vbCrLf)
' Enumerate lines.
For Each strLine In arrLines
' Remove punctuation.
strLine = Replace(strLine, ".", "")
strLine = Replace(strLine, ",", "")
strLine = Replace(strLine, ";", "")
strLine = Replace(strLine, ":", "")
strLine = Replace(strLine, "?", "")
strLine = Replace(strLine, "-", "")
strLine = Replace(strLine, "!", "")
' Create array of words delimited by spaces.
arrWords = Split(strLine, " ")
' Enumerate words in the line.
For Each strWord In arrWords
' Check if the word has been encountered before.
If (objWordList.Exists(strWord) = True) Then
' Increment count for this word by one.
objWordList(strWord) = objWordList(strWord) + 1
Else
' Add this word to the dictionary object with a count of one.
objWordList(strWord) = 1
End If
Next
Next

' Enumerate all words and their counts in parentheses.
For Each strWord In objWordList.Keys
Wscript.Echo strWord & " (" & objWordList(strWord) & ")"
Next
========
You might want to make all words lower case. Then you could add:

strLine = LCase(strLine)

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 12-18-2008   #3 (permalink)
HAL07


 
 

Re: Build a tag list of a database column

Richard Mueller [MVP] wrote:
Quote:

> HAL07 wrote:
>
Quote:

>> Hello, I have a column called newstext in an access database.
>>
>> I would like to build a Tag list that consist of most words in a textfile.
>> I would like to count how many times they occur, and maybe how many times
>> they occur in relations to another tag.
>>
>> Do anybody have any tips for how to proceed on this one?
>
> In VBScript I would use a dictionary object. The Exists method ensures
> uniqueness. The key value would be the case insensitive word, the item value
> would be the number of occurrences. Perhaps something similar to:
> ===========
> Set objWordList = CreateObject("Scripting.Dictionary")
> objWordList.CompareMode = vbTextCompare
>
> strText = "This is a test consisting of a few lines" _
> & vbCrLf & "of words. Words are delimited by spaces," _
> & vbCrLf & "punctuation, and carriage returns. There are" _
> & vbCrLf & "many possible punctuation marks, so it is" _
> & vbCrLf & "important to account for all possibilities." _
> & vbCrLf & "The expected result is a count of how many times" _
> & vbCrLf & "Each word occurs in the text."
>
> ' Create array of lines delimited by carriage returns.
> arrLines = Split(strText, vbCrLf)
> ' Enumerate lines.
> For Each strLine In arrLines
> ' Remove punctuation.
> strLine = Replace(strLine, ".", "")
> strLine = Replace(strLine, ",", "")
> strLine = Replace(strLine, ";", "")
> strLine = Replace(strLine, ":", "")
> strLine = Replace(strLine, "?", "")
> strLine = Replace(strLine, "-", "")
> strLine = Replace(strLine, "!", "")
> ' Create array of words delimited by spaces.
> arrWords = Split(strLine, " ")
> ' Enumerate words in the line.
> For Each strWord In arrWords
> ' Check if the word has been encountered before.
> If (objWordList.Exists(strWord) = True) Then
> ' Increment count for this word by one.
> objWordList(strWord) = objWordList(strWord) + 1
> Else
> ' Add this word to the dictionary object with a count of one.
> objWordList(strWord) = 1
> End If
> Next
> Next
>
> ' Enumerate all words and their counts in parentheses.
> For Each strWord In objWordList.Keys
> Wscript.Echo strWord & " (" & objWordList(strWord) & ")"
> Next
> ========
> You might want to make all words lower case. Then you could add:
>
> strLine = LCase(strLine)
>
thank you very much. i will look into it.


--
-- HAL07, Engineering Services, Norway
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Wrong Addresses in "To" Column of List Pane Live Mail
Is it possible in "computer" to view files from top to bottom in 1st column then same again in next column to the right etc? Vista file management
Works database 2007 and Office database 2003 .NET General
Vista Build 5744 doesn't want to upgrade build 5536 Vista installation & setup
Vista public build 5384, nerds build 5472 Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46