Click here to Skip to main content
15,926,281 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHelp on code translated from c# Pin
MikeMarq26-Sep-07 14:17
MikeMarq26-Sep-07 14:17 
AnswerThe code for the form Pin
MikeMarq26-Sep-07 14:18
MikeMarq26-Sep-07 14:18 
AnswerRe: Help on code translated from c# Pin
Dave Doknjas26-Sep-07 14:38
Dave Doknjas26-Sep-07 14:38 
GeneralRe: Help on code translated from c# Pin
MikeMarq26-Sep-07 14:52
MikeMarq26-Sep-07 14:52 
Generalc# Main Pin
MikeMarq26-Sep-07 14:52
MikeMarq26-Sep-07 14:52 
GeneralRe: c# Main Pin
Dave Doknjas26-Sep-07 15:21
Dave Doknjas26-Sep-07 15:21 
Generalc# Formats Pin
MikeMarq26-Sep-07 14:53
MikeMarq26-Sep-07 14:53 
GeneralRe: c# Formats Pin
Dave Doknjas26-Sep-07 15:22
Dave Doknjas26-Sep-07 15:22 
(via Instant VB)

Imports Microsoft.VisualBasic
'----------------------------------------------------------------------------
' File: Formats.cs
'
' Copyright (c) Microsoft Corp. All rights reserved.
'-----------------------------------------------------------------------------
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Collections
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound

Public Class FormatsForm
Inherits Form
Private Structure FormatInfo
Public format As WaveFormat
Public Overrides Function ToString() As String
Return ConvertWaveFormatToString(format)
End Function
End Structure
Private WithEvents buttonOk As Button
Private WithEvents buttonCancel As Button
Private WithEvents lbFormatsInputListbox As ListBox
Private WithEvents labelStatic As Label

Private mf As MainForm = Nothing
Private formats As ArrayList = New ArrayList()
Private InputFormatSupported As Boolean() = New Boolean(19){}
Public Sub New(ByVal mf As MainForm)
'
' Required for Windows Form Designer support
'
InitializeComponent()
Me.mf = mf

ScanAvailableInputFormats()
FillFormatListBox()
End Sub
#Region "InitializeComponent code"
Private Sub InitializeComponent()
Me.buttonOk = New System.Windows.Forms.Button()
Me.buttonCancel = New System.Windows.Forms.Button()
Me.lbFormatsInputListbox = New System.Windows.Forms.ListBox()
Me.labelStatic = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
' buttonOk
'
Me.buttonOk.Enabled = False
Me.buttonOk.Location = New System.Drawing.Point(10, 128)
Me.buttonOk.Name = "buttonOk"
Me.buttonOk.Size = New System.Drawing.Size(75, 23)
Me.buttonOk.TabIndex = 0
Me.buttonOk.Text = "OK"
'Me.buttonOk.Click += New System.EventHandler(Me.buttonOk_Click);
'
' buttonCancel
'
Me.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.buttonCancel.Location = New System.Drawing.Point(97, 128)
Me.buttonCancel.Name = "buttonCancel"
Me.buttonCancel.Size = New System.Drawing.Size(75, 23)
Me.buttonCancel.TabIndex = 1
Me.buttonCancel.Text = "Cancel"
'Me.buttonCancel.Click += New System.EventHandler(Me.buttonCancel_Click);
'
' lbFormatsInputListbox
'
Me.lbFormatsInputListbox.Location = New System.Drawing.Point(10, 24)
Me.lbFormatsInputListbox.Name = "lbFormatsInputListbox"
Me.lbFormatsInputListbox.Size = New System.Drawing.Size(162, 95)
Me.lbFormatsInputListbox.TabIndex = 2
'Me.lbFormatsInputListbox.SelectedIndexChanged += New System.EventHandler(Me.lbFormatsInputListbox_SelectedIndexChanged);
'
' labelStatic
'
Me.labelStatic.Location = New System.Drawing.Point(10, 11)
Me.labelStatic.Name = "labelStatic"
Me.labelStatic.Size = New System.Drawing.Size(75, 13)
Me.labelStatic.TabIndex = 3
Me.labelStatic.Text = "Input Format:"
'Me.labelStatic.Click += New System.EventHandler(Me.labelStatic_Click);
'
' FormatsForm
'
Me.AcceptButton = Me.buttonOk
Me.CancelButton = Me.buttonCancel
Me.ClientSize = New System.Drawing.Size(183, 170)
Me.Controls.Add(Me.buttonOk)
Me.Controls.Add(Me.buttonCancel)
Me.Controls.Add(Me.lbFormatsInputListbox)
Me.Controls.Add(Me.labelStatic)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "FormatsForm"
Me.Text = "Select Capture Format"
Me.ResumeLayout(False)

