I am writting a encoder in VBA excel. I keep getting a runtime error 13. It says there is a mismatch

StackOverflow https://stackoverflow.com/questions/22457906

Domanda

Sub Encoder()


Dim word As String
Dim en_word As Variant
Dim i As Integer
Dim wordSec As Variant
Dim d As Variant
Dim x As Variant
Dim y As Variant
Dim T_len As Variant

word = InputBox("Please enter a word")

     Sheet1.Cells(127, 6) = word



For i = 1 To Len(word) Step 3

This splits the word in threes till the end of the word

 T_len = i

This scrabbles the characters of every word section

 Mid(word, 1, T_len) = wordSec

    x = Mid(wordSec, 1, 1)

    y = Mid(wordSec, 2, 1)

    d = Mid(wordSec, 3, 1)
   wordSec = d + x + y

This changes e to u and u to e

  If d = "e" Then
  d = "u"




  ElseIf y = "e" Then
  y = "u"




 ElseIf x = "e" Then
  x = "u"

  Else
  x = x
    y = y
        d = d
End If

If d = "u" Then
d = "e"

ElseIf x = "u" Then
x = "e"

ElseIf y = "u" Then
y = "e"
Else
 x = x
 y = y
 d = d
 End If

This changes i to o and o to i

 If d = "i" Then
 d = "o"

 ElseIf x = "i" Then
 x = "o"
 ElseIf y = "i" Then
 y = "o"

 Else
 x = x
 y = y
 d = d
 End If

If d = "o" Then
 d = "i"

 ElseIf x = "o" Then
 x = "i"
 ElseIf y = "o" Then
 y = "i"

 Else
 x = x
 y = y
 d = d
 End If

This is adding 1 to a word section that has a vowel

This is were the mismatch happens

 If d And x And y = "a" And "i" And "o" And "u" And "e" Then 




    wordSec = wordSec + 1

    Else

    wordSec = wordSec

    End If
 en_word = wordSec + wordSec
 Next i

 Sheet1.Cells(127, 14).Value = en_word

End Sub

Computer should translate to mci1tpe1ur1

È stato utile?

Soluzione

This is not a logical statement

If d And x And y = "a" And "i" And "o" And "u" And "e" Then 

This are the expressions you are trying to evaluate

d
x
y= "a"
"i"
"o"
"u"
"e"

y="a" is a logical expression. Variables d and x Could maybe be boolean values but strings are definitely not. You need to think about what you are trying to say here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top