6 Replies - 589 Views - Last Post: 14 June 2015 - 12:43 AM Rate Topic: -----

#1 john02813  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-June 15

had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 11:36 AM

How do I use VB 6 code that requires DirectX version 8 when my computer has Windows 7 Pro and DirectX 11 installed? I tried to convert the vb 6 code to VB.net version 4.5 and use in VS 2013 but I am lost as the two DirectXs are not compatible. I just wanted to see what DirectX is all about. I wanted to draw a 3D triangle for fun.
Is This A Good Question/Topic? 0
  • +

Replies To: had a VB 6 program that could play music but VB.net isn't able

#2 john02813  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-June 15

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 12:05 PM

I programmed in VB 6.0 many years ago and created a program that plays Happy Birthday with up to 4 chords of notes. I am unable to create this with vb.net 4.5 as all I get are unpleasant notes. I use a midi and create the frequency and octaves etc but vb.net doesn't seem to be able to accomplish this. I wish I had kept the code from VB 6 but my programs were deleted when I upgraded from Vista to Windows 7 Pro. Now I don't even have DirectX 9 as the new Windows installed DirectX 11 which doesn't work with VB 6. Any ideas?
Was This Post Helpful? 0
  • +
  • -

#3 RamonRobben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 538
  • Joined: 19-May 14

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 12:11 PM

i dunno if this is programming help or just generaly vb.net :/
What have you tried so far to reasearch how you can accomplish that?

This post has been edited by RamonRobben: 13 June 2015 - 12:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 john02813  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-June 15

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 12:29 PM

Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim MidiCaps As MIDIOUTCAPS = MidiOpen(0)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Channel_0 As Integer = 0
        Dim Channel_1 As Integer = 1

        SetInstrument(0, 3)
        SetInstrument(1, 4)
        Dim Volume As Byte = 127
        Dim Oct As Integer = 62
        '  C = 0    C_Sharp = 1  D = 2   D_Sharp = 3 e = 4   F = 5    F_Sharp = 6   G = 7
        '    G_Sharp = 8  A = 9  A_Sharp = 10  B = 11
        ' C4 C4 D4 C4 F4 E4 C4 C4 D4 C4 G4 F4 
        'C4 C4 C5 A4 F4 E4 D4 B4 B4 A4 F4 G4 F4
        '262 1/2 sec py  262 1/2 sec birth  294 1 sec day 262 1 sec
        'to F4 349 1 sec you E4 330 2 sec hap C4 262 1/2 sec py C4 262 1/2 sec
        'birth D4 294 1 sec day C4 262 1 sec to G4 392 1 sec you F4 349 2 sec
        'hap C4 262 1/2 sec py C4 262 1/2 sec birth C5 523 1 sec day A4 440 1 sec
        'dear F4 349 1 sec so E4 330 1 sec so D4 294 3 sec hap B4b 466 1 sec
        'py B4b 466 1 sec birth A4 440 1 sec day F4 349 1 sec to G4 392 1 sec you! F4 349 2 sec
        Dim Player1 As New Threading.Thread(AddressOf PlayOnChannel0)
        Dim Player2 As New Threading.Thread(AddressOf PlayOnChannel1)

        Play(Oct, 0, 250, Volume, 0)  ' C
        Play(Oct, 0, 250, Volume, 0)  ' C
        Play(Oct, 2, 500, Volume, 0)  ' D
        Play(Oct, 0, 500, Volume, 0)  ' C
        Play(Oct, 5, 500, Volume, 0)  ' F
        Play(Oct, 4, 1000, Volume, 0)  ' E
        Play(Oct, 0, 250, Volume, 0)  ' C
        Play(Oct, 0, 250, Volume, 0)  ' C
        Play(Oct, 2, 500, Volume, 0)  ' D
        Play(Oct, 0, 500, Volume, 0)  ' C
        Play(Oct, 7, 500, Volume, 0)  ' G
        Play(Oct, 5, 1000, Volume, 0)  ' F
        Play(Oct, 0, 250, Volume, 0)  ' C
        Play(Oct, 0, 250, Volume, 0)  ' C
        Oct = 66
        Play(Oct, 8, 500, Volume, 0)  ' C
        Oct = 62
        Play(Oct, 4, 500, Volume, 0)  ' A
        Play(Oct, 5, 500, Volume, 0)  ' F
        Play(Oct, 4, 500, Volume, 0) ' E 
        Play(Oct, 2, 1500, Volume, 0)  ' D
        Play(Oct, 11, 500, Volume, 0)  ' B
        Play(Oct, 11, 500, Volume, 0)  ' B
        Play(Oct, 9, 500, Volume, 0)  ' A
        Play(Oct, 5, 500, Volume, 0)  ' F
        Play(Oct, 7, 500, Volume, 0)  ' G
        Play(Oct, 5, 1000, Volume, 0)  ' F

        Play(Oct, 0, 250, Volume, 1)  ' C
        Play(Oct, 0, 250, Volume, 1)  ' C
        Play(Oct, 2, 500, Volume, 1)  ' D
        Play(Oct, 0, 500, Volume, 1)  ' C
        Play(Oct, 5, 500, Volume, 1)  ' F
        Play(Oct, 4, 1000, Volume, 1)  ' E
        Play(Oct, 0, 250, Volume, 1)  ' C
        Play(Oct, 0, 250, Volume, 1)  ' C
        Play(Oct, 2, 500, Volume, 1)  ' D
        Play(Oct, 0, 500, Volume, 1)  ' C
        Play(Oct, 7, 500, Volume, 1)  ' G
        Play(Oct, 5, 1000, Volume, 1)  ' F
        Play(Oct, 0, 250, Volume, 1)  ' C
        Play(Oct, 0, 250, Volume, 1)  ' C
        Oct = 66
        Play(Oct, 8, 500, Volume, 1)  ' C
        Oct = 62
        Play(Oct, 4, 500, Volume, 1)  ' A
        Play(Oct, 5, 500, Volume, 1)  ' F
        Play(Oct, 4, 500, Volume, 1) ' E 
        Play(Oct, 2, 1500, Volume, 1)  ' D
        Play(Oct, 11, 500, Volume, 1)  ' B
        Play(Oct, 11, 500, Volume, 1)  ' B
        Play(Oct, 9, 500, Volume, 1)  ' A
        Play(Oct, 5, 500, Volume, 1)  ' F
        Play(Oct, 7, 500, Volume, 1)  ' G
        Play(Oct, 5, 1000, Volume, 1)  ' F
        End


       
    End Sub


    

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MidiClose()
    End Sub

