|
-
Jun 19th, 2001, 06:07 PM
#1
Thread Starter
Addicted Member
Giving away code.....a drawback
Just an observation that I have seen over and over again.
Many advanced people on this forum will readily post complex code for people that can't even figure out the InStr function.
In some cases I think that is fine, but I also know, from experience, that if you are given the code to solve a difficult problem, and it works, you will probably not take the time to figure out why it works, or how it works, thereby not learning anything.
The code below is an example from my past, I had no clue what it did then, and I still don't, because it worked from day one and has never had a bug (except for commenting out the first If).
This code is very poorly written, so perhaps it's a bad example, but it is a good example of the point I am making.
Code:
Private Function RSEncode(NumRSSyms As Integer, TmpArray() As String, ParitySyms() As String) As Integer
'------------------------------------------------------------------
' This function accepts as inputs the number of input symbols, an
' array where the input symbols are stored and an output array
' where the resulting output symbols are stored.
'------------------------------------------------------------------
'Code supplied by AustraliaPost web site
'SSS 02/99 AU Mail update
Dim N As Integer
Dim i As Integer
Dim j As Integer
ReDim mult(0 To 63, 0 To 63) As Integer 'used for Reed Solomon error correction
ReDim gen(0 To 4) As Integer ' " " " " " "
ReDim temp(31) As Integer
'Static RSInited As Integer
ReDim ParitySyms(0 To 3) As String
'If Not RSInited Then
'RSInit needs to be called once at the start
'Code supplied by AustraliaPost web site
'I don't claim to understand it-SSS
Dim primpoly As Integer
Dim testv As Integer
Dim prevv As Integer
Dim nextv As Integer
'Dim i As Integer
'Dim j As Integer
primpoly = 67 ' a**6 + a + 1 where a (alpha) is 2
testv = 64
For i = 0 To 63
mult(0, i) = 0
mult(1, i) = i
Next i
prevv = 1
For i = 1 To 63
nextv = prevv * 2
If (nextv >= testv) Then
nextv = nextv Xor primpoly
End If
For j = 0 To 63
mult(nextv, j) = mult(prevv, j) * 2
If mult(nextv, j) >= testv Then
mult(nextv, j) = mult(nextv, j) Xor primpoly
End If
Next j
prevv = nextv
Next i
gen(0) = 48
gen(1) = 17
gen(2) = 29
gen(3) = 30
gen(4) = 1
'RSInited = True
'End If
On Error GoTo OOOps
N = NumRSSyms + 4
For i = 0 To 3
temp(i) = 0
Next i
For i = 4 To N - 1
temp(i) = Val(TmpArray(N - 1 - i)) 'Fill in reversed order
Next i
For i = NumRSSyms - 1 To 0 Step -1
For j = 0 To 4
temp(i + j) = temp(i + j) Xor mult(gen(j), temp(i + 4))
Next j
Next i
For i = 0 To 3 ' Fill in the resulting output array
ParitySyms(i) = Str(temp(i))
Next i
RSEncode = 0
On Error GoTo 0
Exit Function
OOOps:
RSEncode = 1
Exit Function
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|