Anyone feel like a Gematria numeric challenge in EXCEL VBA? - vba

To explain: I’m in EXCEL and need a genius formula in VBA, where each letter in the alphabet (except j) is given a SPECIFIC numeric value (as listed below), so that as you type LETTERS in one cell, the SUM OF THE NUMERIC VALUES appear in the cell next to it.
a=1 b=2 c=600 d=4 e=5 f=500 g=3 h=8 i=10
k=20 l=30 m=40 n=50 o=70 p=80 q=9 r=100 s=200
t=300 u=400 v=200 w=800 x=60 y=700 z=7
(Note: It should also apply to CAPS and a space should count zero)
e.g: If I type the words lady asks help in cell A1, the value 1279 should appear in cell B1
(Seeing that l=30, a=1, d=4, y=700, a=1, s=200, k=20, s=200, h=8, e=5, l=30, p=80)
The same formula should apply to the rest of Columns A and B.
In case it’s important, I need it for Greek Gematria. As I type “abc” on the keyboard, the Greek letters “αβχ” appear on the screen (by use of the Tyndale House keyboard code). Each Greek letter has a set numeric value, confirming numeric patterns found in Greek Bible Texts.
I’ve found fixed programs using Greek Gematria (e.g. DAVAR4), but none are editable text and I don’t know how to get into their ‘brains’ to transfer it to EXCEL. Frankly, I’m really clueless when it comes to programming and don’t even know if what I’m asking is possible. Local programmers referred me to Stack Overflow, so ANY help or directive would be much appreciated!
I looked at this question & answer, asked Jul 7 '14 by data_garden, but alas, I’m a dummy!
Please say if any more info is needed. Thanks

You're in luck. There are votes for this to be closed as you've made no apparent effort to write the code yourself. I've written something similar myself recently so all that was needed was to replace the array with your scoring system and it is below:
Function gem(txt As String) As Long
gem = 0
Dim i As Long, c As Integer
Dim arr()
arr = Array(0, 1, 2, 600, 4, 5, 500, 3, 8, 10, 0, 20, 30, 40, 50, 70, 80, 9, 100, 200, 300, 400, 200, 800, 60, 700, 7)
For i = 1 To Len(txt)
c = Asc(Mid(UCase(txt), i, 1)) - 64
If c > 0 And c <= 26 Then gem = gem + arr(c)
Next
End Function

Related

How do i convert an integer to an index in an "if" function?

My first question on this forum and im completely new to programming, so apologies if i do something wrong.
So im trying to program something to do a collatz sequense on a number i put in. To do that i have to check if the number i put in is even or odd. The easy fix would be to use the built in % 2 function but i want to do it "dirty" to learn better.
So my plan was to check if the last number in said input number is in the list (0, 2, 4, 6, 8) since an even number ends on those and is odd otherwise. Problem is how to check the very last index in the number to see if its in that list. I tried the following code
def Collatz(input_number):
input_number_num = int(input_number)
lenght = len(input_number_num)
position = lenght - 1
if [position] in input_number_num is in (0, 2, 4, 6, 8)
return (input_number_num / 2)
else:
return (input_number_num * 3 + 1)
This gives me a syntax error, im guessing since it reads [lenght] as an tuple rather than the index.
You could convert the number to a string and then use the -1 index to extract the last character:
if input_number[-1] in ('0', '2', '4', '6', '8'):
But to be completely honest, I can't see any advantage of doing this over just using % 2.

I need to create a finite automata

Consider the language L of all strings made of the symbols 0, 1 and 2 (Σ = {0, 1, 2}) where the last symbol is not smaller than the first symbol. E.g., the strings 0, 2012, 01231 and 102 are in the language, but 10, 2021 and 201 are not in the language.
As 0 is in the language and I don't understand why, I can't figure out if strings 1 and 2 are in the language?
So could someone please tell me if 1 and 2 as a string themselves are in the language and why?
Thank you
'0' is in the language because the first symbol and last symbol in '0' are both '0'. This satisfies the requirements that the last is not smaller than the first.
This means that the same applies for '1', '2', and for the empty string ''.

Changing the order of columns in a CSV file in VB.NET

