Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Why cant I do this


MortenS Sep 9, 2011 11:28 AM

In my lttle sample program below I try to figure out why it dosn't work.
in TextOK the string is OK
but in TextFail, string is missing when I'm using ISCO_STS_Labels(ISCOStatusArray(STS)).
I don't know what it is called, but maybe some kind of double indexing ?
'========================================
Const MaxEventStringLength = 40
Const STS = 5' Current Status
Const CRLF = CHR(13)+CHR(10)

Public ISCOStatusLabels(10) As String * MaxEventStringLength
Public ISCOStatusArray(10) As String * 10
Public TextOK As String * 100
Public TextFail As String * 100
Public ISCO_STS_Labels(21) As String * MaxEventStringLength
Public STSCode

'Main Program
BeginProg
Scan (3,Sec,1,0)
TextOK = ""
TextFail = ""
ISCOStatusLabels(STS) = "Current Status"
ISCO_STS_Labels(9) = "SAMPLER OFF"
ISCOStatusArray(STS) = "9"
STSCode = ISCOStatusArray(STS)
TextOK = ISCOStatusLabels(STS) + "(STS) : " + ISCO_STS_Labels(STSCode)+"("+STSCode+")" + CRLF
TextFail = ISCOStatusLabels(STS) + "(STS) : " + ISCO_STS_Labels(ISCOStatusArray(STS))+"("+ISCOStatusArray(STS)+")" + CRLF
NextScan
EndProg
'========================================


aps Sep 9, 2011 01:32 PM

The problem is that you are using a string variable as the index value for the array. Although CRBasic does some implicit type conversion this is one step too far, i.e. it is not converting the string to a number correctly, resulting in the run-time out of bounds error(look in the status table).

If the iscostatusarray is defined as a float or integer it works fine. Also if you use STSCode as the index it works fine, because the conversion from a string to number is done when you say STSCode is equal to the string.

Andrew


MortenS Sep 9, 2011 03:43 PM

Andrew

Thanks for the explanation

Log in or register to post/reply in the forum.