#1




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: AF=5 (A=1. F=6) thanks' Yacov. 
#2




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




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




attached a file

#5




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




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




I don't know how to correctly handle the minus sign (is ba the same as ab 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 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




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 
#9




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




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




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




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 atil des conséquences pour l'interprétation des textes bibliques ? 
#13




Thank you for your help.
There are many types of gematria I use in the most basic. 
#14




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




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  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Draft  Retirement Calculator  DJ0691  Excel  0  01162020 06:56 AM 
Calculator in word  Zhibek  Word  2  08172018 12:07 AM 
Result Calculator  Raza  Excel Programming  7  01262015 11:35 PM 
Excel Calculator  Mandusin  Excel  6  12252010 07:34 AM 
Age Calculator in MS Outlook 2002 SP3  turns  Outlook  0  06152010 12:26 AM 