首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在向特定列中的行中的每个值发送sms时使用数据集。VB6

如何在向特定列中的行中的每个值发送sms时使用数据集。VB6
EN

Stack Overflow用户
提问于 2017-06-21 10:34:50
回答 1查看 116关注 0票数 0

我是Vb6的新手。我只想知道如何使用我的sms代码来发送特定列中行中的所有数字。在这段代码中,我收到的消息比我想要接收的要多。请帮我修一下我的循环法。

代码语言:javascript
复制
Dim x As String
Dim e As Integer
Dim allcontacts As String

For i = 0 To DataGrid1.VisibleRows
    For e = 0 To DataGrid1.ApproxCount - 1

    allcontacts = DataGrid1.Columns(5).CellValue(DataGrid1.GetBookmark(e))


    ' Send an 'AT' command to the phone
    MSComm1.Output = "AT" & vbCrLf
    Sleep 500
    MSComm1.Output = "AT+CMGF=1" & vbCrLf     'This line can be removed if your modem will always be in Text Mode...
    Sleep 500
    MSComm1.Output = "AT+CMGS=" & Chr(34) & allcontacts & Chr(34) & vbCrLf   'Replace this with your mobile Phone's No.
    Sleep 1000
    MSComm1.Output = "From School Activities Management System: " & vbCrLf & vbCrLf & "The time now is " & Label3.Caption & vbCrLf & vbCrLf & "Announcement:" & vbCrLf & Text1.Text & Chr(26)
    Sleep 2000


    Next e
Next i

x = DataGrid1.VisibleRows
MsgBox "Message Sent to " + x + " contacts in faculty."
End Sub

下面是这个数据集的截图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-21 12:42:14

根据你的截图,看起来你想为每一行发送一条短信。因此,我将尝试以下代码:

代码语言:javascript
复制
   Dim i As Integer
   Dim allcontacts As String

   For i = 0 To DataGrid1.VisibleRows - 1
      allcontacts = DataGrid1.Columns(5).CellValue(DataGrid1.GetBookmark(i))

      ' Send an 'AT' command to the phone
      MSComm1.Output = "AT" & vbCrLf
      Sleep 500
      MSComm1.Output = "AT+CMGF=1" & vbCrLf     'This line can be removed if your modem will always be in Text Mode...
      Sleep 500
      MSComm1.Output = "AT+CMGS=" & Chr(34) & allcontacts & Chr(34) & vbCrLf   'Replace this with your mobile Phone's No.
      Sleep 1000
      MSComm1.Output = "From School Activities Management System: " & vbCrLf & vbCrLf & "The time now is " & Label3.Caption & vbCrLf & vbCrLf & "Announcement:" & vbCrLf & Text1.Text & Chr(26)
      Sleep 2000
   Next i

   MsgBox "Message Sent to " & DataGrid1.VisibleRows & " contacts in faculty."

要记住的一件事是,消息只发送给屏幕上可见的行。如果它们从屏幕上滚动,无法被看到,那么就不会发送任何消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44673696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档