Microsoft Office Forums gematria calculator
 Register FAQ Search Today's Posts Mark Forums Read

#1
07-13-2021, 01:53 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122
gematria calculator

HI'

I have been using Word for over two years, and I would like to try to write a macro to calculate gematria within Word.
That is, to give a numerical value to each letter and allow Word to solve equations of subtraction. Is it possible? Can anyone give me guidance on how to get started?

For example:
A-F=5 (A=1. F=6)

thanks'
Yacov.
#2
07-13-2021, 03:36 AM
 Guessed Windows 10 Office 2016 Expert Join Date: Mar 2010 Location: Canberra/Melbourne Australia Posts: 3,614

Post a document showing the formulas you want to calculate. and describe how you envision the user preparing the file to run the macro.

And does the answer need to be correct - your example is wrong
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
#3
07-13-2021, 03:54 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

hi andrew,
I am writing a book on gematria and I have thousands of such equations (from the Bible) that I would like to check that I was not wrong. For example:

לירת במסתרים תם פתאם ירהו ולא ייראו-וירם אלהים חץ פתאום היו מכותם=1344

א=1 ב=2 ג=3 ד=4 ה=5 ו=6 ז=7 ח=8 ט=9 י=10 כ=20 ל=30 מ=40 נ=50 ס=60 ע=70 פ=80 צ=90 ק=100 ר=200 ש=300 ת=400
#4
07-13-2021, 04:01 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

attached a file
Attached Files
 EX.docx (11.8 KB, 14 views)
#5
07-13-2021, 06:46 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

the envision:
1. the user Select the text.
2. Click on the shortcut that activates the macro.
3. The software will recognize the minus sign (or a nonbreaking hyphen) and the result will appear somewhere screen.

thanks,
Yacov
#6
07-14-2021, 07:07 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

toolscalculator can be starting point,

Sub wcal()
If Selection.Name = "א" Then _
Selection.Name = "1"
If Selection.Name = "ב" Then _
Selection.Name = "2"
MsgBox "And the answer is... " & Selection.Calculate
End Sub
#7
07-14-2021, 06:36 PM
 Guessed Windows 10 Office 2016 Expert Join Date: Mar 2010 Location: Canberra/Melbourne Australia Posts: 3,614

I don't know how to correctly handle the minus sign (is b-a the same as a-b in hebrew LTR and english RTL) or the spaces but this should be enough to get you started
Code:
```Sub MyCalculator()
Dim aChar As Variant, aRng As Range, iTotal As Long
Set aRng = Selection.Range
For Each aChar In aRng.Characters
Select Case AscW(aChar)
Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
Case 1499: iTotal = iTotal + 20
Case 1500: iTotal = iTotal + 30
Case 1502: iTotal = iTotal + 40
Case 1504: iTotal = iTotal + 50
Case 1505: iTotal = iTotal + 60
Case 1506: iTotal = iTotal + 70
Case 1508: iTotal = iTotal + 80
Case 1510: iTotal = iTotal + 90
Case 1511: iTotal = iTotal + 100
Case 1512: iTotal = iTotal + 200
Case 1513: iTotal = iTotal + 300
Case 1514: iTotal = iTotal + 400
Case 45: iTotal = iTotal * -1     'a minus sign
End Select
Next aChar
MsgBox iTotal
End Sub```
I needed to convert the characters to their AscW ids to do this. This is the code I used to build that list when I selected your legend code.
Code:
```Sub GetAscWFromLegend()
Dim arr() As String, i As Integer, aRng As Range
Set aRng = Selection.Range
arr = Split(aRng.Text, " ")
For i = LBound(arr) To UBound(arr)
Debug.Print AscW(arr(i)), Mid(arr(i), 3)
Next i
End Sub```
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
#8
07-14-2021, 11:41 PM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

Thank you so much Andrew. Great help.
I forgot 5 letters that come at the end of a word. I will try to add them.
ך=20
ם=40
ן=50
ף=80
ץ=90
Attached Files
 5 more letters.docx (11.9 KB, 6 views)
#9
07-15-2021, 01:38 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

here is the final:
Sub MyCalculator()
Dim aChar As Variant, aRng As Range, iTotal As Long
Set aRng = Selection.Range
For Each aChar In aRng.Characters
Select Case AscW(aChar)
Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
Case 1498: iTotal = iTotal + 20
Case 1499: iTotal = iTotal + 20
Case 1500: iTotal = iTotal + 30
Case 1501: iTotal = iTotal + 40
Case 1502: iTotal = iTotal + 40
Case 1503: iTotal = iTotal + 50
Case 1504: iTotal = iTotal + 50
Case 1505: iTotal = iTotal + 60
Case 1506: iTotal = iTotal + 70
Case 1507: iTotal = iTotal + 80
Case 1508: iTotal = iTotal + 80
Case 1509: iTotal = iTotal + 90
Case 1510: iTotal = iTotal + 90
Case 1511: iTotal = iTotal + 100
Case 1512: iTotal = iTotal + 200
Case 1513: iTotal = iTotal + 300
Case 1514: iTotal = iTotal + 400
Case 45: iTotal = iTotal * -1 'a minus sign
End Select
Next aChar
MsgBox iTotal
End Sub
#10
07-15-2021, 02:21 AM
 Guessed Windows 10 Office 2016 Expert Join Date: Mar 2010 Location: Canberra/Melbourne Australia Posts: 3,614

