注册 登录
编程论坛 VB.NET论坛

请教各位怎么循环数组

qinyi92 发布于 2019-10-12 16:18, 2448 次点击
刚开始学习,请教各位大佬怎么循环数组
A1*1后面怎么多出个117,请教各位帮我看一下代码怎么修改

Public Class Form2
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f As String
        '设置打开的文本格式
        OpenFileDialog1.Filter = "Text Files(*.TXT)|*.TXT"
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            f = (OpenFileDialog1.FileName)
            '下面是把文本里的度分秒符号替换,这个是中海达格式
            f = Replace(Trim(f), "°", ",")
            f = Replace(Trim(f), "′", ",")
            f = Replace(Trim(f), "″,", ",")
            Dim f1 As String()
            Dim f2 As Double, f3 As Double, f4 As Double
            Dim f5 As String
            Dim i As Integer, i1 As Integer
            For i = 0 To f.Length
                f1 = f.Split(",")
                f2 = Val(f1(0) + f1(1) / 60 + f1(2) / 3600)
                f3 = Val(f1(3) + f1(4) / 60 + f1(5) / 3600)
                f4 = Val(f1(6))
                f5 = f1(7)
                TextBox1.Text = f2
                'TextBox2.Text = f3
                DataGridView1.Rows.Add(f2, f3, f4, f5)
            Next

        End If
2 回复
#2
qinyi922019-10-12 16:19
只有本站会员才能查看附件,请 登录
#3
ccmirlove2019-11-08 08:56
使用这个.getupperbound应该是可以的,不过起始值从1开始,你修改一下你的代码即可。

For i = 0 To f.GetUpperBound(0)
    f1 = f.Split(",")
         f2 = Val(f1(0) + f1(1) / 60 + f1(2) / 3600)
          f3 = Val(f1(3) + f1(4) / 60 + f1(5) / 3600)
          f4 = Val(f1(6))
          f5 = f1(7)
          TextBox1.Text = f2
          'TextBox2.Text = f3
          DataGridView1.Rows.Add(f2, f3, f4, f5)
Next



p.s:中海达,看来大家是同行啊~~
1