VB Code:
Private Sub Command1_Click()
Dim strKeys As String, strFolding As String, strNumbers() As String
Dim lngAnswer As Long, lngA As Long
' store key values
strKeys = txtKeyValues.Text
' there must be ten values
If Len(strKeys) <> 10 Then MsgBox "Incorrect length for key values.": Exit Sub
' get the folding process
strFolding = txtFoldingProcess.Text
' remove spaces
strFolding = Replace(strFolding, " ", vbNullString)
' select each key value, replace the text with the key value
strFolding = Replace(strFolding, "1st", Left$(strKeys, 1))
strFolding = Replace(strFolding, "2nd", Mid$(strKeys, 2, 1))
strFolding = Replace(strFolding, "3rd", Mid$(strKeys, 3, 1))
strFolding = Replace(strFolding, "4th", Mid$(strKeys, 4, 1))
strFolding = Replace(strFolding, "5th", Mid$(strKeys, 5, 1))
strFolding = Replace(strFolding, "6th", Mid$(strKeys, 6, 1))
strFolding = Replace(strFolding, "7th", Mid$(strKeys, 7, 1))
strFolding = Replace(strFolding, "8th", Mid$(strKeys, 8, 1))
strFolding = Replace(strFolding, "9th", Mid$(strKeys, 9, 1))
strFolding = Replace(strFolding, "10th", Right$(strKeys, 1))
' now split by summing
strNumbers = Split(strFolding, "+")
' add up the values together
For lngA = 0 To UBound(strNumbers)
' add up the values together into the final answer
lngAnswer = lngAnswer + CLng(Val(strNumbers(lngA)))
Next lngA
' show the answer
MsgBox "The answer is " & CStr(lngAnswer)
End Sub