一个VB短心平台,速要,急给分,高手门看看

kevin520bj 2008-03-26 05:56:31
Private Sub Command1_Click()

If txtServer.Text = "" Then
MsgBox ("请输入服务器IP地址!")
Exit Sub
End If

serverIP = txtServer.Text
Call Conn1_serverIP

If Jindi.IsOpen Then


Command1.Enabled = False
Label1.Caption = "正在运行" & vbCrLf & vbCrLf & Now()
Label1.Refresh

Timer1.Enabled = False

Dim SQL As String
On Error GoTo conn_error
Call Conn_Open
SQL = "select * from sms where status=0"
rs.Open SQL, conn, 3, 3
k = 0
Do While Not rs.EOF


If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1

Else
If k < 2 Then
If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1
k = 0
Else
k = k + 1
End If
Else
rs("status") = 2
rs("finish_time") = Now()
rs.Update
rs.MoveNext
j = j + 1
End If
End If

Label1.Caption = "正在运行 已成功发送" & i & "条短信" & vbCrLf & vbCrLf & Now()
Label1.Refresh
Sleep (1000)

Loop

Call Conn_Close

Label1.Caption = "正在运行 已成功发送" & i & "条短信"
If j <> 0 Then
Label1.Caption = Label1.Caption & "," & vbCrLf & vbCrLf & j & "条短信发送失败"
End If
Label1.Caption = Label1.Caption & vbCrLf & vbCrLf & Now()
Timer1.Enabled = True

Else
MsgBox "请先打开短信设备"
Exit Sub
End If

Exit Sub

conn_error:
MsgBox ("连接服务器失败,请检查IP地址!")
Command1.Enabled = True
End Sub

在以上代码中我要实现让他自动检测数据库表然后发送信息!哪里需要改进呢? 谢谢各位!
现在状况只能开启一次 检测一次 发送一次!
...全文
61 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zmrok 2008-03-28
你这个写得好乱,自动收发怎么写得那么麻烦?
建议你将发送短信并改变数据库的值写成一个函数,
刚好我做了一个自动接收的程序,可以给你一点参考
Private Sub FAutoRecive() '---------自动接收信息
If isBusy = True Then
MsgBox "设备繁忙..."
Exit Sub
End If
'-----------------------------------------------
StatusBar1.Panels(2).Text = "正在执行自动接收短信..."
setGrid1
Timer1.Interval = 6000
isBusy = True

End Sub
Private Sub Timer1_Timer()
On Error GoTo errbFRcive
' If isOK = False Then
' MsgBox "设备初始化失败。"
' Exit Sub
' End If
' If isBusy = True Then
' StatusBar1.Panels(2).Text = "设备处于繁忙状态..."
' Exit Sub
' End If
' isBusy = True
'-----------------------------------------获得一个随机UUID

'---------接收短信
FMsgRecive strUUID
'-----------------
Exit Sub
errbFRcive:
StatusBar1.Panels(2).Text = Err.Description
End Sub
回复
kevin520bj 2008-03-28
我就从新拖了一个Timer控件!
在事件里面写了command1_chick()事件里的东西!
回复
kevin520bj 2008-03-28
Private Sub Command1_Click()

If txtServer.Text = "" Then
MsgBox ("请输入服务器IP地址!")
Exit Sub
End If

serverIP = txtServer.Text
Call Conn1_serverIP

If Jindi.IsOpen Then


Command1.Enabled = False
Label1.Caption = "正在运行" & vbCrLf & vbCrLf & Now()
Label1.Refresh

Timer1.Enabled = False

Dim SQL As String
On Error GoTo conn_error
Call Conn_Open
SQL = "select * from sms where status=0"
rs.Open SQL, conn, 3, 3
k = 0
Do While Not rs.EOF


If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1

Else
If k < 2 Then
If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1
k = 0
Else
k = k + 1
End If
Else
rs("status") = 2
rs("finish_time") = Now()
rs.Update
rs.MoveNext
j = j + 1
End If
End If

Label1.Caption = "正在运行 已成功发送" & i & "条短信" & vbCrLf & vbCrLf & Now()
Label1.Refresh
Sleep (1000)

Loop

Call Conn_Close