End Sub
#End Region
Private Sub ScanAvailableInputFormats()
'-----------------------------------------------------------------------------
' Name: ScanAvailableInputFormats()
' Desc: Tests to see if 20 different standard wave formats are supported by
' the capture device
'-----------------------------------------------------------------------------
Dim format As WaveFormat = New WaveFormat()
Dim dscheckboxd As CaptureBufferDescription = New CaptureBufferDescription()
Dim pDSCaptureBuffer As CaptureBuffer = Nothing

' This might take a second or two, so throw up the hourglass
Cursor = Cursors.WaitCursor

format.FormatTag = WaveFormatTag.Pcm

' Try 20 different standard formats to see if they are supported
For iIndex As Integer = 0 To 19
GetWaveFormatFromIndex(iIndex, format)

' To test if a capture format is supported, try to create a
' new capture buffer using a specific format. If it works
' then the format is supported, otherwise not.
dscheckboxd.BufferBytes = format.AverageBytesPerSecond
dscheckboxd.Format = format

Try
pDSCaptureBuffer = New CaptureBuffer(dscheckboxd, mf.applicationDevice)
InputFormatSupported(iIndex) = True
Catch
InputFormatSupported(iIndex) = False
End Try
If Not pDSCaptureBuffer Is Nothing Then
pDSCaptureBuffer.Dispose()
End If
Next iIndex
Cursor = Cursors.Default
End Sub
Private Sub GetWaveFormatFromIndex(ByVal Index As Integer, ByRef format As WaveFormat)
'-----------------------------------------------------------------------------
' Name: GetWaveFormatFromIndex()
' Desc: Returns 20 different wave formats based on Index
'-----------------------------------------------------------------------------
Dim SampleRate As Integer = Index \ 4
Dim iType As Integer = Index Mod 4

Select Case SampleRate
Case 0
format.SamplesPerSecond = 48000
Case 1
format.SamplesPerSecond = 44100
Case 2
format.SamplesPerSecond = 22050
Case 3
format.SamplesPerSecond = 11025
Case 4
format.SamplesPerSecond = 8000
End Select

Select Case iType
Case 0
format.BitsPerSample = 8
format.Channels = 1
Case 1
format.BitsPerSample = 16
format.Channels = 1
Case 2
format.BitsPerSample = 8
format.Channels = 2
Case 3
format.BitsPerSample = 16
format.Channels = 2
End Select

format.BlockAlign = CShort(Fix(format.Channels * (format.BitsPerSample / 8)))
format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond
End Sub
Private Sub FillFormatListBox()
'-----------------------------------------------------------------------------
' Name: FillFormatListBox()
' Desc: Fills the format list box based on the availible formats
'-----------------------------------------------------------------------------
Dim info As FormatInfo = New FormatInfo()
Dim strFormatName As String = String.Empty
Dim format As WaveFormat = New WaveFormat()

