Results 1 to 9 of 9

Thread: [RESOLVED]Calling a function from usercontrole

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    87

    Resolved [RESOLVED]Calling a function from usercontrole

    Dont know what the problem is...


    here is my usercontrole
    Code:
    Option Explicit
    Private DX_Main                         As New DirectX7
    Private DX_Writer                       As DirectSound
    Private DX_WriterBuffer                 As DirectSoundBuffer
    Private WAVBuffer()                     As Byte
    Private SamplesPerSec                   As Long
    Private Channels                        As Byte
    Private BitsPerSample                   As Integer
    Private DataLength                      As Long
    Private DataLengthTemp                  As Long
    Private Match                           As Boolean
    Private Sub UserControl_Resize()
        UserControl.Width = Img_Interface.Width
        UserControl.Height = Img_Interface.Height
    End Sub
    Public Sub InitReceiver()
        If DX_WriterBuffer Is Nothing Then Call CreateBuffer
        DX_WriterBuffer.Play DSBPLAY_LOOPING
    End Sub
    Private Function CreateBuffer() As String
    On Error GoTo ErrorHandel:
        Dim BufferDescription           As DSBUFFERDESC
        Dim WAVFormat                   As WAVEFORMATEX
        Set DX_Writer = DX_Main.DirectSoundCreate("")
        DX_Writer.SetCooperativeLevel UserControl.hWnd, DSSCL_PRIORITY
        WAVFormat = SetWavFormat(SamplesPerSec, Channels, BitsPerSample)
        BufferDescription.lBufferBytes = WAVFormat.lAvgBytesPerSec
        BufferDescription.lFlags = DSBCAPS_CTRLPOSITIONNOTIFY Or DSBCAPS_GLOBALFOCUS Or DSBCAPS_GETCURRENTPOSITION2
        Set DX_WriterBuffer = DX_Writer.CreateSoundBuffer(BufferDescription, WAVFormat)
    Exit Function
    ErrorHandel:
    CreateBuffer = "Error Source: " & Err.Source & vbCrLf & "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description
    End Function
    Private Function SetWavFormat(ByVal WSamplesPerSec As Long, ByVal WChannels As Byte, ByVal WBitsPerSample As Integer) As WAVEFORMATEX
        SetWavFormat.nFormatTag = WAVE_FORMAT_PCM
        SetWavFormat.nChannels = WChannels
        SetWavFormat.lSamplesPerSec = WSamplesPerSec
        SetWavFormat.nBitsPerSample = WBitsPerSample
        SetWavFormat.nBlockAlign = WChannels * WBitsPerSample / 8
        SetWavFormat.lAvgBytesPerSec = SetWavFormat.lSamplesPerSec * SetWavFormat.nBlockAlign
        SetWavFormat.nSize = 0
    End Function
    Public Sub SetWavQuality(ByVal WSamplesPerSec As Long, ByVal WChannels As Byte, ByVal WBitsPerSample As Integer)
        SamplesPerSec = WSamplesPerSec
        Channels = WChannels
        BitsPerSample = WBitsPerSample
    End Sub
    Public Sub DestroyObjects()
        Set DX_Main = Nothing
        Set DX_Writer = Nothing
        Set DX_WriterBuffer = Nothing
    End Sub
    Public Sub StopStreaming()
        DX_WriterBuffer.Stop
    End Sub
    Private Sub Receiver_DataArrival(ByVal bytesTotal As Long)
        On Error Resume Next
        Receiver.GetData WAVBuffer, vbArray + vbByte, bytesTotal
        DX_WriterBuffer.WriteBuffer 0, UBound(WAVBuffer), WAVBuffer(0), DSBLOCK_DEFAULT
        'DataLength = bytesTotal
    End Sub
    'Private Sub Checker_Timer()
    '    If DataLengthTemp = DataLength Then
    '        StopStreaming
    '    Else
    '        DX_WriterBuffer.Play DSBPLAY_LOOPING
    '        DataLengthTemp = DataLength
    '    End If
    'End Sub
    Private Sub Receiver_Close()
        StopStreaming
    End Sub
    Public Sub SetNetworkParameters(ByVal Protocol As Byte, ByVal LocalPort As Long)
        Receiver.Close
        Receiver.Protocol = Protocol
        Receiver.LocalPort = LocalPort
        Receiver.Bind LocalPort
    End Sub
    I added the directx to my project and added the usercontrole to the main form but still getting "Sub not definded" when im calling the SetNetworkParameters

    here is my form code

    Code:
    Private Sub Form_Load()
        Call Receiver.SetNetworkParameters(1, 19841)
        Call Receiver.SetWavQuality(8000, 1, 8)
        Call Receiver.InitReceiver
    End Sub
    Please help
    Last edited by Milad87; Jun 1st, 2008 at 05:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width