以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何将代码转换为内部函数,【已解决】  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89454)

--  作者:188802386
--  发布时间:2016/8/22 14:49:00
--  [求助]如何将代码转换为内部函数,【已解决】
请问如何将以下代码转换成内部函数并如何提取
\'获取外网IP地址
Dim WinHttpReq As Object = CreateObject("Msxml2.ServerXMLHTTP")
WinHttpReq.Open("GET", "http://1212.ip138.com/ic.asp")
WinHttpReq.Send
\'正则表达式解析出外网IP
Dim str As String = WinHttpReq.ResponseText
Dim mc = System.Text.RegularExpressions.Regex.Matches(str, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
If mc.count > 0 Then
    msgbox(mc(0).value)
End If
[此贴子已经被作者于2016/8/22 16:53:59编辑过]

--  作者:大红袍
--  发布时间:2016/8/22 14:53:00
--  

If mc.count > 0 Then
    return mc(0).value

Else

    return nothing
End If


--  作者:188802386
--  发布时间:2016/8/22 15:02:00
--  
大红袍老师,我是想把以上代码放在内部函数里面,取名“获取外部ip”,但代码要作调整,不知道怎么改。


--  作者:大红袍
--  发布时间:2016/8/22 15:08:00
--  
dim str As String = functions.Execute("获取外部ip")
[此贴子已经被作者于2016/8/22 15:08:26编辑过]

--  作者:188802386
--  发布时间:2016/8/22 16:36:00
--  
内部函数“获取外部IP”
Dim WinHttpReq As Object = CreateObject("Msxml2.ServerXMLHTTP")
WinHttpReq.Open("GET", "http://1212.ip138.com/ic.asp")
WinHttpReq.Send
\'正则表达式解析出外网IP
Dim str As String = WinHttpReq.ResponseText
Dim mc = System.Text.RegularExpressions.Regex.Matches(str, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
\'命令窗口
Dim str As String = functions.Execute("获取外部ip")
msgbox(str)
执行结果为空白,请问问题出现在那点呢

--  作者:大红袍
--  发布时间:2016/8/22 16:44:00
--  
内部函数“获取外部IP”
Dim WinHttpReq As Object = CreateObject("Msxml2.ServerXMLHTTP")
WinHttpReq.Open("GET", "http://1212.ip138.com/ic.asp")
WinHttpReq.Send
\'正则表达式解析出外网IP
Dim str As String = WinHttpReq.ResponseText
Dim mc = System.Text.RegularExpressions.Regex.Matches(str, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")

If mc.count > 0 Then
    return mc(0).value

Else

    return nothing
End If


--  作者:188802386
--  发布时间:2016/8/22 16:54:00
--  
终于搞懂了,谢谢