[已解决]老是提示"If"声明没有与之匹配的"EndIf".
本帖最后由 waxy 于 2010-4-15 16:17 编辑前几天在“源码作品”区看到“非典男人”发的一个原创贴-----给AU3程序加个使用期限觉得挺好的,于是我把三恨兄弟写的一段代码代进去一运行
,就是提示无匹配的"EndIf",代码如下(说明一下我是菜鸟,刚学AU3,请各位多指点-,谢了)----
$Y = @YEAR; "年"
$M = @MON ; "月"
$D = @MDAY ;天属本月的第几天,值的范围是 01 到 31
$Now = $Y & $M & $D ;当前日期 格式例如 20100129
$Birth = "20100129" ;指定程序出生日期 格式例如 20100129
$Death = "20100630" ;指定程序死亡日期 格式例如 20121001
If Number($Now) <= $Birth Or Number($Now) >= $Death Then;如果程序运行的日期超过了设定的日期 则不能运行
MsgBox(0, "警告", "程序死亡!!")
Exit
Else
#include <GUIConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
_Singleton("Hardware_info")
Global $hGui,$bios,$board,$cpu,$display,$sound,$network,$mem,$os
SplashImageOn("logo","Splash.jpg",425,200,-1,-1,1)
$hGui=GUICreate (" 硬件信息查看器",450,400,-1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_hGuiMsg")
GUICtrlCreateGroup ("信息选项", 10, 10, 430, 360)
GUICtrlCreateButton("CPU",25,40,80,30)
$cpu=GUICtrlCreateInput("",120,40,270,30,$ES_READONLY)
GUICtrlCreateButton("B I O S",25,80,80,30)
$bios=GUICtrlCreateInput("",120,80,270,30,$ES_READONLY)
GUICtrlCreateButton("主 板",25,120,80,30)
$board=GUICtrlCreateInput("",120,120,270,30,$ES_READONLY)
GUICtrlCreateButton("显 卡",25,160,80,30)
$display=GUICtrlCreateInput("",120,160,270,30,$ES_READONLY)
GUICtrlCreateButton("声 卡",25,200,80,30)
$sound=GUICtrlCreateInput("",120,200,270,30,$ES_READONLY)
GUICtrlCreateButton("网 卡",25,240,80,30)
$network=GUICtrlCreateInput("",120,240,270,30,$ES_READONLY)
GUICtrlCreateButton("内 存",25,280,80,30)
$mem=GUICtrlCreateInput("",120,280,270,30,$ES_READONLY)
GUICtrlCreateButton("操作系统",25,320,80,30)
$os=GUICtrlCreateInput("",120,320,270,30,$ES_AUTOHSCROLL+$ES_READONLY)
GUICtrlCreateGroup ("",-99,-99,1,1)
GUICtrlCreateLabel("Autoit 中文论坛 www.autoitx.com 倾情奉献",15,370,300,30)
GUICtrlCreateLabel("Make By Sanhen",350,370,100,30)
GUISetState()
info()
SplashOff()
While 1
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', @AutoItPID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)
DllCall("kernel32.dll" , 'int', 'CloseHandle', 'int', $ai_Handle)
Sleep(1000)
Wend
Func _hGuiMsg()
Switch @GUI_CTRLID
Case$GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
guisetstate(@SW_MINIMIZE)
Case $GUI_EVENT_RESTORE
guisetstate(@SW_RESTORE)
EndSwitch
EndFunc;==>_hGuiMsg()
Func info()
Global $objWMIService,$colBios,$colBoard,$colSettings,$colMemory,$colCPU,$colVideoinfo,$colSound ,$colNIC
Local $object,$objOperatingSystem
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colBios = $objWMIService.ExecQuery("Select * from Win32_BIOS")
$colBoard = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard")
$colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
$colCPU = $objWMIService.ExecQuery("Select * from CIM_Processor")
$colVideoinfo = $objWMIService.ExecQuery("Select * from Win32_VideoController")
$colSound = $objWMIService.ExecQuery("Select * from Win32_SoundDevice")
$colNIC = $objWMIservice.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
For $object in $colCPU
GUICtrlSetData($cpu, StringStripWS($object.Name,1))
Next
For $object in $colBios
GUICtrlSetData($bios,StringMid($object.Caption,1))
Next
For $object in $colBoard
GUICtrlSetData($board,$object.Product)
Next
For $object in $colVideoinfo
GUICtrlSetData($display, StringStripWS($object.Description ,1))
Next
For $object in $colSound
GUICtrlSetData($sound, StringStripWS($object.Description ,1))
Next
For $object in $colNIC
GUICtrlSetData($network, StringStripWS($object.name ,1))
Next
For $objOperatingSystem in $colSettings
GUICtrlSetData($os,$objOperatingSystem.Caption & " Build " & $objOperatingSystem.BuildNumber & " Sp " & $objOperatingSystem.ServicePackMajorVersion & "." & $objOperatingSystem.ServicePackMinorVersion )
Next
for $objectin $colMemory
GUICtrlSetData($mem,String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " Mb")
Next
EndFunc;==>Info()
endif 检查 if 和 endif 的数量 把最后那个end if替换到上面的else If Number($Now) <= $Birth Or Number($Now) >= $Death Then;如果程序运行的日期超过了设定的日期 则不能运行
MsgBox(0, "警告", "程序死亡!!")
Exit
Else
EndIf 哈,我以前也和你有过相同的困惑。
大概的意思如下,慢慢理解吧。$Y = @YEAR; "年"
$M = @MON ; "月"
$D = @MDAY ;天属本月的第几天,值的范围是 01 到 31
$Now = $Y & $M & $D ;当前日期 格式例如 20100129
$Birth = "20100129" ;指定程序出生日期 格式例如 20100129
$Death = "20100129" ;指定程序死亡日期 格式例如 20121001
If Number($Now) <= $Birth Or Number($Now) >= $Death Then;如果程序运行的日期超过了设定的日期 则不能运行
notepad()
Exit
Else
calc()
EndIf
Func notepad()
Run("notepad.exe")
EndFunc
Func calc()
Run("calc.exe")
EndFunc 网络原因,咋刷新一下就变成回复2遍? 按上面的几个兄弟的提示试了一下,好像都不行哦。
EndFunc
Exit
EndIf
;这是什么意思????
研究了很长时间也不知道问题到底出在哪,把“ENDIF”放在不同位置都不行。 $Y = @YEAR; "年"
$M = @MON ; "月"
$D = @MDAY ;天属本月的第几天,值的范围是 01 到 31
$Now = $Y & $M & $D ;当前日期 格式例如 20100129
$Birth = "20100131" ;指定程序出生日期 格式例如 20100129
$Death = "20100630" ;指定程序死亡日期 格式例如 20121001
If Number($Now) <= $Birth Or Number($Now) >= $Death Then;如果程序运行的日期超过了设定的日期 则不能运行
MsgBox(0, "警告", "程序死亡!!")
Exit
EndIf
#include <GUIConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
_Singleton("Hardware_info")
Global $hGui, $bios, $board, $cpu, $display, $sound, $network, $mem, $os
SplashImageOn("logo", "Splash.jpg", 425, 200, -1, -1, 1)
$hGui = GUICreate(" 硬件信息查看器", 450, 400, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_hGuiMsg")
GUICtrlCreateGroup("信息选项", 10, 10, 430, 360)
GUICtrlCreateButton("CPU", 25, 40, 80, 30)
$cpu = GUICtrlCreateInput("", 120, 40, 270, 30, $ES_READONLY)
GUICtrlCreateButton("B I O S", 25, 80, 80, 30)
$bios = GUICtrlCreateInput("", 120, 80, 270, 30, $ES_READONLY)
GUICtrlCreateButton("主 板", 25, 120, 80, 30)
$board = GUICtrlCreateInput("", 120, 120, 270, 30, $ES_READONLY)
GUICtrlCreateButton("显 卡", 25, 160, 80, 30)
$display = GUICtrlCreateInput("", 120, 160, 270, 30, $ES_READONLY)
GUICtrlCreateButton("声 卡", 25, 200, 80, 30)
$sound = GUICtrlCreateInput("", 120, 200, 270, 30, $ES_READONLY)
GUICtrlCreateButton("网 卡", 25, 240, 80, 30)
$network = GUICtrlCreateInput("", 120, 240, 270, 30, $ES_READONLY)
GUICtrlCreateButton("内 存", 25, 280, 80, 30)
$mem = GUICtrlCreateInput("", 120, 280, 270, 30, $ES_READONLY)
GUICtrlCreateButton("操作系统", 25, 320, 80, 30)
$os = GUICtrlCreateInput("", 120, 320, 270, 30, $ES_AUTOHSCROLL + $ES_READONLY)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("Autoit 中文论坛 www.autoitx.com 倾情奉献", 15, 370, 300, 30)
GUICtrlCreateLabel("Make By Sanhen", 350, 370, 100, 30)
GUISetState()
info()
SplashOff()
While 1
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', @AutoItPID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)
DllCall("kernel32.dll", 'int', 'CloseHandle', 'int', $ai_Handle)
Sleep(1000)
WEnd
Func _hGuiMsg()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_MINIMIZE)
Case $GUI_EVENT_RESTORE
GUISetState(@SW_RESTORE)
EndSwitch
EndFunc ;==>_hGuiMsg
Func info()
Global $objWMIService, $colBios, $colBoard, $colSettings, $colMemory, $colCPU, $colVideoinfo, $colSound, $colNIC
Local $object, $objOperatingSystem
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colBios = $objWMIService.ExecQuery("Select * from Win32_BIOS")
$colBoard = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard")
$colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
$colCPU = $objWMIService.ExecQuery("Select * from CIM_Processor")
$colVideoinfo = $objWMIService.ExecQuery("Select * from Win32_VideoController")
$colSound = $objWMIService.ExecQuery("Select * from Win32_SoundDevice")
$colNIC = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
For $object In $colCPU
GUICtrlSetData($cpu, StringStripWS($object.Name, 1))
Next
For $object In $colBios
GUICtrlSetData($bios, StringMid($object.Caption, 1))
Next
For $object In $colBoard
GUICtrlSetData($board, $object.Product)
Next
For $object In $colVideoinfo
GUICtrlSetData($display, StringStripWS($object.Description, 1))
Next
For $object In $colSound
GUICtrlSetData($sound, StringStripWS($object.Description, 1))
Next
For $object In $colNIC
GUICtrlSetData($network, StringStripWS($object.name, 1))
Next
For $objOperatingSystem In $colSettings
GUICtrlSetData($os, $objOperatingSystem.Caption & " Build " & $objOperatingSystem.BuildNumber & " Sp " & $objOperatingSystem.ServicePackMajorVersion & "." & $objOperatingSystem.ServicePackMinorVersion)
Next
For $object In $colMemory
GUICtrlSetData($mem, String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " Mb")
Next
EndFunc ;==>info LZ的整个程序结构有问题
定义函数的语句怎么能放到If里面去
我都不知道该怎么解释, 只能说, LZ的编程的基本思想都还没有具备.
还是从基础看起吧. 学习了!!谢谢! 问题已解决,谢谢nmgwddj ,但不知道为何要删除“Else”。 回复 10# nmgwddj
问题已解决,谢谢nmgwddj ,但不知道为何要删除“Else”。 加上ELSE效果一样
这样如果结果为false则不会执行任何东西
页:
[1]
2