Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2021, 01:53 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 07-13-2021, 03:36 AM
Guessed's Avatar
Guessed Guessed is offline gematria calculator Windows 10 gematria calculator Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 07-13-2021, 03:54 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 07-13-2021, 04:01 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

attached a file
Attached Files
File Type: docx EX.docx (11.8 KB, 14 views)
Reply With Quote
  #5  
Old 07-13-2021, 06:46 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 07-14-2021, 07:07 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 07-14-2021, 06:36 PM
Guessed's Avatar
Guessed Guessed is offline gematria calculator Windows 10 gematria calculator Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #8  
Old 07-14-2021, 11:41 PM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
File Type: docx 5 more letters.docx (11.9 KB, 6 views)
Reply With Quote
  #9  
Old 07-15-2021, 01:38 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
Reply With Quote
  #10  
Old 07-15-2021, 02:21 AM
Guessed's Avatar
Guessed Guessed is offline gematria calculator Windows 10 gematria calculator Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #11  
Old 07-15-2021, 05:10 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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.
Reply With Quote
  #12  
Old 07-15-2021, 06:10 AM
jpl jpl is offline gematria calculator Windows 7 64bit gematria calculator Office 2010 32bit
Advanced Beginner
 
Join Date: Jan 2016
Location: France
Posts: 33
jpl is on a distinguished road
Default

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 ?
Reply With Quote
  #13  
Old 07-15-2021, 06:45 AM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

Thank you for your help.
There are many types of gematria I use in the most basic.
Reply With Quote
  #14  
Old 07-15-2021, 03:56 PM
Guessed's Avatar
Guessed Guessed is offline gematria calculator Windows 10 gematria calculator Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #15  
Old 07-17-2021, 10:29 PM
yacov yacov is offline gematria calculator Windows 10 gematria calculator Office 2016
Competent Performer
gematria calculator
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Draft - Retirement Calculator DJ0691 Excel 0 01-16-2020 06:56 AM
gematria calculator Calculator in word Zhibek Word 2 08-17-2018 12:07 AM
gematria calculator Result Calculator Raza Excel Programming 7 01-26-2015 11:35 PM
Excel Calculator Mandusin Excel 6 12-25-2010 07:34 AM
Age Calculator in MS Outlook 2002 SP3 turns Outlook 0 06-15-2010 12:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft