2014-03-31 69 views
0

我目前正在編寫一個宏,它是我工作的標籤生成器,基本上它有一個組合框,並且在組合框中可以從1-4中選擇一個數字(讓我們爲以後調用此數字框參考),還有一些複選框和其他組合框用於選擇標籤選項。在宏中,我有一個存儲每個號碼箱所有信息的數組。每個數字框都有相同的選項可供選擇,但所選的選項可能不同。Excel數組值存儲

EXAMPLE: 

Numberbox: 1 
name label: yes 
last name label: no 
gender: yes 

Numberbox: 2 
name label: no 
last name label: yes 
gender: yes 

Numberbox: 4 
name label: no 
last name label: yes 
gender: no 

我已說的是,當用戶選擇在numberbox不同數量時,它調用其全部選定標籤存儲到一個數組的子程序。在這個子程序被調用並且所有的信息被存儲後,無論用戶在數字框中選擇了什麼號碼,它都會將這些信息提取出來並自動選擇用戶已經選擇的選項。

EXAMPLE: 

let's say i start fresh, no info submitted into array yet, i select: 

NUMBERBOX: 1 
name label: yes 
last name label: no 
gender: yes 
的選擇後

上述我進入numberbox和選擇號碼2中,所有的信息將被保存到所述陣列的第一ARRAYS1(1,等等等等等等)。那麼它會去查看數組ARRAYS1(2,等等等等),因爲我選擇了2,檢查選擇的選項(在這種情況下是沒有的),並將信息提取出來。但因爲我沒有提交任何信息的是,選項名稱標籤,姓標籤,性別將是空白的,將是這樣的:

NUMBERBOX: 2 
name label: 
last name label: 
gender: 

now lets say i input info into numberbox 2 

NUMBERBOX: 2 
name label: no 
last name label: no 
gender: no 

現在,如果我進入NUMBERBOX並選擇1再次,它會存儲所有信息到數組numberbox 2,所以ARRAYS1(2,等等等等等等),重新回到了陣來獲得numberbox 1的信息,現在它應該是這樣的:

NUMBERBOX: 1 
name label: yes 
last name label: no 
gender: yes 

^^^^(the same as chosen from the first time). 

現在的問題是我有一個按鈕,當點擊它時選擇其中一個選項並檢查它

q24.value=true 

可以說,此複選框是名稱標籤是選項,我還有一個按鈕,這將改變NUMBERBOX值可以說,「2」

Current_Label_Number.Text = "2" 

應該叫Private Sub current_Label_number_Change()和信息存入數組然後將其更改爲2.

但由於某些原因,它不存儲信息,出於某種原因,我的選項僅在用戶選擇複選框或組合框本身時才使用以下代碼存儲:q24.value =真正行不通。我不知道爲什麼,有人請幫忙!

謝謝

+0

**發佈您的當前代碼** –

+0

我已經發布了用於存儲和檢索數組信息的代碼作爲回答 – HumanlyRespectable

+0

沒關係,我已經自己解決了這個問題。我只是很愚蠢 – HumanlyRespectable

回答

0

這是用於存儲信息的整個代碼和檢索信息

Private Sub Current_Bay_Number_Enter() 

      Dim i As Integer 
      For i = 0 To 19 Step 1 

       If Me.Controls("Q" & i).Value = -1 Then 
        Question_Value(Cu 

rrent_Bay_Number.Value - 1, i) = 1 
      Else 
       Question_Value(Current_Bay_Number.Value - 1, i) = Me.Controls("Q" & i).Value 
      End If 
     Next 

     For i = 22 To 27 Step 1 
      If Me.Controls("Q" & i).Value = -1 Then 
       Question_Value(Current_Bay_Number.Value - 1, i) = 1 
      Else 
       Question_Value(Current_Bay_Number.Value - 1, i) = Me.Controls("Q" & i).Value 
      End If 
     Next 

     Call DataEntry 

    End Sub 

'' '' '' '' '' '' '' '' '' ''」 「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」 '

