首页 > 开发 > 综合 > 正文

用VB实现来电显示的源代码(部份)

2024-07-21 02:25:41
字体:
来源:转载
供稿:网友
 

下面的代码是我上次给一个上公司

做管理信息系统时用来实现来电显示的源代码。

发到这里时只删了一些没有用的东西

大家就凑合着看吧

有兴趣的话可以发信到[email protected]和我交流

我是菜鸟

option explicit
const debflg = 1

public comx, beepno, hangup, pnloc as integer

public combuf, comlin as string
dim h

private sub command1_click()
   
    frmwelcome.visible = false
   
end sub


private sub option1_click(index as integer)

    comx = index + 1

    call init_modem

end sub

private sub form_load()


    '电话号码置空
    phonenumber = ""   '用来存放从猫中的电话号码
    getnumber = ""       '存放去掉区号后的号码
    
    
    with mscomm1
    .inbuffersize = 1024
    .inputlen = 0
    .inputmode = 0
    .rthreshold = 1
    .rtsenable = true
    .settings = "9600,n,8,1"
    .sthreshold = 0
    end with
   
  

'检测串行口

    dim i, c as integer

    comx = 0

    combuf = ""

    comlin = ""

    beepno = 0

    hangup = 0

    on error goto error_form_load

'检测可用串口

    for c = 1 to 4

        if mscomm1.portopen then mscomm1.portopen = false
   

        mscomm1.commport = c

        if not mscomm1.portopen then
   
             mscomm1.portopen = true
        end if

        if mscomm1.portopen then mscomm1.portopen = false
   

        if comx = 0 then comx = c
   

form_load_1:

    next c

    if comx = 0 then end

    on error goto 0

    option1(comx - 1).value = true

exit sub

error_form_load:

    option1(c - 1).enabled = false

    resume form_load_1
    exit sub
   

exit sub
why:
msgbox err.description
end sub

'检测串行口


'检查modem命令是否完成

private sub chk_modem()
on error goto why

dim t as single

dim l as integer

t = timer

do

    combuf = combuf + mscomm1.input

    l = instr(1, combuf, "ok")

loop until l <> 0 or timer - t > 1

    if l = 0 then
  
        msgbox "端口" & comx & "上没有发现modem,请选择别的端口试试.", vbokonly + vbcritical, "测试modem"

    else
        msgbox "来电显示已经启动,确定此按钮后,如果返回ok,说明计算机与modem能正常通信,否则,请重试其它端口"

    end if
exit sub
why: msgbox err.description
end sub

'串行口接收事件处理
private sub mscomm1_oncomm()
    dim a
    dim b
    on error goto why
    dim instrdata as string, tm as string
    dim ipos as integer
    instrdata = mscomm1.input & mscomm1.input
    ipos = instr(instrdata, "nmbr=")
    '记录程序是否第一次打开,不是话下次就不显示猫的返回信息
    
     if timeopen = 0 then
         msgbox instrdata
         timeopen = 54 '写成什么都可以,但0不可以,
         msgbox "恭喜!来电显示和modem都已经成功设置." '成功了,哈哈,我有钱可以赚了
         frmwelcome.visible = false
         command2.visible = false
     end if
    a = instr(1, instrdata, "nmbr = ", vbtextcompare)
    if a <> 0 then
        b = instr(a, instrdata, vbcr, vbtextcompare)
        phonenumber = mid(instrdata, a + 7, b - a - 7)
        frmreg.show
    else:
    end if
  exit sub
why:
 msgbox err.description
end sub

private sub init_modem()
on error goto why

    if mscomm1.portopen then mscomm1.portopen = false

    mscomm1.commport = comx

    if not mscomm1.portopen then mscomm1.portopen = true

    mscomm1.output = "at+vcid=1" + vbcr

    '检查modem命令是否完成

    call chk_modem

    mscomm1.output = "ats0=0" + vbcr
    exit sub
why:
msgbox err.description

end sub

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表