End Class





Module Midi

    Public Tempo As Integer = 500

    
    Public Blanche As Integer = Tempo * 4
    Public [DOUBLE] As Integer = Tempo * 2
    Public WHOLE As Integer = Tempo
    Public HALF As Integer = Tempo \ 2
    Public QUARTER As Integer = Tempo \ 4
    Public EIGHTH As Integer = Tempo \ 8
    Public SIXTEENTH As Integer = Tempo \ 16

    Const KeysDown As Byte = 144
    Const KeysUp As Byte = 128

    Declare Auto Function midiOutGetDevCaps Lib "winmm.dll" (ByVal uDeviceID As Integer, ByRef lpMidiOutCaps As MIDIOUTCAPS, ByVal cbMidiOutCaps As Integer) As Integer
    Declare Function midiOutOpen Lib "winmm.dll" (ByRef lphmo As IntPtr, ByVal uDeviceID As Integer, ByVal dwCallback As Integer, ByVal dwCallbackInstance As Integer, ByVal dwFlags As Integer) As Integer
    Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hmo As IntPtr, ByVal dwMsg As Integer) As Integer
    Declare Function midiOutClose Lib "winmm.dll" (ByVal hmo As IntPtr) As Integer

    Public Caps As MIDIOUTCAPS
    Public hmo As IntPtr
    Private RetValue As Integer

    Public Function MidiOpen(ByVal DevID As Integer) As MIDIOUTCAPS
        RetValue = midiOutGetDevCaps(DevID, Caps, Runtime.InteropServices.Marshal.SizeOf(Caps))
        If Not RetValue = 0 Then
            MsgBox("midiOutGetDevCaps error " & CStr(RetValue))
            Return Caps
        End If
        RetValue = midiOutOpen(hmo, DevID, 0, 0, 0)
        If RetValue = 0 Then Return Caps
        MsgBox("midiOutOpen error " & CStr(RetValue))
        Return Caps
    End Function


    Function NoteFrequency(ByVal octave As Octave, ByVal note As Note) As Integer
        Return octave + note
    End Function

    Sub Play(ByVal O As Octave, ByVal N As Note, ByVal D As Integer, ByVal V As Byte, ByVal channel As Byte)
        KeysMsg(channel, CByte(O + N), V, KeysDown)
        Threading.Thread.Sleep(D)
        KeysMsg(channel, CByte(O + N), V, KeysUp)
    End Sub

    Sub pause(ByVal D As Integer)
        Threading.Thread.Sleep(D)
    End Sub

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MIDIOUTCAPS
        Dim ManufacturerID As Short
        Dim ProductID As Short
        Dim DriverVersion As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
        Dim Label As String
        Dim Technology As Short
        Dim Voices As Short
        Dim Notes As Short
        Dim ChannelMask As Short
        Dim Support As Integer
    End Structure


    Public Sub KeysMsg(ByVal Channel As Byte, ByVal Note As Byte, ByVal Volume As Byte, ByVal PressState As Byte)
        Dim msg As Integer
        msg = Volume
        msg = (msg << 8) + Note
        msg = (msg << 8) + PressState + Channel
        RetValue = midiOutShortMsg(hmo, msg)
        If RetValue = 0 Then Return
        MsgBox("Error in midiOutShortMsg " & CStr(RetValue))
    End Sub

    Public Sub SetInstrument(ByVal Channel As Integer, ByVal Patch As Integer)
        Dim Status As Integer = &HC0 + Channel
        Dim msg As Integer = (Patch << 8) + Status
        Dim ret = midiOutShortMsg(hmo, msg)
    End Sub

    Public Sub MidiClose()
        RetValue = midiOutClose(hmo)
        If RetValue = 0 Then Return
        MsgBox("midiOutClose error " & CStr(RetValue))
    End Sub

End Module

This post has been edited by andrewsw: 14 June 2015 - 05:16 AM
Reason for edit:: Added [code][/code] tags

Was This Post Helpful? 0
  • +
  • -

#5 RamonRobben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 538
  • Joined: 19-May 14

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 03:03 PM

Please put your code between code tags it will be much nicer to look at, and people are more likely to help you :)
Was This Post Helpful? 0
  • +
  • -

#6 john02813  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-June 15

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 13 June 2015 - 04:04 PM

View PostRamonRobben, on 13 June 2015 - 03:03 PM, said:

Please put your code between code tags it will be much nicer to look at, and people are more likely to help you :)/>

That is all vb.net code
Was This Post Helpful? 0
  • +
  • -

#7 maceysoftware  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,491
  • Joined: 07-September 13

Re: had a VB 6 program that could play music but VB.net isn't able

Posted 14 June 2015 - 12:43 AM

Hey John,

it doesn't matter what language it is, when posting code snippets they should be within a code tags [ code ][ /code ] - removing the spaces I just put in.


this will allow users to be able to view the code more easier as it will be in a structured way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1