Hi,
I can't see how you've got it working if you don't load the array with the ASCII values of the numbers you later want in the variable. Here's a piece of testcode I just wrote:Let's examine the output of each of the tests:Code:BufferLength CON 16 Array VAR BYTE[BufferLength] Variable1 VAR WORD Variable2 VAR WORD i VAR WORD Test VAR BYTE Pause 2500 HSEROUT["Start...",13,13] Start: CLEAR Test = 1 ArrayRead Array,[DEC Variable1] ArrayRead Array,[Variable2] GOSUB PrintIt '---------------------------------------------------------------------------------------------- CLEAR ' Make sure we clear the array (and every other variable) Test = 2 Array[0] = 1 ' Populate array with binary value Array[1] = 2 Array[2] = 3 ArrayRead Array,[DEC Variable1] ' Try to read the array into variable using DEC modifier ArrayRead Array,[Variable2] GOSUB PrintIt ' Display results '---------------------------------------------------------------------------------------------- CLEAR ' Make sure we clear the array (and every other variable) Test = 3 Array[0] = "1" ' Populate array with ASCII representation of out value...49 Array[1] = "2" ' 50 Array[2] = "3" ' 51 ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt ' Display results '---------------------------------------------------------------------------------------------- Test = 4 ' This time we DON'T clear the array Array[0] = 5 ' Load the array with binary values Array[1] = 6 'Array[2] = 7 ' And we purposly don't populate array[2] ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt ' Display results '---------------------------------------------------------------------------------------------- Test = 5 ' This time we DON'T clear the array either Array[0] = "5" ' But load the first to locations with ASCII representations of the value 56 Array[1] = "6" ' Array[2] = 7 ' Again, we don't populate array[2] ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt ' Display results '---------------------------------------------------------------------------------------------- Test = 6 ' We still don't clear the array Array[0] = "8" ' But load it with the ASCII representation of 89 Array[1] = "9" Array[2] = 0 ' This time we pad a null to the end though. ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt ' Display results '---------------------------------------------------------------------------------------------- Test = 8 ' We still don't clear the array Array[0] = "4" ' But load it with the ASCII representation of 47 Array[1] = "7" Array[2] = 65 ' This time we pad a value not corresponding to a numeric digit. ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt '---------------------------------------------------------------------------------------------- Test = 7 ' We still don't clear the array Array[0] = 49 ' But load it with the ASCII representation of 1234 Array[1] = 50 Array[2] = 51 Array[3] = 52 ArrayRead Array,[DEC Variable1] ' Try read the array into variable using DEC modifier. ArrayRead Array,[Variable2] GOSUB PrintIt '---------------------------------------------------------------------------------------------- Pause 10 END PrintIt: HSEROUT["Test ", DEC Test, ":",13] For i = 0 to (BufferLength-1) HSEROUT[DEC Array[i], ","] NEXT HSEROUT [13] HSEROUT ["Variable 1:", DEC Variable1,13] HSEROUT ["Variable 2:", DEC Variable2,13,13] RETURN
Here, all the array locations are null/zero. I don't know why the ArrayRead routine with the DEC modifier returns 8 but I guess the routine is actually using the Variable1 (in this case) internally and when it aborts it happens to have the value 8 in it. It sort of must be that since we DO clear it prior to this routine.Code:Test 1: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:8 Variable 2:0
Again, the ArrayRead with the DEC modifier fails since the values in the Array aren't ASCII code for any digits.Code:Test 2: 1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:8 Variable 2:1
Now ArrayRead with DEC works because this time we loaded the Array with values corresponding the ASCII characters/digits that we later try and read with ArrayRead and the DEC modifier.Code:Test 3: 49,50,51,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:123 Variable 2:49
This time we didn't clear the Array prior to reloading it. But since the first value isn't a valid ASCII code for a digit ArrayRead with DEC fails. And this time with another "random" number than in Test 1.Code:Test 4: 5,6,51,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:3 Variable 2:5
This time we only "reloaded" the first two locations but since the third location already contained a valid ASCII code for a numering digit the DEC modifier "included" that when reading the array - as expected of course.Code:Test 5: 53,54,51,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:563 Variable 2:53
Here we change the first two locations and "manually" padded a zero/null at the end. ArrayRead with the DEC modifier does its job.Code:Test 6: 56,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:89 Variable 2:56
(Yes, got them in the wron order). This time the third location in the array isn't null/zero but it still works because it's not a valid ASCII code for a numeric digit.Code:Test 8: 52,55,65,0,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:47 Variable 2:52
And again it works fine when array contains ASCII data.Code:Test 7: 49,50,51,52,0,0,0,0,0,0,0,0,0,0,0,0, Variable 1:1234 Variable 2:49
As you can see, in order for ARRAYREAD to work with the DEC modifier the array must containf the ASCII codes for the numeric value - otherwise it won't work. Obviously I don't know what your main code looks like but hopefully you'll be able to figure out why it works (or parhaps why you think it works).
/Henrik.




Bookmarks