2017-01-24 8 views
2

私はちょうどAHKを使い始めています。4列、スペースとタブ区切り文字、および未知数の行からなるテキストファイルの読み方を教えています。配列から項目を返すのに問題がある

文字列 "xcal"を含む行の最初のトークンを取得し、その最初のトークン(%A_Index%= 1、右?)を配列(RunNum)に格納しようとしています。 MsgBoxに表示されます。あなたの説明に基づいて、このデータを使用して

#SingleInstance, Force 

RunNum := Object() ; Initialize temporary array 

; ----------------- Read LIST.TAB. --------------------------- 

IfNotExist, %A_ScriptDir%\LIST.TAB 
{ 
    MsgBox,48,Error!, LIST.TAB was not found. 
     ExitApp 
} 
else 
{ 
    RunCount = 1 ; Set Run counter 
    Loop, read, %A_ScriptDir%\list.tab ; Read config file 
    { 
     IfInString, A_LoopReadLine, xcal ; If current line contains the word 'xcal'... 
     { 
      Loop, Parse, A_LoopReadLine, %A_Space% %A_Tab% ; Parse through current line of config file, space and tab delimiter 
      { 
       if (%A_Index% = 1) ; Continue if at the first element/token of string 
       { 
       RunNum[RunCount] := A_LoopField ; Store current field in RunNum array 
       RunCount+=1 ; Increase counter   
       } 
      }    
     }           
    } 
MsgBox % RunNum[RunCount] 
} 
+1

右が 'です記号 –

+1

また、最も内側の '' if''が不足しているようですそれに続く2つの行の中括弧。 – wOxxOm

+0

%を削除すると何も変更されません。そして、私は中括弧をifループに追加するのを忘れていたに違いありませんが、実際のスクリプトの中にあります。 私は配列の値をどのように表示することができないのか、または配列が偶数の場合でも理解できませんか? – Glycoversi

答えて

1

1234 xcal RandomJunk 
4567 Nocal RandomJunk 
8910 xcal RandomJunk 

コード:

#SingleInstance, Force 

RunNum := [] ; No reason to use Object() 

; ----------------- Read LIST.TAB. --------------------------- 
If !(FileExist(A_ScriptDir "\list.tab")) { 
    MsgBox,48,Error!, LIST.TAB was not found. 
     ExitApp 
} else { 
    Loop, read, %A_ScriptDir%\list.tab ; Read config file 
    { 
     If (InStr(A_LoopReadLine, "xcal")) ; If current line contains the word 'xcal'... 
      RunNum.push(StrSplit(A_LoopReadLine, A_Space A_tab).1)    
    } 

For Each, Value in RunNum 
    YourNumbers .= Value "`n" 
MsgBox % YourNumbers 
} 

結果:A_Index = 1`なしパーセントの場合

1234 
8910 
+0

そうですよ!それはあまりにも合理化された方法です、Ahkcoderに感謝します! – Glycoversi

+0

問題はありません。うれしく思います!あなたが理解していないコマンド/機能に関するドキュメント(チュートリアルは優れています)を読んでください。それはすべてそこにあります!また、練習、練習、練習! – errorseven

+0

"InStr"関数インデックスページの ".1"への参照を見つけることができません。それは単に配列の最初の要素から開始することを意味しますか? – Glycoversi

関連する問題