Hi, new to the list and fairly new to VB.Net. Hope this is the correct forum. Been banging my head over this for a few days - can anyone help please?
I am in the midst of writing a new app to read a serial densitometer (shows ink density values). The result comes out of the unit as a String, eg - V0.23Y0.91M0.84C0.45, the bit I want is the MAX value. I've replaced the alpha characters with a "," to put it into an array, then converted the array to an integer array (had to multiply the values by 100 otherwise they'd be decimals - I don't mind decimals, just more familiar with integers). So far it all works fine.
However - I want to extract the MAX value and discard the others, so using a very well-worn bit of code from t'interweb that I've seen used at least once on this forum:
Now I just get an error
"Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'"
I've tried changing everything to a decimal, no good. Surely some of you boys and girls out there must be able to assist? I need the index reference as the 4 values refer to particular colours and so need to be in those positions - otherwise I'd just sort the array.
The value will eventually get written to a SQL Server DB and I did think of writing to a temp table there and doing the sorting that way but I'd prefer to keep it all on the one PC while it's working stuff out.
Any ideas, anyone?
I am in the midst of writing a new app to read a serial densitometer (shows ink density values). The result comes out of the unit as a String, eg - V0.23Y0.91M0.84C0.45, the bit I want is the MAX value. I've replaced the alpha characters with a "," to put it into an array, then converted the array to an integer array (had to multiply the values by 100 otherwise they'd be decimals - I don't mind decimals, just more familiar with integers). So far it all works fine.
VB.NET:
trimRead = Replace(densReading, "V", "")
trimRead = Replace(trimRead, "C", ",")
trimRead = Replace(trimRead, "M", ",")
trimRead = Replace(trimRead, "Y", ",")
convRead = Split(trimRead, ",")
Dim cA As Integer = Convert.ToInt32(convRead(1) * 100)
Dim mA As Integer = Convert.ToInt32(convRead(2) * 100)
Dim yA As Integer = Convert.ToInt32(convRead(3) * 100)
Dim kA As Integer = Convert.ToInt32(convRead(0) * 100)
Dim arrRead() As Integer = New Integer(3) {cA, mA, yA, kA}
However - I want to extract the MAX value and discard the others, so using a very well-worn bit of code from t'interweb that I've seen used at least once on this forum:
VB.NET:
Public Function MaxValOfIntArray(ByRef arrRead)
'This function gives max value of int array without sorting an array
Dim i
Dim MaxIntegersIndex
MaxIntegersIndex = 0
For i = 0 To UBound(arrRead)
If arrRead(i) > arrRead(MaxIntegersIndex) Then
MaxIntegersIndex = i
End If
Next
'index of max value is MaxValOfIntArray
MaxValOfIntArray = arrRead(MaxIntegersIndex)
End Function
Now I just get an error
"Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'"
I've tried changing everything to a decimal, no good. Surely some of you boys and girls out there must be able to assist? I need the index reference as the 4 values refer to particular colours and so need to be in those positions - otherwise I'd just sort the array.
The value will eventually get written to a SQL Server DB and I did think of writing to a temp table there and doing the sorting that way but I'd prefer to keep it all on the one PC while it's working stuff out.
Any ideas, anyone?
Last edited: