Visual Basic 6 function "volume_set_waveout"

Go back

Below you'll find the source for the Visual Basic 6 function volume_set_waveout.

Attribute VB_Name = "modVolumeSetWaveout"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long

''
' Sets the volume for the left and right channel
' @param    byte    chleft          The volume of the left channel (0 to 255)
' @param    byte    chright         The volume of the right channel (0 to 255)
' @param    long    device_id       If a computer has more then one audio device, you could use this to specify another
' @return   boolean                 True on success, false on failure
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function volume_set_waveout(ByVal chleft As Byte, ByVal chright As Byte, Optional ByVal device_id As Long = 0) As Boolean
    Dim sl As String, sr As String
    sl = Hex(65535 / 255 * chleft): sl = String(4 - Len(sl), "0") & sl
    sr = Hex(65535 / 255 * chright): sr = String(4 - Len(sr), "0") & sr
    If waveOutSetVolume(device_id, Val("&h" & sl & sr)) = 0 Then volume_set_waveout = True
End Function