Results 1 to 4 of 4

Thread: [RESOLVED] Help with arrays - Almost there!

Threaded View

  1. #1

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Resolved [RESOLVED] Help with arrays - Almost there!

    Back again with cap in hand...

    Below is code kindly provided by killazzz. Attached is the document that contains the code.

    Within the document is a userform that contains a series of comboboxes, some of which are disabled. Each combobox represents an item that has a unique price.

    When the code is executed, any comboboxes that are enabled, but false will be added to the document in the form:

    checkbox.caption <TAB SPACE> £ <TAB SPACE> Price


    VB Code:
    1. Private Sub CommandButton1_Click()
    2.  
    3. 'you define an array of all your prices and string variables
    4. Dim A As Variant
    5. Dim x As Integer
    6. Dim chkMyCheck As Control
    7. Dim MainPriceControlArray(5, 2) As String
    8.  
    9.     MainPriceControlArray(1, 1) = "150.00"       'Chain Shorteners
    10.     MainPriceControlArray(2, 1) = "100.00"        'Protection Covers
    11.     MainPriceControlArray(3, 1) = "2000.00" '     'Load Cells
    12.     MainPriceControlArray(4, 1) = "400.00" '    strCheckBox4= "400.00"
    13.     MainPriceControlArray(5, 1) = "500.00" '    strCheckBox5 = "500.00"
    14.    
    15.     MainPriceControlArray(1, 2) = "chkChainShorteners"
    16.     MainPriceControlArray(2, 2) = "chkProtectionCovers"
    17.     MainPriceControlArray(3, 2) = "chkLoadCells"
    18.     MainPriceControlArray(4, 2) = "strCheckBox4" '    strFireExtingExt
    19.     MainPriceControlArray(5, 2) = "chktest124578986532" '    strFireExtingInt
    20.    
    21. 'then you loop through your array and controls in the document
    22. ' you check each  control for it's anabled and value property and take the appropriate action
    23.  
    24.     For x = 1 To UBound(MainPriceControlArray)
    25.         For Each chkMyCheck In Me.Controls
    26.             If LCase(Left(chkMyCheck.Name, 3)) = "chk" And InStr(1, MainPriceControlArray(x, 2), chkMyCheck.Name, vbTextCompare) <> 0 Then
    27.                 If chkMyCheck.Enabled = True And chkMyCheck.Value = False Then
    28.                     ActiveDocument.Bookmarks("Test").Range.Text = vbCr & chkMyCheck.Caption & vbTab & "£" & vbTab & MainPriceControlArray(x, 1)
    29.                 Exit For
    30.                 End If
    31.             End If
    32.         Next chkMyCheck
    33.     Next
    34.    
    35. End Sub
    I am now attempting to alter the code slightly so that the items to be added to the document are done so using a table.

    What I have attempted to do is create another array that has 3 columns and the number of rows is equal to the number of items to be added. I than want to create a table of equivalent dimensions and add that to the document.

    For example, if there were 2 items to be added to the document (in reality the list is much larger), I would get a 2 row, 3 column table, which would contain the following items.

    (1,1) = checkbox1.caption
    (1, 2) = "£"
    (1, 3) = checkbox1 price

    (2,1) = checkbox2.caption
    (2,2) = "£"
    (2, 3) = checkbox2 price

    I also want to set column sizes and word alignment, but can probably work that out later. I have made numerous attempts at the above, but am having real difficulty. I have referenced arrays in the help files in vba, but can't seem to apply the information correctly (obviously it is the help files at fault )

    Any help appreciated.
    Attached Files Attached Files
    Last edited by New2vba; Mar 26th, 2006 at 12:30 PM.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width