Runtime Error 6 - How to make Mod process double?

In vba, a runtime error always occurs:

Sub rsa() Dim c1 As Long Dim c2 As Long Dim z As Long Dim e As Long pt = "xa" n = 187 e = 7 For i = 1 To Len(pt) b = Mid$(pt, i, 1) If b <> " " Then z = Asc(UCase(b)) 'Here is the problem: c = z ^ e Mod n Text = Text & c Else Text = Text & " " End If Next i Cells(20, 4).Value = Text End Sub 

I get a runtime error in c = z ^ e Mod n .

I tried different data types, but without a solution.

+6
vba excel-vba excel
source share
2 answers

A Mod B is equal to A - Int(A / B) * B , so you can try instead of c = z ^ e - Int(z ^ e / n) * n c = z ^ e Mod n . It works for me

+10
source share

Runtime Error 6 - operation with numerical overflow. One of your variables is not defined large enough or without sufficient accuracy. You need to show more examples, etc., so that people can give you a better idea. The first thing I would like to do is print ALL the numbers before you complete the formula.

Use the Double data type and when converting to Double use CDbl ()

+2
source share

All Articles