Results 1 to 10 of 10

Thread: [RESOLVED] Logic problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2020
    Posts
    73

    Resolved [RESOLVED] Logic problem

    Hello

    I am working on a small project in VB6.
    The program should populate a ListView table.
    It is about assigning door-phone numbers for a residential building.
    The building can have from 1 to 10 floors, and each floor can have from 0 to 10 apartments.
    Door-phone system has one calling unit and handset in each apartment. There are also decoders connected between the calling unit and the handset. From 1 to 4 handset units can be connected to each decoder.

    In the first picture there is an example of 4 floors and 4 decoders. On the first floor there are 3 apartments marked with numbers 0001, 0002, 0003. Address 003 from decoder number 0 is unused. Apartment numbers continue with decoder number 1, which is located on floor number 2 and has 2 apartments marked with numbers 0004 and 0005. Addresses 006 and 007 are unused. Can you see a pattern?

    The second picture shows an example with 5 apartments on the first floor and 2 decoders. On the second floor there is 1 decoder for 2 apartments and on the third floor there are 3 decoders for 9 apartments.

    I need the apartment numbers to be in order starting from 0001, with unused addresses from each decoder to be 0000.

    Any idea how this could be written in VB6?

    ps I use Google Translate




    1.zip

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,608

    Re: Logic problem

    I'm going with the premise, that the apartments are "there", just not rented out.
    Meaning:
    Decoder 0 - Address 003 should be Apartment 0004 with a Flag "unused", and so on.

    IMO, it makes no sense, to "jump" over unused apartments
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2020
    Posts
    73

    Re: Logic problem

    Decoder 0 - Address 003 is unused because Apartment 0004 is on the 2nd floor and Decoder 0 is on the 1st floor.

    1st floor
    apartment 0001
    apartment 0002
    apartment 0003

    2nd floor
    apartment 0004
    apartment 0005

    etc.
    Last edited by Zann; Jun 18th, 2024 at 05:31 AM.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,608

    Re: Logic problem

    OK, got you.
    So the "Master" is not the Decoder, but the Apartment, since an Apartment should know on which floor it resides on.
    The count of apartments per floor divided by 4 round up to next integer gives you the number of decoders per floor.
    Then it's a simple "run down" assigning the addresses. Any "left over" of apartments is set to 0000
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2020
    Posts
    73

    Re: Logic problem

    I would not call it "Master" , but each decoder has a unique ID number shown in the images in the first column "Decoder No."

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,621

    Re: Logic problem

    Personally I'd try to organize it so that the address and the apt number match... leaving address 0000 unused (since there is no apartment 0000)....
    That would then make things match up a bit better...

    But then again, I'm not 100% sure I'm following correctly.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,665

    Re: Logic problem

    Edit: Ok, just read OP again and didn't catch the part where different floors have different numbers of apartments.

    Something like this - or could be done recursively if you want to be clever about it.

    Code:
    Dim nFloor As Long
    CONST FLOOR_COUNT As Long = 1000 ' Moderately tall building.
    Dim nApartmentCount(FLOOR_COUNT) As long
    Dim nFloor As long
    dim nApartment As Long
    
    ' Fill in nApartmentCount  from a text file or whatever.  Do that here or call another sub.
    
    For  nFloor = 1 To FLOOR_COUNT
    
       for nApartment = 1 To nApartmentCount(nFloor)
    
          GenerateBuzzerNumber(nFloor, nApartment)
    
       Next nApartment
    
    Next nFloor
    Last edited by cafeenman; Jun 18th, 2024 at 11:33 AM.

  8. #8
    Junior Member
    Join Date
    Nov 2020
    Posts
    31

    Re: Logic problem

    This will need a reference to the "Microsoft Hierarchiel FlexGrid Control 6.0" component. Place one on a form named "grid"
    The following should get you pretty close to what you want. Sorry its a mess and lacking comments.

    Basically set apartment count and decoder count for each floor in SetupFloors() and the FLOOR_CT const at the top.

    Code:
    Option Explicit
    
    'Set floor count here
    Private Const FLOOR_CT& = 3
    
    
    Private Type apt_floor
        apartment_ct As Long
        decoder_ct As Long
        End Type
    
    Private apt_floors() As apt_floor
    Private row_ct&
    
    Private Sub Form_Load()
        Call SetupFloors    'Setup info for floors
        Call SetupGrid      'Setup the grid. Row count, col headers
        Call DisplayGrid    'Fill the grid
    End Sub
    
    Private Sub SetupFloors()
        'Setup your decoder and apartment counts here for each floor
    
        ReDim apt_floors(FLOOR_CT) As apt_floor
        
        apt_floors(1).apartment_ct = 5
        apt_floors(1).decoder_ct = 2
        
        apt_floors(2).apartment_ct = 2
        apt_floors(2).decoder_ct = 1
        
        apt_floors(3).apartment_ct = 9
        apt_floors(3).decoder_ct = 3
    
    End Sub
    
    Private Sub SetupGrid()
        Dim i&
        
        For i& = 1 To FLOOR_CT
            row_ct& = row_ct& + (apt_floors(i&).decoder_ct * 4)
            Next i&
        grid.Rows = row_ct& + 1
        
        grid.Cols = 3
        
        grid.TextMatrix(0, 0) = "Decoder No."
        grid.TextMatrix(0, 1) = "Address"
        grid.TextMatrix(0, 2) = "Apartment No."
        
        grid.ColWidth(0) = 1500
        grid.ColWidth(1) = 2000
        grid.ColWidth(2) = 1500
        
        grid.Top = 0
        grid.Left = 0
        grid.Height = Me.Height - 900
        grid.Width = Me.Width - 500
        
        grid.Font.Size = 10
        
    End Sub
    
    Private Sub DisplayGrid()
        Dim row_idx&
        Dim address_idx&
        Dim apt_no_idx&
        Dim decoder_no_idx&
        Dim i&, j&, k&
        Dim floor_start&
        
        decoder_no_idx& = 0
        address_idx& = 0
        apt_no_idx& = 1
        
        For i& = 1 To FLOOR_CT&
            floor_start& = address_idx& + 1
            For j& = 1 To (apt_floors(i&).decoder_ct * 4)
                
                grid.TextMatrix(address_idx& + 1, 0) = decoder_no_idx&
                grid.TextMatrix(address_idx& + 1, 1) = address_idx&
                
                If j& <= apt_floors(i&).apartment_ct Then
                        grid.TextMatrix(address_idx& + 1, 2) = apt_no_idx&
                        apt_no_idx& = apt_no_idx& + 1
                    Else
                        grid.TextMatrix(address_idx& + 1, 2) = 0
                    End If
                
                
                For k& = 0 To 2
                    grid.Row = address_idx& + 1
                    grid.Col = k&
                    If i& Mod 2 Then
                            grid.CellBackColor = &H8000000A
                        Else
                            grid.CellBackColor = vbWhite
                        End If
                    Next k&
                    
                address_idx& = address_idx& + 1
                If j& Mod 4 = 0 Then decoder_no_idx& = decoder_no_idx& + 1
                
                
                Next j&
                
            Next i&
        
    End Sub
    
    Private Sub Form_Resize()
        grid.Height = Me.Height - 900
        grid.Width = Me.Width - 500
    End Sub

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2020
    Posts
    73

    Re: Logic problem

    DrBobby thank you very much, it is working as expected.

  10. #10
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,073

    Re: [RESOLVED] Logic problem

    Any idea how this could be written in VB6?
    Before coding in any language, I'd suggest you first design the program. How would you do this using pen & paper? What is the algorithm for doing this? Then produce instructions in English (pseudo code) that would enable someone else to complete the task just using the instructions (without knowing what is the task). Once you have these correct then code the program from the instructions. IMO what you shouldn't do is to jump straight in and start coding. Design first, code second.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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