Menu

Declaring multiple variables on one line with the same value?

2026-07-05
2026-07-07
  • Roger Jönsson

    Roger Jönsson - 2026-07-05

    Dim Variable1, Variable2, Variable3 as Byte = 0
    Is there a reason why this is not possible? Bad idea?

    What does the error message mean?
    Error: Multiple bits can only be set to a fixed value, not a variable

     
  • Roger Jönsson

    Roger Jönsson - 2026-07-06

    The help says this:
    Dim variable[, variable2 [, variable3]] [As type] [At location] [= initialvalue]
    https://gcbasic.sourceforge.io/help/_dim.html
    Is that not what I am trying to do?

     

    Last edit: Roger Jönsson 2026-07-06
  • Anobium

    Anobium - 2026-07-06

    Build 1607 ( when I get to building it ) will support

    // '==============================================================================
    // ' TC04 - Multiple variables, shared initializer (core regression case)
    // '==============================================================================
    Dim RedChannel, GreenChannel, BlueChannel As word = 512
    // ' Expected DataSource after strip: Dim RedChannel, GreenChannel, BlueChannel As Byte
    // ' Expected generated lines:
    // ' RedChannel = 512
    // ' GreenChannel = 512
    // ' BlueChannel = 512

    So, the method to set multiple variables was not implemented by Angel. I have added in 1607.

     
  • Roger Jönsson

    Roger Jönsson - 2026-07-06

    Good to have that working before and in the next general release!

     
  • Anobium

    Anobium - 2026-07-07

    Here you go.

    https://1drv.ms/u/c/2f87ffe77f3dbec7/IQCo0aCT9MXhSqUK9PDDG68_Ad9ZcIaLUbD5CuvX2C25HOs?e=MUCFEY

    My final test program. This ensures you can multiple commands on the init line

    #CHIP 18F27Q84, 64
    #OPTION Explicit
    
    // '==============================================================================
    // ' TC01 - Single variable, no initializer
    // '==============================================================================
    // Dim TemperatureReading As Byte
    // ' Expected: no synthetic assignment line generated (no "=" present)
    
    
    // '==============================================================================
    // ' TC02 - Single variable, with initializer
    // '==============================================================================
    Dim TemperatureReading As Byte = 72
    // ' Expected DataSource after strip: Dim TemperatureReading As Byte
    // ' Expected generated line:         TemperatureReading = 72
    
    
    // '==============================================================================
    // ' TC03 - Multiple variables, no initializer
    // '==============================================================================
    Dim RedChannel, GreenChannel, BlueChannel As Byte
    // ' Expected: no synthetic assignment line generated (no "=" present)
    
    
    // '==============================================================================
    // ' TC04 - Multiple variables, shared initializer (core regression case)
    // '==============================================================================
    NOP: Dim RedChannel, GreenChannel, BlueChannel As word = 512: ASM NOP
    // ' Expected DataSource after strip: Dim RedChannel, GreenChannel, BlueChannel As Byte
    // ' Expected generated lines:
    // '   RedChannel = 512
    // '   GreenChannel = 512
    // '   BlueChannel = 512
    
    
    // '==============================================================================
    // ' TC05 - Location only, no type, no initializer
    // '==============================================================================
    Dim WatchdogFlag1 At 0x500
    // ' Expected: no synthetic assignment line generated (no "=" present)
    
    
    // '==============================================================================
    // ' TC06 - Type and location, no initializer
    // '==============================================================================
    Dim WatchdogFlag2 As Byte At 0x501
    // ' Expected: no synthetic assignment line generated (no "=" present)
    
    
    // '==============================================================================
    // ' TC07 - Type, location, and initializer together
    // '==============================================================================
    Dim WatchdogFlag3 As Byte At 0x502 = 1
    // ' Expected DataSource after strip: Dim WatchdogFlag As Byte At $100
    // ' Expected generated line:         WatchdogFlag = 1
    
    
    
    
    // '==============================================================================
    // ' TC09 - Array declaration (GCBASIC does NOT support an inline array
    // ' initializer -- arrays are declared, then loaded on a separate line)
    // '==============================================================================
    Dim PixelBuffer(10)
    PixelBuffer = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    // ' Expected: the Dim line generates no synthetic assignment line.
    // ' The "PixelBuffer = ..." line does not start with "Dim ", so it never
    // ' enters the Dim parser at all -- it's handled by ordinary assignment
    // ' parsing elsewhere in the preprocessor.
    
    
    // '==============================================================================
    // ' TC10 - Metadata marker present after the initializer
    // ' (";?F...L...S...I...?" is preprocessor-internal line metadata, appended
    // ' automatically -- shown here to confirm it's correctly separated from the
    // ' initializer value rather than swallowed into it)
    // '==============================================================================
    Dim LoopCounter As Byte = 0 
    // ' Expected DataSource after strip: Dim LoopCounter As Byte 
    // ' Expected generated line:         LoopCounter = 0
    
    
    // '==============================================================================
    // ' TC11 - Initializer value itself contains "=" (string literal)
    // '==============================================================================
    // Dim StatusMessage As String = "Code=Ready"
    // ' Expected DataSource after strip: Dim StatusMessage As String
    // ' Expected generated line:         StatusMessage = "Code=Ready"
    
    
    // '==============================================================================
    // ' TC12 - Negative numeric initializer
    // '==============================================================================
    Dim TemperatureOffset As Integer = -5
    // ' Expected DataSource after strip: Dim TemperatureOffset As Integer
    // ' Expected generated line:         TemperatureOffset = -5
    
    
    // '==============================================================================
    // ' TC13 - Variable name containing "As"/"At" as a substring (not a keyword)
    // '==============================================================================
    Dim DataTableIndex As Byte = 0
    // ' Expected DataSource after strip: Dim DataTableIndex As Byte
    // ' Expected generated line:         DataTableIndex = 0
    
     
    ❤️
    1
  • Roger Jönsson

    Roger Jönsson - 2026-07-07

    Thanks! Declaring several variables on one line with the same value, is SO nice!

     
    👍
    1
    • Anobium

      Anobium - 2026-07-07

      Praise goes to Angel for initial implementation and to me for a tidy up.

      I did try using AI for this change, but, AI went a tad crazy by increasing the scope of the change. So, I wrote 'by hand' the update to parse the new construct and handle the change.

       
  • Roger Jönsson

    Roger Jönsson - 2026-07-07

    In todays test program, ten lines of DIM and values became one easy to read and manage line!
    Thank you both!

     

Log in to post a comment.

MongoDB Logo MongoDB