Results 1 to 9 of 9

Thread: [RESOLVED] Too many Line Continuations

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    578

    Resolved [RESOLVED] Too many Line Continuations

    I have run into a problem with the above. To keep my code easy to manage for the future, I have tried;

    Code:
    FPData = Array(0, "File Paths:", False, False, _
            1, "MusicPath: " & MusicPath, True, 0, _
            2, "JinglePath: " & JinglePath, True, 0, _
            3, "Location for Data files: " & UAP, False, 0, _
            4, "Location for Backup files: " & NDir, False, 0)
        
        CtlData = Array(10, "Control:", False, False, _
            11, "Auto start next loaded player.", True, PlayNext, _
            12, "Colour alternate rows in lists.", True, Alternate, _
            13, "Delete all images from this session in downloads folder when App closes.", True, DelImage, _
            14, "Delete source files after importing into Music Folder.", True, DeleteSource, _
            15, "Hot tracking in lists.", True, Tracking, _
            16, "Load tracks into memory, instead of playing from disk.", True, Memory, _
            17, "Remove 'The'. Replace 'and' with '&' in Artist during Import/Input/Edit.", True, InpRemoveThe, _
            18, "Show track technical details.", True, LoadTime, _
            19, "Use External Jingles from folder selected in File Paths.", True, UseJingles, _
            30, "Searches:", False, False, _
            31, "Add Fuzzy Logic to Artist/Title/Duplicate searches.   Not to 'Exact' searches.", True, FuzzSearch, _
            32, "Highlight tracks whose Album names need attention. F7 updates.", True, AlbumNames, _
            33, "TrackTypes: Show Lossless as GREEN.  Compressed as MAGENTA.", True, ShowFileFormat, _
            34, "TrackTypes: Add (P)icture to above.", True, AddPicture, _
            40, "Sorting:", False, False, _
            41, "Default: Except Number & Album (to keep track order), sort by Artist & Title.", True, Not SrchSort, _
            42, "Title: Sort all except Album by Title only. (Useful for finding odd duplicates)", True, SrchSort, _
            43, "Highlight duplicate Titles. (Only if Title selected above)", True, (HighLiteDupes And SrchSort), _
            50, "Sound:", False, False, _
            51, "SoundCard in use: " & strSound, False, False, _
            52, "AutoLevel: RMS Average.", True, AutoLevel = 1, _
            53, "AutoLevel: Compression 5:1", True, AutoLevel = 2)
    If I try to do it all in one array, I get the error. How can I use just one array and yet have plenty of room for the future and keep the layout neat for control?

    Many thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Too many Line Continuations

    I would put the data in a file, database or resource file and read it into the array. Another option would be to create a class and have those as properties. Hard coding with line continuations like that would be the last resort as that counts as one really really long line of code and makes it hard to read and debug.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Too many Line Continuations

    In addition to DataMiser's suggestions, here's another one.

    Use a loop to populate the array...
    Code:
    Dim n As Long, p As Long
    
    Const NrRows As Long = 23   ' modify these 2 whenever rows or columns change
    Const NrCols As Long = 4
    
    ReDim CtlData(NrRows * nrCols - 1)
    
    For n = 0 to NrRows - 1
        Select Case n
        Case 0
            CtlData(p)=10: CtlData(p+1) = "Contrtol:": CtlData(p+2)=False: CtlData(p+3)=False
        Case 1
            CtlData(p)=11: CtlData(p+1) = "Auto start next loaded player.": CtlData(p+2)=True: CtlData(p+3)=PlayNext
        
        ... continue with other Case statements
    
        Case 22
            CtlData(p)=53: CtlData(p+1) = "AutoLevel: Compression 5:": CtlData(p+2)=True: CtlData(p+3)=AutoLevel = 2
    
        End Select
        p = p + nrCols
    Next
    This does make it a bit easy to read and update for future changes -- but not as easy as what you are doing right now. It does kinda suck in one way: If you needed to insert/remove a Case statement (nrRows changed), that would require manually renumbering the statements following the insert/deletion, only if the order in the array is important.

    One of the problems with storing these in a res file, database, or another static place is that it appears most of your array rows have a dynamic setting, i.e., AutoLevel = 2, (HighLiteDupes And SrchSort), and references to other variables.

    Edited: If you use Option Base 1 then ensure p=1 before the loop starts and change your ReDim to: ReDim CtlData(NrRows * nrCols)
    Last edited by LaVolpe; Feb 24th, 2019 at 12:57 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Too many Line Continuations

    And, to add my 2-cents, if you just really wanted all those constant literals in your source code (as opposed to off in a file somewhere), you could put a large Select Case inside of your loop, based on the loop's index. Something like this (not tested):

    Code:
    
    Dim FPData(4 * 4)       As Variant
    Dim CtlData(53 * 4)     As Variant
    Dim i                   As Long
    
    For i = 0 To 4 * 4 Step 4
        FPData(i) = i \ 4
        Select Case FPData(i)
        Case 0: FPData(i + 1) = "File Paths:":                           FPData(i + 2) = False:  FPData(i + 3) = False
        Case 1: FPData(i + 1) = "MusicPath: " & MusicPath:               FPData(i + 2) = True:   FPData(i + 3) = 0
        Case 2: FPData(i + 1) = "JinglePath: " & JinglePath:             FPData(i + 2) = True:   FPData(i + 3) = 0
        Case 3: FPData(i + 1) = "Location for Data files: " & UAP:       FPData(i + 2) = False:  FPData(i + 3) = 0
        Case 4: FPData(i + 1) = "Location for Backup files: " & NDir:    FPData(i + 2) = False:  FPData(i + 3) = 0
        End Select
    Next
    
    
    For i = 0 To 53 * 4 Step 4
        CtlData(i) = (i \ 4) + 10
        Select Case CtlData(i)
        Case 10:    CtlData(i + 1) = "Control:":                            CtlData(i + 2) = False: CtlData(i + 3) = False
        Case 11:    CtlData(i + 1) = "Auto start next loaded player.":      CtlData(i + 2) = True:  CtlData(i + 3) = PlayNext
        Case 12:    CtlData(i + 1) = "Colour alternate rows in lists.":     CtlData(i + 2) = True:  CtlData(i + 3) = Alternate
        ' ... complete the list.
        End Select
    Next
    
    

    Good Luck,
    Elroy

    EDIT1: Also, if it were me, I'd absolutely use a UDT array for that data, rather than a strided arrays. Personally, I just really don't like strided arrays. And using a UDT would simplify my example code substantially.

    EDIT2: I couldn't help myself. The following shows how I'd do it with a UDT, just for your first array:

    Code:
    
    Option Explicit
    
    Private Type FPDataType
        idx     As Long
        path    As String
        num1    As Integer
        num2    As Integer
    End Type
    
    Dim MusicPath   ' just to test
    Dim JinglePath  ' just to test
    Dim UAP         ' just to test
    Dim NDir        ' just to test
    '
    
    
    Private Sub Form_Load()
    
        Dim FPData(4)           As FPDataType
        Dim i                   As Long
    
        For i = 0 To 4
            FPData(i).idx = i
            Select Case i
            Case 0: FPData(i).path = "File Paths:":                           FPData(i).num1 = False:  FPData(i).num2 = False
            Case 1: FPData(i).path = "MusicPath: " & MusicPath:               FPData(i).num1 = True:   FPData(i).num2 = 0
            Case 2: FPData(i).path = "JinglePath: " & JinglePath:             FPData(i).num1 = True:   FPData(i).num2 = 0
            Case 3: FPData(i).path = "Location for Data files: " & UAP:       FPData(i).num1 = False:  FPData(i).num2 = 0
            Case 4: FPData(i).path = "Location for Backup files: " & NDir:    FPData(i).num1 = False:  FPData(i).num2 = 0
            End Select
        Next
    
    End Sub
    
    
    Last edited by Elroy; Feb 24th, 2019 at 12:00 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Too many Line Continuations

    Just for grins, here's the outline of another trick I sometimes use in similar situations. I'm probably not going to give you complete source, but hopefully you'll get the idea. In the example below, I'm setting up to add a new table to an MS-Access database. I'm going to start at field #13, because the earlier ones are a bit more complex:

    Code:
    
        ' The muscle parameter fields.
        i = 12
        lInc i: SetNewField TheFields(i), "GastrocLenMin", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "GastrocLenMax", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "GastrocLenMean", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "GastrocVelMin", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "GastrocVelMax", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "GastrocVelMean", dbDouble, 8, Null, True, False
        '
        lInc i: SetNewField TheFields(i), "SoleusLenMin", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "SoleusLenMax", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "SoleusLenMean", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "SoleusVelMin", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "SoleusVelMax", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "SoleusVelMean", dbDouble, 8, Null, True, False
        '
        lInc i: SetNewField TheFields(i), "PosteriorTibLenMin", dbDouble, 8, Null, True, False
        lInc i: SetNewField TheFields(i), "PosteriorTibLenMax", dbDouble, 8, Null, True, False
    
    

    And, the little lInc procedure is just:

    Code:
    
    Public Sub lInc(l As Long)
        l = l + 1
    End Sub
    
    

    That just gives me a i++ (c) type functionality, which cleans up the code a bit. And then, I'll show you my SetNewField function which takes one of those TheFields UDTs from the array and sets it:

    Code:
    
    Private Sub SetNewField(TheField As dbFieldAddType, TheName As String, TheType As dbDataTypeEnum, TheSize As Long, _
                            DefaultVal As Variant, AllowZeroLength As Boolean, Required As Boolean, Optional Description As String)
        ' This is just for convenience so that code above is cleaned up to one line per new field.
        TheField.fdfName = TheName
        TheField.fdfType = TheType
        TheField.fdfSize = TheSize
        TheField.fdfDefaultValue = DefaultVal
        TheField.fdfAllowZeroLength = AllowZeroLength
        TheField.fdfRequired = Required
        TheField.fdfDescription = Description
    End Sub
    
    

    And the TheFields UDT looks like the following:

    Code:
    
    Private Type dbFieldAddType
        fdfName             As String
        fdfType             As dbDataTypeEnum
        fdfSize             As Long
        fdfDefaultValue     As Variant
        fdfAllowZeroLength  As Boolean ' For strings.
        fdfRequired         As Boolean
        fdfDescription      As String
    End Type
    
    

    I don't know if that'll give you any ideas or not, but it is quite similar to what you're doing. Also, just to say it, if they're not to be user-maintained, I've got no problems at all with putting constant literals directly in my source code like the above.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Too many Line Continuations

    @Steve. When do you use the code you posted in #1 above? Guessing that those arrays are used during the presentation of some "Options" form. If that is the case, not sure persisting these in memory during the lifetime of your project is the best choice. Why? You only need that info when the "Options" are displayed. A better choice may be to simply read them from a file where you saved the user's choices. And of course, save those choices when the "Options" form is closed/released. In that case, you would have a read/write function triggered by the form's Load/Unload events. And the code you use there is typically self-documenting, i.e., easy to modify for future changes.

    How you save those choices are completely up to you. DataMiser offered suggestions as did Elroy. And there are other formats available to you, i.e., property bags, disconnected recordsets and more.
    Last edited by LaVolpe; Feb 24th, 2019 at 01:06 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Too many Line Continuations

    Hello,

    If they are fixed values, I would use simple arrays:

    Code:
        Dim FPData(4 * 4)
        
        FPData(0) = 0: FPData(1) = "File Paths:": FPData(2) = False: FPData(3) = False
        FPData(4) = 1: FPData(5) = "MusicPath: " & MusicPath: FPData(6) = True: FPData(7) = 0
        FPData(8) = 2: FPData(9) = "JinglePath: " & JinglePath: FPData(10) = True: FPData(11) = 0
        FPData(12) = 3: FPData(13) = "Location for Data files: " & UAP: FPData(14) = False: FPData(15) = 0
        FPData(16) = 4: FPData(17) = "Location for Backup files: " & NDir: FPData(18) = False: FPData(19) = 0

  8. #8
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Too many Line Continuations

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:07 AM.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    578

    Re: Too many Line Continuations

    Thank you all. It is clear that I really need to get this stuff out of the program and onto disk.

    First thing in the morning I will be at it.

    Thanks again.

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