I have a CSV files output from a software without headers,
I need to change the order of columns based on a config file
initial-column Final-Column
1 5
2 3
3 1
Any ideas how to go about this?
There is very very little to go on, such as how the config file works and what the data looks like.
Note that using the layout of {1, 5, 2, 3, 3, 1} you arent just reordering the columns, that drops one (4) and duplicates columns 1 and 3.
Using some fake random data left over from this answer, this reads it in, then writes it back out in a a different order. You will have to modify it to take the config file into consideration.
Sample data:
Ndxn fegy n, 105, Imaypfrtzghkh, -1, red, 1501
Mfyze, 1301, Kob dlfqcqtkoccxwbd, 0, blue, 704
Xe fnzeifvpha, 328, Mnarhrlselxhcyby hq, -1, red, 1903
Dim csvFile As String = "C:\Temp\mysqlbatch.csv"
Dim lines = File.ReadAllLines(csvFile)
Dim outFile As String = "C:\Temp\mysqlbatch2.csv"
Dim data As String()
Dim format As String = "{0}, {4}, {1}, {2}, {2}, {0}"
Using fs As New StreamWriter(outFile, False)
For Each s As String In lines
' not the best way to split a CSV,
' no OP data to know if it will work
data = s.Split(","c)
' specifiy the columns to write in
' the order desired
fs.WriteLine(String.Format(format,
data(0),
data(1),
data(2),
data(3),
data(4),
data(5)
)
)
Next
End Using
This approach uses the format string and placeholder ({N}) to control the order. The placeholders and array elements are all zero based, so {1, 5, 2, 3, 3, 1} becomes {0, 4, 1, 2, 2, 0}. Your config file contents could simply be a collection of these format strings. Note that you can have more args to String.Format() than there are placeholders but not fewer.
Output:
Ndxn fegy n, red, 105, Imaypfrtzghkh, Imaypfrtzghkh, Ndxn fegy n
Mfyze, blue, 1301, Kob dlfqcqtkoccxwbd, Kob dlfqcqtkoccxwbd, Mfyze
Xe fnzeifvpha, red, 328, Mnarhrlselxhcyby hq, Mnarhrlselxhcyby hq, Xe fnzeifvpha
Splitting the incoming data on the comma (s.Split(","c)) will work in many cases, but not all. If the data contains commas (as in some currencies "1,23") it will fail. In this case the seperator char is usually ";" instead, but the data can have commons for other reasons ("Jan 22, 2016" or "garden hose, green"). The data may have to be split differently.
Note: All the OPs previous posts are vba related. The title includes VB.NET and is tagged vb.net, so this is a VB.NET answer

Fortran runtime error while reading a file: "Bad repeat count"

I'm trying to read an input file with fortran but I get the following error at runtime:
At line 118 of file prog.f90 (unit = 53, file = 'data.dat')
Fortran runtime error: Bad repeat count in item 1 of list input
The data file is the following
3, 5, 3 %comment
%%%%%%%%%%%%%%
1d0, 0d0, 0d0 % comment
0d0, 0d0, 1d0
%%%%%%%%%%%%%%
1, 1, identity, 1, 1 %comment
1, 2, sigmax, 2, 2
2, 3, sigmax, 2, 2
1, 3, sigmaz, 1, 3
3, 3, identity, 1, 1
%%%%%%%%%%%%%%
0, 0 %comment
and the interesting part of prog.f90 is
COMPLEX(KIND(1D0)), DIMENSION(:), ALLOCATABLE:: H1, H2
INTEGER :: i,A,B,C
CHARACTER(50) :: GHOST
OPEN(UNIT=53,file='data.dat',status='old')
READ(53,*) A,B,C
READ(53,*) GHOST
ALLOCATE (H1(A),H2(A))
READ(53,*) (H1(i), i=1,A)
READ(53,*) (H2(i), i=1,A)
where the 118th line is READ(53,*) (H1(i), i=1,A). I tryed also with an explicit do loop but with the same result.
I haven't tested this, but I'd expect
READ(53,*) (H1(i), i=1,A)
to try to read 3 complex numbers. It gets fed the line
1d0, 0d0, 0d0 % comment
from which it gets 1½ complex numbers and then barfs on the % sign, misinterpreting it as a syntactically invalid repeat count.
I'd suggest providing 3 complex numbers in the file when that read statement is executed.
The numbers are dimensioned complex, while in fortran complex numbers should be in the file with parenthesis as:
( realpart , imaginarypart ) ( realpart , imaginarypart )
I really don't know what the standards say regarding the input form you have presented, but after some testing gfortran throws that Bad repeat count error regardless of the % comment. It throws that error even with four or more comma separated reals on the line.
Now ifort on the other hand reads the line just the way you have it -- but watch out -- it reads each of the comma separated values as the real part of your complex variable, setting the imaginary part to zero. ( that is it only uses the first two values on each line and discards the third )
You will really need to study the code to make sure you understand what was intended to sort out how to fix this. If the later (ifort) behavior is the intention one simple fix would be to declare a couple of reals. Read into the reals, then assign those to your complex variables.

rdlc (piechart) customized colors for different segments

I have written a code like below, my problem was sometimes I am getting same color for different segments in the piechart if the value came from the same range.
ref:
rdlc expression iif use?
my code sample
=SWITCH(Fields!ID__Share_of_Costs.Value <= 0.99, "Yellow",
Fields!ID__Share_of_Costs.Value <= 30, "Teal",
Fields!ID__Share_of_Costs.Value <= 60, "SteelBlue",
Fields!ID__Share_of_Costs.Value <= 100, "Crimson",
)
for eg: suppose my chart value is dynamic and it will come like 22 and 29, in this case the segment will show the same color (<= 30, "Teal",) as it is difficult to differntiate. Is there is any way to give different colors for each segment like no repeated color ?
Thanks in advance...cheers
It depends what do you mean by segment (range of values or particular value) or in other words is number of your segments limited?
If yes, then you could set up as much segments as you want with particular color.
If no, then write a custom function which will return hex value as your color.