Change the Type Parameter in a For Loop?

57 views Asked by At

So I'm close with this code but not home free yet. The "Of Integer" part needs to change to "Of Single" once the For Loop gets to a channel that is of a Single data type. Is there an easy way to do that without explicitly coding it "Of Single"? If not, then I don't think I'm going to be able to Loop through this like I'm trying to do. I tried to just omit the first parameter after the AppendData I.E. "Channels(i).AppendData(jaggedArray(i))" and although I don't get an error when compiling, it does throw an exception when running the code. So that doesn't work. It requires the data type parameter and of course the array of data that is to be appended.

For Each c As TdmsChannel In Channels
        Channels(i).AppendData(Of Integer)(jaggedArray(i))
        i += 1
    Next
1

There are 1 answers

0
busarider29 On

I figured it out. Actually there was a method for the channel collections that one can use to get the datatype. I used that method in order to determine how to append the data (Of Integer, Of Single, or Of Boolean types).

Dim dtype As System.Type
    For Each c As TdmsChannel In Channels
        dtype = Channels(i).GetDataType
        If dtype.Name = "Int32" Then
            Channels(i).AppendData(Of Integer)(jaggedarray(i))
        ElseIf dtype.Name = "Single" Then
            Channels(i).AppendData(Of Single)(jaggedarray(i))
        ElseIf dtype.Name = "Boolean" Then
            Channels(i).AppendData(Of Boolean)(jaggedarray(i))
        End If
        i += 1
    Next