folk754
04-13-2005, 11:00 AM
I am trying to run the following code, but i am getting an overflow error. Any hints?:banghead:
Private Sub createflat()
Dim i As Integer, j As Integer, s As Long
Dim dest As Range
Set dest = Sheet28.Range("A1")
For i = 1 To 212
For j = i To 212
s = posit(i, j)
dest.Offset(s, 0) = dist(i, j)
dest.Offset(s, 0).Select
Next j
Next i
End Sub
Function posit(i As Integer, j As Integer) As Double
Dim s As Double
If i > j Then
s = CLng(250 * j + j * (j + 1) / 2 + i)
Else
s = CDbl(i * 250) 'Here it is where it gives the error...
s = s + i * (i + 1) / 2
s = s + j
End If
posit = s
End Function
I tried using CDbl and CLng, but both returned overflow error. Any hints? (The dist function returns some x value, not important on this macro.):help
What I am trying to do is create a different way to store a symmetric matrix on a spreadsheet. Because there are only 256 columns, I would rather use a horizontal storage algorithm, which would allow me to store approx 362 on a single column. So the position (posit function) would tell me where to store element (i,j) of the matrix.
Private Sub createflat()
Dim i As Integer, j As Integer, s As Long
Dim dest As Range
Set dest = Sheet28.Range("A1")
For i = 1 To 212
For j = i To 212
s = posit(i, j)
dest.Offset(s, 0) = dist(i, j)
dest.Offset(s, 0).Select
Next j
Next i
End Sub
Function posit(i As Integer, j As Integer) As Double
Dim s As Double
If i > j Then
s = CLng(250 * j + j * (j + 1) / 2 + i)
Else
s = CDbl(i * 250) 'Here it is where it gives the error...
s = s + i * (i + 1) / 2
s = s + j
End If
posit = s
End Function
I tried using CDbl and CLng, but both returned overflow error. Any hints? (The dist function returns some x value, not important on this macro.):help
What I am trying to do is create a different way to store a symmetric matrix on a spreadsheet. Because there are only 256 columns, I would rather use a horizontal storage algorithm, which would allow me to store approx 362 on a single column. So the position (posit function) would tell me where to store element (i,j) of the matrix.