dulein 发表于 2010-4-24 16:59:56

新手请教Func...Endfunc问题

本帖最后由 dulein 于 2010-4-24 17:02 编辑

新手刚入门,请教各位高手,如何定义func()参数及如何调用该方法,帮助文件没有具体说明.有个示例讲解更好...谢谢!

doshowyam 发表于 2010-4-24 17:01:12

过来看看再说吧

doshowyam 发表于 2010-4-24 17:02:27


#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("手机号归属地查询工具", 270, 270, 200, 120)
$Label1 = GUICtrlCreateLabel("手机号码", 20, 20, 80, 20)
$Input1 = GUICtrlCreateInput("在这里输入手机号", 90, 18, 170, 20,$ES_NUMBER)
$Button1 = GUICtrlCreateButton("确定查询", 10, 50, 250, 40, 0)
$Label2 = GUICtrlCreateLabel("归属地:", 10, 112, 84, 28)
$Label3 = GUICtrlCreateLabel("卡类型:", 10, 151, 74, 28)
$Label4 = GUICtrlCreateLabel("区 号:", 10, 192, 64, 28)
$Label5 = GUICtrlCreateLabel("邮 编:", 10, 227, 64, 28)
$Input2 = GUICtrlCreateInput("", 90, 105, 169, 32)
$Input3 = GUICtrlCreateInput("", 90, 147, 169, 32)
$Input4 = GUICtrlCreateInput("", 90, 190, 169, 32)
$Input5 = GUICtrlCreateInput("", 90, 227, 169, 32)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $telno = GUICtrlRead($Input1)
                        GUICtrlSetState($Button1,$gui_disable)
                        $telinfo = find138($telno)
                        GUICtrlSetState($Button1,$gui_enable)
                        If $telinfo Then
                                GUICtrlSetData($Input2,$telinfo)
                                GUICtrlSetData($Input3,$telinfo)
                                GUICtrlSetData($Input4,$telinfo)
                                GUICtrlSetData($Input5,$telinfo)
                        Else
                                Exit
                        EndIf
        EndSwitch
WEnd

Func find138($phn)       
        Local $telinfo = , $dt = 0
        $str = InetGet("http://www.ip138.com:8080/search.asp?action=mobile&mobile=" & $phn,@TempDir & "\data.tmp", 1, 1)
        Do
                Sleep(250)
                $dt += 1
                If $dt > 250 Then Return SetError(1,0,0)
        Until InetGetInfo($str, 2)
        InetClose($str)
        $str = FileRead(@TempDir & "\data.tmp")
        FileDelete(@TempDir & "\data.tmp")
        $phoNo = StringRegExp($str, '您查询的手机号码段</TD>(?s)(.[^>]*)>(.[^<]*)(.*)' & _
                        '卡号归属地</TD>(?s)(.[^>]*)>(.[^<]*)(.*)' & _
                        '卡&nbsp;类&nbsp;型</TD>(?s)(.[^>]*)>(.[^<]*)(.*)' & _
                        '区 号</TD>(?s)(.[^>]*)>(.[^<]*)(.*)' & _
                        '邮 编</TD>(?s)(.[^>]*)>(.[^<]*)', 3)
        If Not @error Then
                $telinfo = $phoNo
                $telinfo = StringReplace($phoNo,"&nbsp;"," ")
                $telinfo = $phoNo
                $telinfo = $phoNo
                $telinfo = $phoNo
                $telinfo = 5
        Else
                MsgBox(0, "出错!!", "查询错误!!" & @CRLF & "错误代码: " & @error)
        EndIf
        Return $telinfo
EndFunc   ;==>find138


l4ever 发表于 2010-4-24 17:27:02

本帖最后由 l4ever 于 2010-4-24 17:32 编辑

test("fuck");调用test

test2("16","标题","fuck");调用test

test3("测试","fuck")

test3("测试","fuck","64")


func test($a);定义test
msgbox(32,"",$a)
endfunc

func test2($a,$b,$c);定义test2,随便写都行.只要和调用的地方参数一样多就OK
msgbox($a,$b,$c)
endfunc

func test3($b,$c,$a=36);不一样也行,比如这样 ,如果只有2个参数,则$a =36
msgbox($a,$b,$c)
endfunc

lanfengc 发表于 2010-4-24 18:24:54

这2个关键字的含义是:func ***先定义函数名。函数名后的括号中可以带参数也可以不带参数。
如:func test() 和 func test($a,$b,$c……) 省略号代表的是参数可以任意加。

endfunc是函数结束关键字。 代表从func ***到 endfunc 之间的这段代码是一个子函数。

如上的
func test($a);定义test函数,test函数带参数$a。由于AU3调用函数参数不需要做明确的参数数据类型定义,所以,只需要写上一个参数名就可以了。
msgbox(32,"",$a);这里是调用msgbox函数弹出一个提示框。内容为$a。 这个$a是调用函数传递过来的参数。 (牵扯到编程中的形参与实参,可以自己找资料看。)
endfunc;函数结束。

函数定义了之后,调用的时候,只需要直接输入函数名(如果有参数则在后面加上参数即可。)就可以对相应函数进行调用运行。非常简单。test("这是我定义的一个函数。");调用test
func test($a);定义test
msgbox(32,"",$a)
endfunc

lynfr8 发表于 2010-4-24 21:38:07

这2个关键字的含义是:func ***先定义函数名。函数名后的括号中可以带参数也可以不带参数。
如:func t ...
lanfengc 发表于 2010-4-24 18:24 http://www.autoitx.com/images/common/back.gif
今天看到lanfengc 几个回帖质量都不错,热心助人!
谢谢

gavinlee 发表于 2010-4-24 21:41:34

学习了 想前辈致敬

lanfengc 发表于 2010-4-25 10:42:23

今天看到lanfengc 几个回帖质量都不错,热心助人!
谢谢
lynfr8 发表于 2010-4-24 21:38 http://autoitx.com/images/common/back.gif


    呵呵。今天搞定了一个程序,心情好,就发点有质量的帖子,给论坛增加点活力。 让您见笑了。

lchl0588 发表于 2010-4-25 13:55:00

呵呵,#5已说明Func.......EndFunc大致的用法,但有一点: Func.......EndFunc只能针对一个自定义函数来操作,比如:
Func aaa($a,$b,$c) ;这里只能定义一个函数,但不能同时定义多个函数哦,那($a,$b,$c)则无限制!!!
EndFunc
如果想多个,那就用多个Func.......EndFunc来操作

rikthhpgf2005 发表于 2010-4-25 16:56:57

帮助里那么多例子!!
页: [1]
查看完整版本: 新手请教Func...Endfunc问题