添加者:Ericwoo, 最后更新者: Ericwoo 于 二月 20, 2009 (查看变更)
原作者:hygougou http://topic.csdn.net/t/20050412/18/3930736.html
出于这样的考虑:connect using sqlca //如果远程数据库网络不通,这句语句将会耗费比较长的时间等待。所以考虑速度的问题,在连接之前现判断网络是否连通,如果连通则执行这句,不通则提示。
//声明全局变量global varstring password_,password_hcy=""long dw_addressdec dj[]Constant String ver_old="2K3.11(20)"//声明全局外部函数global ext funfunction ulong CreateMutexA (ulong lpMutexAttributes, int bInitialOwner, ref string lpName) library "kernel32.dll"function ulong GetLastError () library "kernel32.dll"Function long IcmpCreateFile() Library"icmp.dll"Function long IcmpCloseHandle(ulong IcmpHandle)Library"icmp.dll"Function long IcmpSendEcho(ulong IcmpHandle1,ulong DesAddress,string requestdata,long datasize,ulong requestoption,ref ICMP_ECHO_REPLY replybuffer,ulong Replysize,ulong timeout)Library"icmp.dll"function int ShellAboutA( ulong al_hWnd, string as_szApp, string as_szOtherStuff, ulong hIcon ) library "shell32"//声明结构1、type icmp_echo_reply from structureunsignedlongaddressunsignedlongstatusunsignedlongroundtriptimeunsignedlongdatasizeunsignedlongreservedunsignedlongdatapointericmp_optionsoptionsstringdata2、icmp_options from structurecharacterTtlcharacterToscharacterFlagscharacterOptionsSizecharacterOptionsData//函数,f_isipaddress /*---------------------- 功能:判断是否IP有效地址 传入:string f_p_address 返回:boolean ------------------------*/string a_s[16],as_1[4]int a_dot[3]int i,jj=1for i=1 to 16a_s[i]=mid(f_p_address,i,1)if a_s[i]="." thena_dot[j]=ij++end ifnextif j<>4 then return falseif a_dot[2]=a_dot[1]+1 or a_dot[3]=a_dot[2]+1 thenreturn falseend iffor i=1 to a_dot[1] - 1as_1[1]=as_1[1]+a_s[i]nextfor i=a_dot[1]+1 to a_dot[2] - 1as_1[2]=as_1[2]+a_s[i]nextfor i=a_dot[2]+1 to a_dot[3] - 1as_1[3]=as_1[3]+a_s[i]nextfor i=a_dot[3]+1 to 16as_1[4]=as_1[4]+a_s[i]nextfor i=1 to 4if long(as_1[i])>255 or long(as_1[i])<0 thenreturn falseexitend ifnextdw_address=long(as_1[4])*16777216+long(as_1[3])*65536+long(as_1[2])*256+long(as_1[1])return true--------------------------------------------------------------------------函数f_ping /*---------------------- 功能:pingIP有效地址 传入:string u_ipaddress 返回:无 ------------------------*/if f_isipaddress(u_ipaddress) thenelsesetprofilestring("ping.ini","properties","result","Ping Failure")end iflong l_hPortstring s_DataToSendlong l_iOptICMP_ECHO_REPLY echos_DataToSend="Send this characters"long strlenl_hport=0strlen=len(s_datatosend)l_hPort=IcmpCreateFile()long rtnrtn=0dw_address=long(u_ipaddress)rtn=IcmpSendEcho(l_hPort,dw_address,s_DataToSend,strlen,0,echo,56,200)if rtn=1 then//messagebox("Hello","Ping successful")setprofilestring("ping.ini","properties","result","Ping Successful")setprofilestring("ping.ini","properties","flag","1")elsesetprofilestring("ping.ini","properties","result","Ping Failure")setprofilestring("ping.ini","properties","flag","1")end iflong l_rtnl_rtn=IcmpCloseHandle(l_hPort)dw_address=0// 窗口实例子变量:int return_b// open事件 Timer(0.5)//Timer事件timer(0)idle(1)//SQLCA.DBMS = "O73 ORACLE 7.3"//SQLCA.LogPass = "zxcvbn"//SQLCA.ServerName = "@mybzk"//SQLCA.LogId = "bzk22"//SQLCA.AutoCommit = False//SQLCA.DBParm = "CommitOnDisconnect='NO'"label1:f_ping(STRING(f_ipaddressany('192.168.1.1')))if ProfileString("ping.INI", "properties", "Result","None")="Ping Successful" then //CONNECT USING SQLCA; //if sqlca.sqlcode<>0 then // messagebox("错误","能连通指定的IP地址,但远程服务器未提供数据服务~r~n"sqlca.sqlerrtext"~r~n~r~n远程服务器未启动或网络配置问题",StopSign!,RetryCancel!) // HALT close //else w_logo.height=1593 sle_1.setfocus() //end ifelsereturn_b=messagebox("错误","与中实运业IP地址通迅失败~r~n原因:①远程服务器关机~r~n>>>>>>②网络太忙,稍后再试~r~n>>>>>>③网络中断",StopSign!,RetryCancel!) choose case return_b case 1 goto label1 case 2 HALT close end chooseend if----屏蔽的代码是连接数据库的代码,自己适当修改
不过,确实漏了一函数,不过不是PING的函数f_ipaddressany// 传:string f_p_address// 返:longstring a_s[16],as_1[4]int a_dot[3]int i,jj=1for i=1 to 16a_s[i]=mid(f_p_address,i,1)if a_s[i]="." thena_dot[j]=ij++end ifnext//if j<>4 then return falseif a_dot[2]=a_dot[1]+1 or a_dot[3]=a_dot[2]+1 then//return falseend iffor i=1 to a_dot[1] - 1as_1[1]=as_1[1]+a_s[i]nextfor i=a_dot[1]+1 to a_dot[2] - 1as_1[2]=as_1[2]+a_s[i]nextfor i=a_dot[2]+1 to a_dot[3] - 1as_1[3]=as_1[3]+a_s[i]nextfor i=a_dot[3]+1 to 16as_1[4]=as_1[4]+a_s[i]nextfor i=1 to 4if long(as_1[i])>255 or long(as_1[i])<0 then//return falseexitend ifnextlong ll_returnll_return=long(as_1[4])*16777216+long(as_1[3])*65536+long(as_1[2])*256+long(as_1[1])return ll_return