0
 Sub voicecounterA() If counterA = 1 Then My.Computer.Audio.Play(My.Resources.SCOM1, AudioPlayMode.WaitToComplete) ElseIf counterA = 2 Then My.Computer.Audio.Play(My.Resources.SCOM2, AudioPlayMode.WaitToComplete) ElseIf counterA = 3 Then My.Computer.Audio.Play(My.Resources.SCOM3, AudioPlayMode.WaitToComplete) ElseIf counterA = 4 Then My.Computer.Audio.Play(My.Resources.SCOM4, AudioPlayMode.WaitToComplete) ElseIf counterA = 5 Then My.Computer.Audio.Play(My.Resources.SCOM5, AudioPlayMode.WaitToComplete) ElseIf counterA = 6 Then My.Computer.Audio.Play(My.Resources.SCOM6, AudioPlayMode.WaitToComplete) ElseIf counterA = 7 Then My.Computer.Audio.Play(My.Resources.SCOM7, AudioPlayMode.WaitToComplete) ElseIf counterA = 8 Then My.Computer.Audio.Play(My.Resources.SCOM8, AudioPlayMode.WaitToComplete) ElseIf counterA = 9 Then My.Computer.Audio.Play(My.Resources.SCOM9, AudioPlayMode.WaitToComplete) ElseIf counterA = 10 Then My.Computer.Audio.Play(My.Resources.SCOM10, AudioPlayMode.WaitToComplete) ElseIf counterA = 101 Then My.Computer.Audio.Play(My.Resources.SCOM10, AudioPlayMode.WaitToComplete) End If End Sub 

I have a simple code how to simplify this code to make it simpler, so when I click on Call menu it will be call next voice, so I dont have to use so many code if i want to call 100 people

I am using vb

4
  • 3
    Is this VBA, VB.NET or VbScript? Commented Jun 14, 2021 at 11:19
  • 3
    VBA? vbScript? VB.Net? Vb6? Commented Jun 14, 2021 at 11:19
  • 1
    In what way you want to simplify this more? Personally i would use a Select Case but that does not reduce the amount of code needed. Imo this is simple and clear enough Commented Jun 14, 2021 at 11:23
  • I am using VB.NET Commented Jun 14, 2021 at 11:24

1 Answer 1

3

You could use a Dictionary(Of Int32, String), then your code becomes:

Private Shared AudioResources As New Dictionary(Of Int32, String) From {{1, My.Resources.SCOM1},{2, My.Resources.SCOM2},{3, My.Resources.SCOM3},{4, My.Resources.SCOM4},{5, My.Resources.SCOM5}, {6, My.Resources.SCOM6},{7, My.Resources.SCOM7},{8, My.Resources.SCOM8},{9, My.Resources.SCOM9},{10, My.Resources.SCOM10},{101, My.Resources.SCOM10}} Sub voicecounterA() Dim audioResource As String = Nothing If AudioResources.TryGetValue(counterA, audioResource) My.Computer.Audio.Play(audioResource, AudioPlayMode.WaitToComplete) End If End Sub 
Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou for answering my question #Schmelter, I was trying to use this code but still not work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.