Public Sub DataEntry() 

    Dim temp() As Integer 
    ReDim temp(ArraySize) 
    Dim i As Integer 

    For i = 0 To 19 Step 1 

     If Me.Controls("Q" & i).Value * (-1) <> 0 Then 
     '//CSA STANDARD 
      If i = 0 Then 
       temp(2) = temp(2) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//CSA SPECIAL 
      If i = 1 Then 
       temp(3) = temp(3) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//MINI RUPTER SWITCH 
      If i = 2 Then 
       temp(9) = temp(9) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//ALDUTI SWITCH 
      If i = 3 Then 
       temp(9) = temp(9) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//ACCESS PLATE INTERIOR 
      If i = 4 Then 
       temp(15) = temp(15) + Me.Controls("Q" & i).Value 
       temp(12) = temp(12) + Me.Controls("Q" & i).Value 
      End If 
     '//DOOR 
      If i = 5 Then 
       temp(10) = temp(10) + Me.Controls("Q" & i).Value 
       temp(17) = temp(17) + Me.Controls("Q" & i).Value 
      End If 
     '//PANEL(NON UTILITY) 
      If i = 6 Then 
       temp(10) = temp(10) + Me.Controls("Q" & i).Value 
       temp(12) = temp(12) + Me.Controls("Q" & i).Value 
       temp(17) = temp(17) + Me.Controls("Q" & i).Value 
      End If 
     '//SCREEN DOOR 
      If i = 7 Then 
       temp(15) = temp(15) + Me.Controls("Q" & i).Value 
       temp(12) = temp(12) + Me.Controls("Q" & i).Value 
      End If 

     '//SERVICE ENTRANCE 
      If i = 9 Then 
       temp(14) = temp(14) + Me.Controls("Q" & i).Value * (-1) 
       temp(16) = temp(16) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//NUMBER OF HEATERS 
      If i = 10 Then 
       temp(18) = temp(18) + Me.Controls("Q" & i).Value 
      End If 

     '//VOLTAGE INDICATORS 
      If i = 12 Then 
       temp(20) = temp(20) + Me.Controls("Q" & i).Value 
      End If 
     '//FUSE REFILL 
      If i = 13 Then 
       temp(21) = temp(21) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//INSTRUCTION LABEL - 1 PER LINEUP, NOT INCLUDED HERE 

     '//ACCESS PLATE EXTERIOR (USED TO BE PT CARIAGE) 
      If i = 14 Then 
       temp(10) = temp(10) + Me.Controls("Q" & i).Value 
       temp(12) = temp(12) + Me.Controls("Q" & i).Value 
      End If 
     '//SMD 
      If i = 15 Then 
       temp(26) = temp(26) + Me.Controls("Q" & i).Value * (-1) 
       temp(27) = temp(27) + Me.Controls("Q" & i).Value * (-1) 
       temp(29) = temp(29) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//FUSE ABOVE SWITCH 
      If i = 16 Then 
       temp(23) = temp(23) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//DOUBLE BREAK SWITCH 
      If i = 17 Then 
       temp(28) = temp(28) + Me.Controls("Q" & i).Value * (-1) 
      End If 
     '//46KV 
      If i = 18 Then 
       temp(9) = temp(9) * 3 
       temp(23) = temp(23) * 3 
       temp(29) = temp(29) * 3 
      End If 

     '//Instruction label and manual location 
      If i = 19 Then 
       temp(22) = temp(22) + Me.Controls("Q" & i).Value * (-1) 
      End If 

     End If 
    Next 

    For i = 22 To ControlCount Step 1 
     If Me.Controls("Q" & i).Value * (-1) <> 0 Then 
      '//SERVICE ENTRANCE BAY 
       If i = 22 Then 
        temp(11) = temp(11) + Me.Controls("Q" & i).Value * (-1) 
       End If 
      '//LINE/LOAD SEPARATOR 
       If i = 23 Then 
        temp(7) = temp(7) + Me.Controls("Q" & i).Value * (-1) 
        temp(8) = temp(8) + Me.Controls("Q" & i).Value * (-1) 
       End If 
      '//TIE BAYS 
       If i = 24 Then 
        temp(16) = temp(16) + Me.Controls("Q" & i).Value * (-1) 
       End If 
      '//WIRE TROUGH 
       If i = 25 Then 
        temp(33) = temp(33) + Me.Controls("Q" & i).Value * (-1) 
        'Bays(Current_Bay_Number.Value - 1, 33) = Bays(Current_Bay_Number.Value - 1, 33) + Me.Controls("Q" & i).Value * (-1) 
       End If 
      '//INCOMER 
       If i = 26 Then 
        temp(16) = temp(16) + Me.Controls("Q" & i).Value * (-1) 
       End If 
      '//# OF PANELS(UTILITY) 
       If i = 27 Then 
        temp(13) = temp(13) + Me.Controls("Q" & i).Value 
        temp(10) = temp(10) + Me.Controls("Q" & i).Value 
        temp(17) = temp(17) + Me.Controls("Q" & i).Value 
       End If 

     End If 
    Next 

    '//Storing bay information array into master array 
    For i = 0 To ArraySize Step 1 
     Bays(Current_Bay_Number.Value - 1, i) = temp(i) 
    Next 
End Sub 

''' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''」 ''''''''''''''''''''''''''''''''''''

Private Sub current_bay_number_Change() 

    Dim i As Integer 

    For i = 0 To 19 Step 1 

     Me.Controls("Q" & i).Value = Question_Value(Current_Bay_Number.Value - 1, i) 
     If Me.Controls("Q" & i).Value = -1 Then 
      Me.Controls("Q" & i).Value = 1 
     End If 
    Next 

    For i = 22 To 27 Step 1 
      Me.Controls("Q" & i).Value = Question_Value(Current_Bay_Number.Value - 1, i) 
     If Me.Controls("Q" & i).Value = -1 Then 
      Me.Controls("Q" & i).Value = 1 
     End If 
    Next 

    '"SMD-2C FUSE" & "DOUBLE BREAK SWITCH" & "# OF DOORS" combo box is locked 
    Q15.Locked = True 
    Q17.Locked = True 

End Sub