我有这个代码的一些问题,我找不到它错在哪里... [英] I Have Some Problem With This Codes And I Can't Find Where It Did Go Wrong...

查看:64
本文介绍了我有这个代码的一些问题,我找不到它错在哪里...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim i As Integer = ListBox1.Items.Count - 1
            Try

                With SerialPort1
                    SerialPort1.WriteLine("AT" & vbCrLf)
                    Threading.Thread.Sleep(1000)
                    SerialPort1.WriteLine("AT+CMGF=1" & vbCrLf)
                    Threading.Thread.Sleep(1000)
                SerialPort1.WriteLine("AT+CMGS=" & i & vbCrLf)
                    Threading.Thread.Sleep(1000)
                    SerialPort1.WriteLine(tx1.Text)


                End With

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try









它只能发送一个项目列表框的第一个记录,但不能发送列表框中的所有记录,它不会给出任何错误... 。请帮助我...





It can send only one item the first record of listbox but not all the records in the listbox and it doen't give any errors....please help me...

推荐答案

变量'i'只是las的索引列表中的t项。你需要一个循环遍历列表并使用i作为索引,例如listBox.Items [i];
Variable 'i' is just the index of the last item in the list. You need a loop to iterate through the list and use i as an index e.g listBox.Items[i];


你需要一个循环,例如:

You need to have a loop, for example:
For Each item As Object In myListBox.Items
    ' do something with item here, send it, and so on...
    ' first, type-cast item to the item type you actually stored in the list box
Next





顺便说一句,永远不要使用自动生成的名称,例如 listBox1 ,总是将它们重命名为您的语义敏感名称。

像listBox1这样的名称违反(良好)Microsoft命名约定,并不打算用于永久性t $。



-SA



By the way, never use auto-generated names like listBox1, always rename them to your semantically sensible names.
The names like "listBox1" violate (good) Microsoft naming conventions and are not intended to be used permanently.

—SA


这篇关于我有这个代码的一些问题,我找不到它错在哪里...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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