求助:VB转VF的参数设置
试用了一个VB6的在短信猫上使用的控件Axalasunsms,连接和发送都没有问题,但读取不了短信。其中有一个读取短信的方法ReadMsg,其调用代码如下:
VB源码:
Private Sub Axalasunsms1_OnReceive(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Axalasunsms1.OnReceive
Dim sNo As String, sCon As String, sMsgCenterNo As String
Dim dSendTime As Date, lTimeZone As Integer
If Axalasunsms1.ReadMsg(sNo, sCon, sMsgCenterNo, dSendTime, lTimeZone) = 0 Then
txtReceive.Text = dSendTime & "收到来自" & sNo & "的短信,短信中心号:" & sMsgCenterNo & "内容:" & sCon
End If
End Sub
我试着将其转为VF的一个“收取短信”按钮:
LOCAL sNo As String, sCon As String, sMsgCenterNo As String &&短信来源号码,短信内容,短信中心号码
LOCAL dSendTime As Date, lTimeZone As Integer &&发送短信时间,发送短信时区
sNo=''
sCon=''
sMsgCenterNo=''
dSendTime=DATETIME()
lTimeZone=0
IF thisform.olecontrol1.readMsg(@sNo,@sCon , @sMsgCenterNo, @dSendTime, @lTimeZone) = 0
thisform.text1.Value=sNo+sCon
ELSE
thisform.text1.Value='no'
ENDIF
一运行就提示:OLE 错误码:0x80020005:type mismatch
因连接和发送使用的都是传值参数,接收使用的是传址参数,怀疑是参数设置的问题,请高手指教,谢谢。
另外,查阅以往的帖子,知道十豆三老师也是使用短信猫,不知使用的是DLL还是OCX,是VF还是其它?若是VF,能给个例程吗? 短信 vb 控件
[解决办法]
应该是这个参数的问题:dSendTime
你分别换成如下试:
日期型
字符型
再有,thisform.olecontrol1.readMsg( 这时候的智能提示你看一下每个参数类型。
[解决办法]
我使用的 sms.dll,不同的厂家的设备,接口也不一样,sml.dll 收短信的函数与你的不一样,相关代码:
'以下为 VB 代码:
'Sms_Receive函数说明如下:
'功能描述:接收指定类型的短信
'Sms_Type:短信类型(0:未读短信;1:已读短信;2:待发短信;3:已发短信;4:全部短信)
'Sms_Text:返回指定类型的短信内容字符串(短信内容字符串说明:短信与短信之前用"
[解决办法]
"符号作为分隔符,每条短信中间的各字段用"#"符号作为分隔符)
Public Declare Function Sms_Receive Lib "sms.dll" (ByVal Sms_Type As String, Sms_Text As String) As Long
Private Sub Sms_Receive_Button_Click()
Screen.MousePointer = vbHourglass
Sms_Receive_Button.Enabled = False
Dim ReceiveSmsStr As String
If Sms_Receive("4", ReceiveSmsStr) Then
ReceiveSms_Text.Text = ReceiveSmsStr
End If
Sms_Receive_Button.Enabled = True
VERSION 5.00
Begin VB.Form mainsms
BorderStyle = 1 'Fixed Single
Caption = "短信收发二次开发接口例程源码(VB版)"
ClientHeight = 6630
ClientLeft = 45
ClientTop = 330
ClientWidth = 9225
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6630
ScaleWidth = 9225
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox MobPort
Height = 330
Left = 1050
TabIndex = 24
Text = "0"
Top = 150
Width = 555
End
Begin VB.Frame Frame5
Caption = "自动接收短信"
Height = 1455
Left = 4200
TabIndex = 18
Top = 120
Width = 4845
'部分代码略
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "端口号:"
Height = 180
Left = 180
TabIndex = 23
Top = 240
Width = 720
End
End
Attribute VB_Name = "mainsms"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
Sms_Send_Button.Enabled = False
Sms_Receive_Button.Enabled = False
Sms_Delete_Button.Enabled = False
SendSms_Text.Enabled = False
TelNum_Text.Enabled = False
ReceiveSms_Text.Enabled = False
DeleteSms_Index.Enabled = False
Sms_Disconnection_Button.Enabled = False
Sms_Start_Button.Enabled = False
NewSms_Show.Caption = ""
NewSms_Show.Enabled = False
End Sub
Private Sub Sms_Delete_Button_Click()
Screen.MousePointer = vbHourglass
Sms_Delete_Button.Enabled = False
Sms_Delete (Trim(DeleteSms_Index.Text))
Sms_Delete_Button.Enabled = True
Screen.MousePointer = vbDefault
End Sub
Private Sub Sms_Exit_Button_Click()
Unload Me
End Sub
Private Sub Sms_Receive_Button_Click()
Screen.MousePointer = vbHourglass
Sms_Receive_Button.Enabled = False
Dim ReceiveSmsStr As String
If Sms_Receive("4", ReceiveSmsStr) Then
ReceiveSms_Text.Text = ReceiveSmsStr
End If
Sms_Receive_Button.Enabled = True
If Sms_AutoFlag() Then
If Sms_Start_Button.Enabled = True Then
NewSms_Show.Caption = "自动接收短信功能处于关闭状态"
Else
NewSms_Show.Caption = "未收到新短信"
End If
Else
NewSms_Show.Caption = "该短信猫不支持自动接收短信功能"
End If
Screen.MousePointer = vbDefault
End Sub
Private Sub Sms_Disconnection_Button_Click()
Screen.MousePointer = vbHourglass
Sms_Disconnection_Button.Enabled = False
Sms_Disconnection
Sms_Connection_Button.Enabled = True
Sms_Send_Button.Enabled = False
Sms_Receive_Button.Enabled = False
Sms_Delete_Button.Enabled = False
SendSms_Text.Enabled = False
TelNum_Text.Enabled = False
ReceiveSms_Text.Enabled = False
DeleteSms_Index.Enabled = False
Sms_Start_Button.Enabled = False
Sms_Close_Button.Enabled = False
State_Show.Caption = ""
NewSms_Show.Caption = ""
NewSms_Show.Enabled = False
NewSms_Timer.Enabled = False
Screen.MousePointer = vbDefault
End Sub
Private Sub Sms_Connection_Button_Click()
Load Me
Screen.MousePointer = vbHourglass
Sms_Connection_Button.Enabled = False
Dim TypeStr As String
Dim CopyRightToCOMStr As String
Dim CopyRightStr As String
CopyRightStr = "//深圳市国爵电子有限公司,网址www.gprscat.com //"
If Sms_Connection(CopyRightStr, CInt(MobPort.Text), 9600, TypeStr, CopyRightToCOMStr) Then '若使用诺基亚移动电话,请使用数据套件虚拟串口连接
State_Show.Caption = "连接短信猫成功" & Chr(10) & "(短信猫型号为:" & TypeStr & ")"
Sms_Send_Button.Enabled = True
Sms_Receive_Button.Enabled = True
Sms_Delete_Button.Enabled = True
SendSms_Text.Enabled = True
TelNum_Text.Enabled = True
ReceiveSms_Text.Enabled = True
DeleteSms_Index.Enabled = True
Sms_Disconnection_Button.Enabled = True
Sms_Start_Button.Enabled = True
NewSms_Show.Caption = "自动接收短信功能处于关闭状态"
NewSms_Show.Enabled = True
NewSms_Timer.Enabled = False
Else
State_Show.Caption = "连接短信猫失败" & Chr(10) & "(请重新连接短信猫)"
Sms_Connection_Button.Enabled = True
End If
Screen.MousePointer = vbDefault
End Sub
Private Sub Sms_Send_Button_Click()
Screen.MousePointer = vbHourglass
Sms_Send_Button.Enabled = False
If Len(Trim(TelNum_Text.Text)) >= 11 And Sms_Send(Trim(TelNum_Text.Text), Trim(SendSms_Text.Text)) Then
MsgBox "发送短信成功!", vbInformation, "提示"
Else
MsgBox "发送短信失败!", vbCritical, "警告"
End If
Sms_Send_Button.Enabled = True
Screen.MousePointer = vbDefault
End Sub
Private Sub Sms_Start_Button_Click()
If Sms_AutoFlag() Then
NewSms_Show.Caption = "未收到新短信"
Sms_Start_Button.Enabled = False
Sms_Close_Button.Enabled = True
NewSms_Timer.Enabled = True
Else
NewSms_Show.Caption = "该短信猫不支持自动接收短信功能"
End If
End Sub
Private Sub Sms_Close_Button_Click()
NewSms_Show.Caption = "自动接收短信功能处于关闭状态"
Sms_Start_Button.Enabled = True
NewSms_Timer.Enabled = False
Sms_Close_Button.Enabled = False
End Sub
Private Sub NewSms_Timer_Timer()
If Sms_NewFlag() Then
NewSms_Show.Caption = "收到新短信,请查收!"
End If
End Sub