Searching for 8 characters words

S

Sasa

How should I set macro to look only for words which have
length 8 characters?

Thank you for your help.
Regards.

Sasa
 
H

Helmut Weber

E.g.
Dim oW As Object
For Each oW In ActiveDocument.Words
If Len(Trim(oW)) = 8 Then
MsgBox oW
End If
Next
Helmut Weber
 
H

Helmut Weber

Hi,
did you get along with binary to decimal conversion?
From your other questions I assume, there might
be a bit of explanation recommended.
Helmut Weber
 
H

Helmut Weber

Hi Sasa,
in case of a 2 column table with strings representing
binary numbers in column 1 and no split or merged cells:
Dim oT As Table ' Table Object
Dim lR As Long ' number of rows
Dim s1 As String ' string from column 1
Dim s2 As String ' string from column 2
Set oT = ActiveDocument.Tables(1)
For lR = 1 To oT.Rows.Count
s1 = oT.Cell(lR, 1).Range.Text
s2 = Bin2Dec(s1)
oT.Cell(lR, 2).Range.Text = s2
Next
Still shorter coding is possible,
but would result in longer code lines,
which I don't like at all.
The function Bin2Dec() removes anything that
isn't a numeral from its input by "isnumeric".
I had assumed from your example that the input-string
was exactly 15 characters long and contained exactly
8 numerals, only "0" or "1".
For i = 1 To 15 ' ! some danger here
If IsNumeric(Mid(Binar, i, 1)) Then
D = D + Mid(Binar, i, 1)
End If
Next
If there are exactly 8 numerals "0" or "1"
the following does the conversion. Example "11110000"
For i = 1 To 8
n = n + CInt(Mid(D, i, 1)) * 2 ^ (8 - i)
Next
n = n + 1 * 2^7 ' 128
n = n + 1 * 2^6 ' 64
n = n + 1 * 2^5 ' 32
n = n + 1 * 2^4 ' 16
n = n + 0 * 2^3 ' 0 ' 0 for the remaining 3 as well.
.... ' > Sum = 240
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 

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