用户登陆 用户注册
您的位置:首页> 电脑专栏>内容正文
PowerBuilder获取ADSL Modem的IP地址
[正文]:首先,建一个批处理文件,命名为getip.bat,保存到c盘根目录下。
   包含如下内容:    @echo off    ipconfig >> c:\ip.txt    然后,在pb中新建一个项目和一个窗口。
   窗口包含如下内容:    一个单行编辑框控件(singleeditcontrol),用于显示ip地址。
命名为:sle_ip   一个命令按钮控件(commandbutton):命令名:cb_getip   在命令按钮控件的单击(clicked)事件中输入如下内容:   integer fb   fb=fileopen("c:\ip.txt",streammode!,write!)    fileclose(fb)                                    //上面三行实际上多余,但没办法,不用fileopen函数新建一个文件,程序就打不开由getip.bat生成的ip.txt文件。
应该是pb10.0的bug。
   run("c:\getip.bat",minimized!)        //pb10.0的bug,如果程序运行时无法获取ip,就把minimized!参数去掉   do until filelength("c:\ip.txt")>5    //大于5没多大意义,主要检测ip.txt文件不为空。
   sle_ip.text="正在获取ip地址"    yield()    loop    int fileoperation                      fileoperation=fileopen("c:\ip.txt",streammode!) //ip.txt文件没多少内容,一次性按流模式读取到内存。
   string readfile    fileread(fileoperation,readfile)    string ip_a   string ip_b   int stringlen   string now_ip   ip_a=mid(readfile,lastpos(readfile,"ip address. . . . . . . . . . . . :"))   ip_b=mid(ip_a,lastpos(ip_a,"subnet mask . . . . . . . . . . . :"))   stringlen=len(ip_a) - len(ip_b) - 36  //获取ip地址长度    now_ip=righttrim(mid(ip_a,37,stringlen))    fileclose(fileoperation)    sle_ip.text=now_ip   filedelete("c:\ip.txt")


网站首页 培训课程 维修指南
技术文章 家电专栏 供应信息
求购信息 培训资讯 展会信息
电脑专栏 教程下载 资料下载
常用软件 PLC教程 PLC资料
变频伺服 低压电器 维修资料
人机界面 自控仪表 工控机类
文章标题: 搜文章
中国工控资源网手机版 2012
电话:010-67577139 13811659603
培训咨询QQ:657167934 471895637 销售咨询QQ:623769457
联系邮箱:zggkzyw@163.com
 京ICP备11002135号
报时(2026-04-02 12:07:50) 流量统计