找回密码
 加入
搜索
查看: 5743|回复: 4

[AU3基础] 非数组变量使用下标,,已解决

[复制链接]
发表于 2012-3-22 01:05:17 | 显示全部楼层 |阅读模式
本帖最后由 vgy0dl 于 2012-3-22 01:29 编辑

Run(@ComSpec & " /C ipconfig >c:\windows\temp.txt",'',@SW_HIDE)
$txt="c:\windows\temp.txt"
FileOpen($txt,1)
$word=FileRead($txt)
$array=StringRegExp($word,'Default Gateway . . . . . . . . . : \h*([^\r]+)',1)
$a=$array[UBound($array[0])]
IniWrite(@TempDir&'\ipmac.ini','gateway','gateway',$a)
MsgBox(0,'',$a)

XP下运行没问题,2003下运行就提示了  非数组变量使用下标
请教下大虾。。。。帮我看看

评分

参与人数 1金钱 +15 收起 理由
afan + 15 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2012-3-22 01:28:32 | 显示全部楼层
Global $array
Run(@ComSpec & " /C ipconfig >c:\windows\temp.txt",@ScriptDir,@SW_HIDE)
$txt="c:\windows\temp.txt"
FileOpen($txt,1)
$word=FileRead($txt)
$array=StringRegExp($word,'Default Gateway . . . . . . . . . : \h*([^\r]+)',1)
$a=$array[UBound($array[0])]
IniWrite(@TempDir&'\ipmac.ini','gateway','gateway',$a)
MsgBox(0,'',$a)
发表于 2012-3-22 04:20:23 | 显示全部楼层
本帖最后由 Ycxw2008 于 2012-3-22 04:47 编辑

大概看了下可能因为系统区别,
所以导致还没运行完cmd就执行到fileread那一步了
;这个时候你的读取的文件还没有包含下面你想要匹配的
;所以把run改成
RunWait(@ComSpec & " /C ipconfig >c:\windows\temp.txt",'',@SW_HIDE)
然后直接这样就行了;
Local $Array=StringRegExp(FIleRead("c:\windows\temp.txt"),"Default Gateway . . . . . . . . . : \h*([^\r]+)",3)
这里的正则可以改成(?<=Default Gateway (?:.\s){9}:)([^\r\n]+)
最好再加个判断,
If @Error Then MsgBox(0,"","没匹配到")

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-3-22 11:45:36 | 显示全部楼层
回复 3# Ycxw2008


    谢谢你哈。。。。
发表于 2014-5-13 11:52:43 | 显示全部楼层
雷锋精神传天下!谢谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-7 15:59 , Processed in 0.085634 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表