Results 1 to 8 of 8
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368

    Overload On Long Variable

    Hi Guys, i have tried a couple of things to fix this one

    I have 16 lists on screen, each list represents a route number,

    I have tried setting variables as Integer knowing the variables are whole numbers, then converting to Long using Clng(), i was receiving runtime error 6 overload which is normally an incorrect variable setting and after multiplying the TWIPS there is a result of 1404246 in the immediate window, still receive an overload (Now Set to Long) to accommodate large numbers that may calculate to include decimals.

    Is there a better way of doing this ?



    So my intention is because there 16 list boxes, i want the option to expand the top row of lists to display without having to scroll on each list


    Once I know the best method, i can expand/collapse a row of lists at a time.


    Code:
    Const TWIPS_PER_CM As Long = 283
    Dim intMainIndex As Integer, intIndex As Integer
    
    Dim lngOrgSize As Long, lngLarge As Long
    
    
    Dim strPath As String, strFile As String
    
    
    intMainIndex = Me.tbcMainMenu.Value ' Tab Page Index
    intIndex = Me.cboOption7.ListIndex 'Combo Index
    lngLarge = 4962
    lngOrgSize = 2210
    
    
    Select Case intMainIndex
    Case Is = 2 'VIEW ROUTES
        Select Case intIndex
        Case Is = 0 ' LISTS 1,5,9,13
        
            With Me.lstRoute1        
    Debug.Print lngLarge * TWIPS_PER_CM
            
            Stop
    
    
    
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute5
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute9
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute13
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
        
        Case Is = 4 'REST TO ORIGIONAL SIZE
            With Me.lstRoute1
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute5
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute9
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute13
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            
        End Select
    End Select

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Why have a nested Select block when it only has one case? Your issue isn't obvious (at least to me). 4692*283 does not exceed the size of a long variable, so I don't see a problem there. Knowing which line raises the error might help. This may be something that you need to upload a db in order to solve it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Try setting lngLarge and lngOrgSize to CM instead of twips.
    Why is code choosing third tab page, but modifying the first page?

    Edit: Everyone is seeing this wrong. Overflow is not due to the calculation, it's because the code is trying to set the listbox height to a bit over 81 FEET.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,567
    4692*283 = 1,327,836
    That still gives me error 6?

    Code:
    Sub TestLong()
    Dim lngResult As Long
    Dim i1 As Integer, i2 As Integer
    i1 = 4692
    i2 = 283
    lngResult = i1 * i2 'Errors here
    Debug.Print lngResult
    
    
    End Sub
    yet Long is supposed to be able to contain -2,147,483,648 to 2,147,483,648

    If I use
    lngResult = 2147483640, it accepts it no problem?

    This works
    Code:
    Sub TestLong()
    Dim lngResult As Long
    Dim i1 As Long, i2 As Long
    i1 = 4692
    i2 = 283
    lngResult = i1 * i2
    Debug.Print lngResult
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,567
    I asked on another site about this and the answer I received was
    Multiply an integer by an integer results in an integer value
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Thanks guys, i have this working by avoiding Const to Twips and using Long variables

    Code:
    Dim lngOrg As Long, lngLarge As Long
    lngOrg = 2210
    lngLarge = 4962
    
    
    Dim strPath As String, strFile As String
    
    
    intMainIndex = Me.tbcMainMenu.Value ' Tab Page Index
    intIndex = Me.cboOption7.ListIndex 'Combo Index
    
    
    Select Case intMainIndex
    Case Is = 2 'VIEW ROUTES
        Select Case intIndex
        Case Is = 0 ' LISTS 1,5,9,13
        
            With Me.lstRoute1
                .Height = lngLarge
            End With
            With Me.lstRoute5
                .Height = lngLarge
            End With
            With Me.lstRoute9
                .Height = lngLarge
            End With
            With Me.lstRoute13
                .Height = lngLarge
            End With
        Case Is = 1
            'Lists 2,6,10,14
        Case Is = 2
            'Lists 3,7,11,15
        Case Is = 3
            'Lists 4,7,12,16
            
        Case Is = 4 'REST TO ORGIGIONAL SIZE
            With Me.lstRoute1
                .Height = lngOrg
            End With
            With Me.lstRoute5
                .Height = lngOrg
            End With
            With Me.lstRoute9
                .Height = lngOrg
            End With
            With Me.lstRoute13
                .Height = lngOrg
            End With
            
        End Select
    End Select

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,567
    FWIW I was consequently advised that only one of the values needs to be Long.
    However someone mentioned variants, and one of the integers as a variant works as well.

    @DMT Dave,
    I would save some typing and just use With Me, then
    Code:
     .lstRoute1.Height = lngOrg
     .lstRoute5.Height = lngOrg
     .lstRoute9.Height = lngOrg
     .lstRoute13.Height = lngOrg
    
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Thanks for the tip WGM, So With Me, didn't realize you could declare an array with nothing after ("ME")

    This is why you guys are the GOAT in vba

    Just adapted and yes, it does shorten the procedure

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Modules and Object Overload
    By drexasaurus in forum Programming
    Replies: 4
    Last Post: 05-23-2014, 11:14 AM
  2. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  3. Long Variable syntax
    By eww in forum Programming
    Replies: 5
    Last Post: 02-10-2011, 03:34 PM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums