2012-12-04 79 views
-1

我的圖形用戶界面和程序工作正常,但並不像預期的那樣,所以請聽我說。AutoIT GUI和文本輸出

我寫了這個程序,以1-10個例子詞的形式爲用戶輸入3個類別。

它的目的是輸出每個三元組排列的文本文件。

不幸的是,它輸出的不是黑社會的排列。

這不是很多代碼,爲什麼會發生這種情況?

ex。

GUI:

顏色數量的希臘字母

紅一阿爾法 藍兩個β

輸出:

紅色阿爾法 紅一個β 紅二阿爾法 紅兩beta blue one alpha blue one beta blue兩個alpha 藍色兩個測試版

//////////////////// ////////////////////////////////////////////

#include <GUIConstantsEx.au3> 

$windowWidth = 600 
$windowHeight = 430 

$textFieldVertSpacing = 30 

GUICreate("Semantic Intuition/Idea Naming Tool", $windowWidth, $windowHeight) 

GUISetBkColor (0xB0E2FF) 

GUICtrlCreateLabel("Category A", 80, 10) 
GUICtrlCreateLabel("Category B", 260, 10) 
GUICtrlCreateLabel("Category C", 450, 10) 

$categoryA = GUICtrlCreateInput("", (150*0)+(150/4)*1, 40, 150) 
$categoryB = GUICtrlCreateInput("", (150*1)+(150/4)*2, 40) 
$categoryC = GUICtrlCreateInput("", (150*2)+(150/4)*3, 40) 

$example0 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80) 
$example1 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*1) 
$example2 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*2) 
$example3 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*3) 
$example4 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*4) 
$example5 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*5) 
$example6 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*6) 
$example7 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*7) 
$example8 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*8) 
$example9 = GUICtrlCreateInput("", (150*0)+(150/4)*1, 80+$textFieldVertSpacing*9) 

$example10 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80) 
$example11 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*1) 
$example12 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*2) 
$example13 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*3) 
$example14 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*4) 
$example15 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*5) 
$example16 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*6) 
$example17 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*7) 
$example18 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*8) 
$example19 = GUICtrlCreateInput("", (150*1)+(150/4)*2, 80+$textFieldVertSpacing*9) 

$example20 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80) 
$example21 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*1) 
$example22 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*2) 
$example23 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*3) 
$example24 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*4) 
$example25 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*5) 
$example26 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*6) 
$example27 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*7) 
$example28 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*8) 
$example29 = GUICtrlCreateInput("", (150*2)+(150/4)*3, 80+$textFieldVertSpacing*9) 

$generateTriadButton = GUICtrlCreateButton("Generate", ($windowWidth-100)/2, $windowHeight-40, 100) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

Global $examplesA[10] = [$example0, $example1, $example2, $example3, $example4, $example5, $example6, $example7, $example8, $example9] 
Global $examplesB[10] = [$example10, $example11, $example12, $example13, $example14, $example15, $example16, $example17, $example18, $example19] 
Global $examplesC[10] = [$example20, $example21, $example22, $example22, $example24, $example25, $example26, $example27, $example28, $example29] 

GUISetState(@SW_SHOW)      


While 1 

    Switch GUIGetMsg() 
     Case $GUI_EVENT_CLOSE 
      Exit 
     Case $generateTriadButton 
      permutate() 

      Exit 
    EndSwitch 

WEnd 

Func permutate() 

    $a = 0 
    $b = 0 
    $c = 0 
    $x = 1 

    $empty = "" 

    $output = FileOpen(@ScriptDir & "\TriadOutput.txt", 2) 

    While $a < 10 
     while $b < 10 
      while $c < 10 


       ;MsgBox(0, "String length is:", StringLen($examplesA[$a])) 
       If (StringStripWS(GUICtrlRead($examplesA[$a]), 8) <> "") AND (StringStripWS(GUICtrlRead($examplesB[$b]), 8) <> "") AND (StringStripWS(GUICtrlRead($examplesA[$a]), 8) <> "") Then 

       FileWrite($output, $x) 
       FileWrite($output, ")") 
       FileWrite($output, " ") 
       FileWrite($output, GUICtrlRead($examplesA[$a])) 
       FileWrite($output, " ") 
       FileWrite($output, GUICtrlRead($examplesB[$b])) 
       FileWrite($output, " ") 
       FileWrite($output, GUICtrlRead($examplesC[$c])) 
       FileWrite($output, " ") 
       FileWrite($output, @CRLF) 

       $x = $x + 1 

       EndIf 

      $c = $c + 1 
      WEnd 
      $c = 0 
      $b = $b + 1 
     WEnd 
     $b = 0 
     $a = $a + 1 
    WEnd 

    FileClose($output) 
EndFunc 

回答

1

典型的複製粘貼錯誤。

只需更換第二$一個在最後if語句(線94)以$ c和它的作品如預期...

您通過驗證輸出發現這一點。問題是,每三個文本字段都會被考慮在內,但其他兩個字都可以正常工作。所以錯誤必須在表達式(條件)中負責第三個字段。這只是在94行...

+1

哦,你可以簡化你的大部分代碼。例如,編寫一個函數,該函數只用兩個參數即行和列計數創建一個GUICtrlCreateInput。然後使用兩個for循環來調用它們中的每一個,將結果放入一個輸入數組中。 你應該使用「&」來連接你的輸出的兩個字符串到你的文件中,所以你只需要一個函數調用FileWrite就像($ output,$ x&「)」&GUICtrl ....) – Samoth