Consulting

Results 1 to 5 of 5

Thread: Solved: Include decimals in a number range

  1. #1

    Solved: Include decimals in a number range

    How can i change this code to include .5 after every whole number? Currently it displays in the combo box -12, -11, -10...0...10, 11, 12. I like it to include -12, 11.5, 11, 10.5, 10 etc., but keep the max range of -12 to 12. Can someone assist. Thank

    [vba]Dim GMT(1 To 25), i As Long

    For i = -12 To 12
    GMT(i + 13) = i
    Next
    Me.cboGMT.List = GMT
    [/vba]

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    [vba]Dim GMT(1 To 50), i As Long

    For i = -12 To 12 step 0.5
    GMT(i + 13) = i
    Next
    Me.cboGMT.List = GMT
    [/vba]

  3. #3
    Sry for the late reply...I made the changes, but the changes locks me out, forcing me to force close the program. Any idea?

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by av8tordude
    Sry for the late reply...I made the changes, but the changes locks me out, forcing me to force close the program. Any idea?
    try changing patel's Long to Double or Single.
    Also you can't have array index as a fraction.
    What are you trying to do?
    Something like this:?
    [VBA]Dim GMT(1 To 49), i As Double, k as Long
    k = 1
    For i = -12 To 12 Step 0.5
    GMT(k) = i
    k = k + 1
    Next
    Me.cboGMT.List = GMT
    [/VBA]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    P45Cal...Yes...this works. I did what you suggest to patel's code (thank you Patel for you assistance.), but it was skipping numbers.

    Thanks

Posting Permissions

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