Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my code I read the sound and then convert to binary I have a problem in it the result in
arraysound(i, j) when I print it be zero not the same result in ST in file "binary.txt"

VB
Dim s(5000000) As Byte
Dim sound() As UShort
Dim Binary(5000000, 8) As UShort
Dim arraysound(5000000, 8) As Integer
Dim l As Integer
Dim ST As String
Sub To_Binary(ByVal Sound() As UShort, ByRef Binary(,) As UShort)
    For i = 1 To l
        Dim D As Integer
        D = 1
        While Sound(i) > 0
            Binary(i, D) = Sound(i) Mod 2
            Sound(i) = Sound(i) \ 2
            D = D + 1
        End While
    Next
End Sub


Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click

    Dim i As Integer
    Dim w As New System.IO.StreamWriter("D:\information.txt")
    s = FileIO.FileSystem.ReadAllBytes("D:\male.wav")
    ReDim sound(Int(s.Length))

    l = s.Length

    For i = 0 To l - 1
        sound(i) = Int(s(i))

        w.WriteLine(sound(i))
    Next
    To_Binary(sound, Binary)
    Dim ST As String
    My.Computer.FileSystem.WriteAllText("d:\binary.txt", "", False)
    For i = 1 To sound.Length
        ST = ""
        For j = 0 To 7
            ST += Binary(i, j).ToString
        Next

         My.Computer.FileSystem.WriteAllText("d:\binary.txt", ST + vbCrLf, True)

    Next

    For i = 1 To sound.Length
        For j = 1 To 8
            arraysound(i, j) += ST

        Next

    Next

   For i = 1 To 4
       For j = 1 To 8
            TextBox5.Text += arraysound(i, j).ToString()
        Next
    Next
    w.Close()
End Sub
Posted
Updated 30-Apr-14 3:03am
v7
Comments
Maciej Los 29-Apr-14 16:54pm    
And the question is...
What kind of iisue do you have? Elaborate!
[no name] 30-Apr-14 1:33am    
my problem is when put the ST in arraysound(i,j) show message call me the index out of range
Sergey Alexandrovich Kryukov 29-Apr-14 17:14pm    
"Convert to binary"? As if your data on input was non-binary... :-)
—SA

1 solution

Seeing your code, you seem to use arrays sometimes with zero-based indices (from 0 to Array.Length - 1), and sometimes with one-based indices (from 1 to Array.Length).

I think this inconsistency is the source of your problem.

In VB, you can define whether you want to use zero-based or one-based arrays.
This may look like:
VB
Option Base [0 | 1]


By default, Option Base 0 is active.

You should stick to a given mode (zero-based or one-based), and not mix both modes in the same module.
IMHO, best option is to use the default (0-based).
 
Share this answer
 
Comments
phil.o 30-Apr-14 8:54am    
Option Base [0 | 1] means either Option Base 0 OR Option Base 1.
Please try at least to read the documentation on the language you are using, and not just copy/paste some code from a public forum without even trying to understand what is told to you.
[no name] 30-Apr-14 9:01am    
Okay, I'm update my question the new problem is when print 4 raw and 8 column the result be 32 zero do u know why

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900