سؤال

I currently am programming a macro that is a label generator for my work, basically it has a combo box and in the combo box you can choose a number from 1-4 (lets call this number box for future reference), there are also a bunch of check boxes and other combo boxes for choosing the label options. In the macro i have an array which stores all the information for each numberbox. Each number box will have the same options to choose from but the options chosen might be different.

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

i have made it that when the user selects a different number in the numberbox, it calls a subroutine which stores all the chosen labels into an array. After this subroutine is called and all the information is stored, whatever number the user chose in the number box, it will pull that information out and auto select the options the user chose already.

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

after the selections above i go into numberbox and choose the number 2, all the information will be saved into the array first ARRAYS1(1,blah blah blah). then it will go look into the array ARRAYS1(2, blah blah blah) because i chose 2, check the chose options (which in this case is none) and pulls info out. but since i did not submit any info yet, the options name label, last name label, and gender will be blank and will look like this:

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

now if i go into NUMBERBOX and select 1 AGAIN, it will store all the info into array for numberbox 2, so ARRAYS1(2, blah blah blah), go back into the array to get info for numberbox 1 and now it should look like this:

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

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

now the problem is that i have a button, that when clicked it chooses one of the options and checks it

q24.value=true

lets say this checkbox is for name label YES option, and i have another button which will change the NUMBERBOX value to lets say "2"

Current_Label_Number.Text = "2"

which should call Private Sub current_Label_number_Change() and store the info into the array and then change it to 2.

but for some reason it is not storing the info, for some reason my options are stored only if the user selects the checkbox or combo box themselves, using the code like: q24.value=true does not work. i do not know why, someone please help!

Thank You

هل كانت مفيدة؟

المحلول

This is the entire code for Storing info, and Retrieving Info

   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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top