DIM JD, j, m, d AS LONG
is not the same as
DIM JD AS LONG, j AS LONG, m AS LONG, d AS LONG
Could that be it? Same for:
DIM y4, y1p, gam1, ksi1, mi1, ksi2, mi2, c41p, q, r, dz1, gam2, ksi3, c42p, c43p, dz2, gam3, mi3, z4, c, x3, x1 AS LONG
With that line, only x1 is a LONG. The rest are SINGLE.