You can tidy it a tiny amount by combining some of the lines with the same output
For example, these two lines
Case 1498: iTotal = iTotal + 20
Case 1499: iTotal = iTotal + 20

can be written on one line as
Case 1498, 1499: iTotal = iTotal + 20

I don't think it would make any difference to the speed of the macro either way.

The maths is NOT likely to be right when there is a minus sign. It would certainly be wrong if there are two of them (eg a - b - c) since all I was doing was flipping the sign of the running total when the macro hits it. Unfortunately I don't know anything about right to left language equations so that is something you will need to solve if it bothers you.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
#11
07-15-2021, 05:10 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

The minus sign does not matter, since I am looking for the difference between the two sentences.
The macro works great. I use a lot of times non breaking hyphen instead of minus. can the Macro identify it as a minus sign and perform the calculation? I searched the internet for this marking in ASCII and did not find it.
In any case it is not a big problem to me put everything back into minus.
#12
07-15-2021, 06:10 AM
 jpl Windows 7 64bit Office 2010 32bit Advanced Beginner Join Date: Jan 2016 Location: France Posts: 33

Le trait d'union insécable (non breaking hyphen) a pour code Unicode le nombre hexadécimal 2011, soit 8209 en écriture décimale.
Pour en tenir compte, vous pouvez remplacer la ligne
Case 45: iTotal = iTotal * -1 'a minus sign
par
Case 45, 8209: iTotal = iTotal * -1 'a minus sign
dans la macro de Guessed. Cela devrait fonctionner.
Une question.
Les valeurs que vous donnez pour les cinq caractères que vous aviez omis ne sont pas les valeurs indiquées dans la page wikipedia Gematria — Wikipedia.
Wikipedia donne les valeurs 500, 600, 700, 800 et 900 (dans Gematria classique).
Cela a-t-il des conséquences pour l'interprétation des textes bibliques ?
#13
07-15-2021, 06:45 AM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

There are many types of gematria I use in the most basic.
#14
07-15-2021, 03:56 PM
 Guessed Windows 10 Office 2016 Expert Join Date: Mar 2010 Location: Canberra/Melbourne Australia Posts: 3,614

You can get the AscW value of a character by selecting it in the document and typing the following line into the Immediate Window of the VBA Editor and pressing Enter
? AscW(Selection.Text)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
#15
07-17-2021, 10:29 PM
 yacov Windows 10 Office 2016 Competent Performer Join Date: Oct 2019 Posts: 122

Thanks for the update. I added to the macro an automatic selection of the paragraph. I would like to check if it is possible for the macro to do a calculation on the whole document. For this I need the result of the calculation to be recorded in the document in each paragraph. Is it possible?

Sub MyCalculatorSelect()
Selection.Paragraphs(1).Range.Select
Dim aChar As Variant, aRng As Range, iTotal As Long
Set aRng = Selection.Range
For Each aChar In aRng.Characters
Select Case AscW(aChar)
Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
Case 1498: iTotal = iTotal + 20
Case 1499: iTotal = iTotal + 20
Case 1500: iTotal = iTotal + 30
Case 1501: iTotal = iTotal + 40
Case 1502: iTotal = iTotal + 40
Case 1503: iTotal = iTotal + 50
Case 1504: iTotal = iTotal + 50
Case 1505: iTotal = iTotal + 60
Case 1506: iTotal = iTotal + 70
Case 1507: iTotal = iTotal + 80
Case 1508: iTotal = iTotal + 80
Case 1509: iTotal = iTotal + 90
Case 1510: iTotal = iTotal + 90
Case 1511: iTotal = iTotal + 100
Case 1512: iTotal = iTotal + 200
Case 1513: iTotal = iTotal + 300
Case 1514: iTotal = iTotal + 400
Case 45: iTotal = iTotal * -1 'a minus sign
End Select
Next aChar
MsgBox iTotal
End Sub

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post DJ0691 Excel 0 01-16-2020 06:56 AM Zhibek Word 2 08-17-2018 12:07 AM Raza Excel Programming 7 01-26-2015 11:35 PM Mandusin Excel 6 12-25-2010 07:34 AM turns Outlook 0 06-15-2010 12:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:09 PM.

 -- Default Style -- Lightweight -- New Mobile Contact Us - Privacy Statement - Top