One approach would be to create arrays of the needed values, for example mydevicedetected and myDevicePathName and HidHandle.
In FindTheHid, on detecting a matching device, set mydevicedetected(index) = true and save myDevicePathName(index). Get HidHandle(index).
Continue looping until memberIndex = devicePathName.Length
Each time you find another match, increment the index and set mydevicedetected(index) = true and save myDevicePathName(index) and HidHandle(index)..
At the end you will have an array of handles to use for writing data.