nmgwddj 发表于 2009-10-16 02:35:38

如何得到Func字段里的值

Func kahao()
         $Val = Random ( 1, 10, 1 );1:行数的最小值,2:行数的最大值,1:设为1则返回整数
      $kahao = FileReadLine ( "data.ini" , $Val )
EndFunc
上边命令是读取data.ini里边的数据。 data.ini数据如下。
0078571023
0078558650
0078558581
0078550241
0078549468
0078551771
0078558565
0078557337
0078553524
0078551796

然后 我用下边代码来获取kahao()的值 为什么显示是0?

$shuru=kahao()
MsgBox(4096, "Test", $shuru , 10)

请高手赐教!

newx 发表于 2009-10-16 02:57:24

data.ini
0078571023
0078558650
0078558581
0078550241
0078549468
0078551771
0078558565
0078557337
0078553524
0078551796
GetVal.au3
$vfile = "data.ini"
$nRandomLine = Random(1,nReadLine($vfile)-1,1);注:nReadLine($vfile)-1,取INI文件的总行数,如果在最后一行是回车符则减1,没有回车符则不需减1
MsgBox(0,"第"&$nRandomLine&"的内容是",FileReadLine($vfile,$nRandomLine))

Func nReadLine($Val)
   $file = FileOpen($Val, 0)
   $xTemVal=0
   While 1
      $line = FileReadLine($file)
      $xTemVal = $xTemVal + 1
      If @error = -1 Then ExitLoop
   Wend
   FileClose($Val)
   return $xTemVal
EndFunc

newx 发表于 2009-10-16 03:06:24

楼主的:
Func kahao()
         $Val = Random ( 1, 10, 1 );1:行数的最小值,2:行数的最大值,1:设为1则返回整数
      $kahao = FileReadLine ( "data.ini" , $Val )
         return $kahao
EndFunc
页: [1]
查看完整版本: 如何得到Func字段里的值