Label1.Caption = "正在运行 已成功发送" & i & "条短信"
If j <> 0 Then
Label1.Caption = Label1.Caption & "," & vbCrLf & vbCrLf & j & "条短信发送失败"
End If
Label1.Caption = Label1.Caption & vbCrLf & vbCrLf & Now()
Timer1.Enabled = True

Else
MsgBox "请先打开短信设备"
Exit Sub
End If

Exit Sub

conn_error:
MsgBox ("连接服务器失败,请检查IP地址!")
Command1.Enabled = True
End Sub

Private Sub Timer2_timer()
If txtServer.Text = "" Then
MsgBox ("请输入服务器IP地址!")
Exit Sub
End If

serverIP = txtServer.Text
Call Conn1_serverIP

If Jindi.IsOpen Then


Command1.Enabled = False
Label1.Caption = "正在运行" & vbCrLf & vbCrLf & Now()
Label1.Refresh

Timer2.Enabled = False

Dim SQL As String
On Error GoTo conn_error
Call Conn_Open
SQL = "select * from sms where status=0"
rs.Open SQL, conn, 3, 3
k = 0
Do While Not rs.EOF


If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1

Else
If k < 2 Then
If Jindi.SendMsg(rs("to_number"), rs("content")) = 0 Then
rs("status") = 1
rs("finish_time") = Now()
rs.Update
rs.MoveNext
i = i + 1
k = 0
Else
k = k + 1
End If
Else
rs("status") = 2
rs("finish_time") = Now()
rs.Update
rs.MoveNext
j = j + 1
End If
End If

Label1.Caption = "正在运行 已成功发送" & i & "条短信" & vbCrLf & vbCrLf & Now()
Label1.Refresh
Sleep (1000)

Loop

Call Conn_Close

Label1.Caption = "正在运行 已成功发送" & i & "条短信"
If j <> 0 Then
Label1.Caption = Label1.Caption & "," & vbCrLf & vbCrLf & j & "条短信发送失败"
End If
Label1.Caption = Label1.Caption & vbCrLf & vbCrLf & Now()

Timer2.Interval = 1000 //补充的

Timer2.Enabled = True


Else
MsgBox "请先打开短信设备"
Exit Sub
End If

Exit Sub

conn_error:
MsgBox ("连接服务器失败,请检查IP地址!")
Command1.Enabled = True
End Sub


高手在看下!我这样改对吗? 谢谢啊 !我真的快疯了!
回复
zmrok 2008-03-28
你应该把command_click里的语句放到Timer1_Timer()事件里,再给Timer1的
timer1.Interval设成你想要的值
回复
zmrok 2008-03-28
这个不关设备的事情,是timer里的事件逻辑没有处理好
回复
DoemingRau 2008-03-27
更正一下
PUB SUB TIMER 'timer事件(我忘记了是什么,暂用这个代替)

strSql="select msg,phonenum from TBL_MSG ORDER BY msdSendTime "
con.open rs,strsql
if rs.eof=true and rs.bof=true then
else
发送短信
更新短信状态

endif
END SUB
回复
DoemingRau 2008-03-27
timer控件不是用来检测有多少条态为0的记录,而是只要查到有一条就立即调用SEND函数
PUB SUB TIMER 'timer事件(我忘记了是什么,暂时这么些)

strSql="select msg,phonenum from TBL_MSG ORDER BY msdSendTime "

con.open rs,strsql
if rs.eof=true and rs.bof=true then
else
发送短信
endif

‘更新短信状态
update()

END SUB
回复
kevin520bj 2008-03-27
timer控件有!但他是控制的查询一次有多少条状态为0的记录!
当第二次就不起作用了!代码中有!
您觉得这timer控件写的什么位置合适?
回复
DoemingRau 2008-03-27
我以前就是用金笛的短信控件帮公司做了一个短信群发的服务端,短信客户端控件,可惜的是我U盘被人偷了,
你应该放置一个TIME控件,每隔多少时间去检测数据库中状态为0的短信,然后发送出去,失败了,更新
下短信标志位,成功的话,更新一个标志位。
回复
shakoe 2008-03-27
你不会自己调试么。

别人设备都没怎么帮你分析
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-26 05:56
社区公告
暂无公告