Hello. Can you please tell me how to make all instances of the "Note" class use the same midiOut? That is, that it (midiOut) is not created for each instance.

Class Note Public midiOut As Midi.MidiOut = New Midi.MidiOut(0) Public Sub Play() midiOut.Send(Midi.MidiMessage.StartNote(note, 127, 1).RawData) Threading.Thread.Sleep(1000) midiOut.Send(Midi.MidiMessage.StopNote(note, 0, 1).RawData) End Sub End Class 
  • I tried to announce midiOut as Shared - it helped, but did I do the right thing? - dizar47

1 answer 1

  • Shared in VB has the semantics of static , and therefore refers to a class in general, and not to any particular class object.

  • midiOut in this example is more correctly declared as Private Shared , or use approximately the following pattern:

http://yuml.me/e0d4634f