本帖最后由 731106 于 2011-4-28 21:01 编辑
这段代码我怎么搞都不行,如果在代码所在目录导入EXCEL文件(或者不导入),代码就能正常运行,也能读取INI文件,但是如果导入代码所在目录以外EXCEL文件,就无法读取INI文件,到底问题出在哪啊?
INI文件内容:
[1111]
信息=00318300,11020201,01,000655
[2222]
信息=00319300,11020202,01,001432
[3333]
信息=00382300,11020203,01,000670
[4444]
信息=00309300,11020204,01,000670
[5555]
信息=00359300,11020205,01,000654
[6666]
信息=00316300,11020206,01,000669
代码如下:#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Excel.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
HotKeySet("`", "Terminate")
Func Terminate()
ProcessClose("EXCEL.exe")
Exit
EndFunc ;==>Terminate
TraySetIcon("1.ico", "")
$Form1 = GUICreate("Form1", 350, 200)
$Label1 = GUICtrlCreateLabel("请选择:", 70, 100, 85, 22)
GUICtrlSetFont(-1, 14, 400, 0, "黑体")
$Label2 = GUICtrlCreateLabel("请选择Excel文件:", 22, 16, 218, 22)
GUICtrlSetFont(-1, 14, 400, 0, "黑体")
$Input1 = GUICtrlCreateInput("", 22, 45, 297, 20)
$Button3 = GUICtrlCreateButton("浏 览", 240, 12, 70, 25, 0)
$Combo1 = GUICtrlCreateCombo("", 170, 95, 100, 25)
$Button1 = GUICtrlCreateButton("确 定", 50, 160, 75, 25)
$Button2 = GUICtrlCreateButton("退 出", 230, 160, 75, 25)
GUISetState(@SW_SHOW)
read()
Func read()
$var = IniReadSectionNames(@ScriptDir & '\123.ini')
If @error Then
MsgBox(1 + 4144, "Form1", "配置文件錯誤")
Exit
Else
For $i = 1 To $var[0]
GUICtrlSetData($Combo1, $var[$i])
Next
EndIf
EndFunc ;==>read
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ProcessClose("EXCEL.exe")
Exit
Case $Button3
$folder = FileOpenDialog("浏览", @MyDocumentsDir, "EXCEL 电子表格(*.xls)")
If Not @error Then
GUICtrlSetData($Input1, $folder)
$oExcel = _ExcelBookOpen($folder, 0)
Global Const $xlUp = -4162
$c = $oExcel.Sheets("Sheet1" ).Range("A65536" ).End($xlUp).Row
EndIf
Case $Button1
$bb = GUICtrlRead($Combo1)
$txt = IniRead("123.ini", $bb, "信息", "")
$array = StringSplit($txt, ",", 1)
GUISetState(@SW_HIDE, $Form1)
ExitLoop
Case $Button2
_ExcelBookClose($oExcel, 0)
Exit
EndSwitch
WEnd
MsgBox(0, "", "值是: " & @CRLF & $array[1])
MsgBox(0, "", "值是: " & @CRLF & $array[2])
MsgBox(0, "", "值是: " & @CRLF & $array[3])
MsgBox(0, "", "值是: " & @CRLF & $array[4])
|