For iIndex As Integer = 0 To InputFormatSupported.Length - 1
If True = InputFormatSupported(iIndex) Then
' Turn the index into a WaveFormat then turn that into a
' string and put the string in the listbox
GetWaveFormatFromIndex(iIndex, format)
info.format = format
formats.Add(info)
End If
Next iIndex
lbFormatsInputListbox.DataSource = formats
End Sub
Private Shared Function ConvertWaveFormatToString(ByVal format As WaveFormat) As String
'-----------------------------------------------------------------------------
' Name: ConvertWaveFormatToString()
' Desc: Converts a wave format to a text string
'-----------------------------------------------------------------------------
If (format.Channels = 1) Then
Return format.SamplesPerSecond & " Hz, " & format.BitsPerSample & "-bit " & ("Mono")
Else
Return format.SamplesPerSecond & " Hz, " & format.BitsPerSample & "-bit " & ("Stereo")
End If
End Function
Private Sub FormatsOK()
'-----------------------------------------------------------------------------
' Name: FormatsOK()
' Desc: Stores the capture buffer format based on what was selected
'-----------------------------------------------------------------------------

mf.InputFormat = (CType(formats(lbFormatsInputListbox.SelectedIndex), FormatInfo)).format
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Close()
End Sub
Private Sub buttonOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonOk.Click
FormatsOK()
End Sub

Private Sub lbFormatsInputListbox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbFormatsInputListbox.SelectedIndexChanged
buttonOk.Enabled = True
End Sub

Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonCancel.Click

End Sub

Private Sub labelStatic_Click(ByVal sender As Object, ByVal e As EventArgs) Handles labelStatic.Click

End Sub
End Class


David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
Generalc# Devices Pin
MikeMarq26-Sep-07 14:53
MikeMarq26-Sep-07 14:53 
Generalc# assembly info Pin
MikeMarq26-Sep-07 15:08
MikeMarq26-Sep-07 15:08 
GeneralRe: c# assembly info Pin
Dave Doknjas26-Sep-07 15:25
Dave Doknjas26-Sep-07 15:25 
GeneralRe: c# Devices Pin
Dave Doknjas26-Sep-07 15:25
Dave Doknjas26-Sep-07 15:25 
GeneralRe: Help on code translated from c# Pin
MikeMarq26-Sep-07 18:18
MikeMarq26-Sep-07 18:18 
GeneralRe: Help on code translated from c# Pin
Dave Doknjas27-Sep-07 5:16
Dave Doknjas27-Sep-07 5:16 
Questionwhat this code means? Pin
ArielR26-Sep-07 8:07
ArielR26-Sep-07 8:07 
AnswerRe: what this code means? Pin
ESTAN26-Sep-07 9:04
ESTAN26-Sep-07 9:04 
AnswerRe: what this code means? Pin
Luc Pattyn26-Sep-07 9:10
sitebuilderLuc Pattyn26-Sep-07 9:10 
GeneralRe: what this code means? Pin
ESTAN26-Sep-07 9:13
ESTAN26-Sep-07 9:13 
GeneralRe: what this code means? Pin
ArielR26-Sep-07 10:20
ArielR26-Sep-07 10:20 
AnswerRe: what this code means? Pin
Guffa26-Sep-07 9:11
Guffa26-Sep-07 9:11 
AnswerRe: what this code means? Pin
Christian Graus26-Sep-07 12:50
protectorChristian Graus26-Sep-07 12:50 
QuestionHow to filter data on Crystal Reports? Pin
shyne726-Sep-07 5:02
shyne726-Sep-07 5:02 
QuestionHow to know which control is selected at runtime for runtime generated controls Pin
VB 8.026-Sep-07 1:56
VB 8.026-Sep-07 1:56 
AnswerRe: How to know which control is selected at runtime for runtime generated controls Pin
ESTAN26-Sep-07 12:54
ESTAN26-Sep-07 12:54 
GeneralRe: How to know which control is selected at runtime for runtime generated controls Pin
VB 8.027-Sep-07 3:19
VB 8.027-Sep-07 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.