使用vb.net将值放在数组2D中 [英] putting value in array 2D using vb.net

查看:84
本文介绍了使用vb.net将值放在数组2D中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中我读取声音然后转换为二进制我在它有一个问题结果在

arraysound(i,j)当我打印它是零时不一样的结果在ST在文件binary.txt



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"

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

推荐答案

看到你的代码,你似乎有时会使用基于零的索引(从0到Array.Length - 1),有时使用基于一的索引(从1到数组)。长度)。



我认为这种不一致是你问题的根源。



在VB中,你可以定义是否要使用从零开始或基于一个数组。

这可能如下所示:

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:
Option Base [0 | 1]





默认情况下,Option Base 0处于活动状态。 />


您应该坚持给定模式(从零开始或从一开始),而不是在同一模块中混合两种模式。

恕我直言,最好的选择是使用默认值(从0开始)。



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).


这篇关于使用vb.net将值放在数组2D中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