Results 1 to 17 of 17

Thread: [RESOLVED] Condense code...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Condense code...

    Hi, how would you condense this into on with instead of multiple due to them all having the same values but different number?
    VB Code:
    1. Private Sub Form_Load()
    2.     Call Button_Captions
    3.     Call Label_Captions
    4.    
    5.     Me.BackColor = vbBlue
    6.    
    7. 'THIS DOESNT WORK SO PROBABLY GOING WRONG SOMEWHERE.  WANT
    8. 'TO CONDENSE THE ONES BELOW INTO ONE INSTEAD OF MULTIPLE.
    9.     Dim intFrame As Integer
    10.     With Frame(intFrame)
    11.         .BackColor = vbBlue
    12.         .ForeColor = vbWhite
    13.     End With
    14.    
    15.     'With Frame(0)
    16.     '    .BackColor = vbBlue
    17.     '    .ForeColor = vbWhite
    18.     'End With
    19.    
    20.     'With Frame(1)
    21.     '    .BackColor = vbBlue
    22.     '    .ForeColor = vbWhite
    23.     'End With
    24.    
    25.     'With Frame(2)
    26.     '    .BackColor = vbBlue
    27.     '    .ForeColor = vbWhite
    28.     'End With
    29.  
    30.     'With Frame(3)
    31.     '    .BackColor = vbBlue
    32.     '    .ForeColor = vbWhite
    33.     'End With
    34.    
    35.     'With Frame(4)
    36.     '    .BackColor = vbBlue
    37.     '    .ForeColor = vbWhite
    38.     'End With
    39.    
    40.     'With Frame(5)
    41.     '    .BackColor = vbBlue
    42.     '    .ForeColor = vbWhite
    43.     'End With
    44.    
    45.     'With Frame(6)
    46.     '    .BackColor = vbBlue
    47.     '    .ForeColor = vbWhite
    48.     'End With
    49. End Sub

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Condense code...

    You can loop through control array (sample below) or controls collection (if you don't have control array):
    VB Code:
    1. Dim i%
    2.  
    3. On Error Resume Next
    4.  
    5. For i = Frame.Lbound To Frame.Ubound
    6.     Frame(i).BackColor = vbBlue
    7.     Frame(i).ForeColor = vbWhite
    8. Next i

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Condense code...

    Quote Originally Posted by BrailleSchool
    Hi, how would you condense this into on with instead of multiple due to them all having the same values but different number? . . .
    I think this is what you want:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim a as Long
    3.  
    4.     Call Button_Captions
    5.     Call Label_Captions
    6.    
    7.     Me.BackColor = vbBlue
    8.        
    9.      With Frame
    10.            For a = .LBound to .UBound    
    11.                 With .Item(a)
    12.                      .BackColor = vbBlue
    13.                      .ForeColor = vbWhite
    14.                 End With
    15.            Next a '<==== Edit  :blush:  :blush:
    16.      End With
    17. End Sub
    Last edited by Mark Gambo; Nov 8th, 2005 at 12:25 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Condense code...

    Rats, you beat me again!!!!!!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Condense code...

    I'll be a jerk and point out that
    VB Code:
    1. With Frame(intFrame)
    2.      .BackColor = vbBlue
    3.      .ForeColor = vbWhite
    4. End With

    is more lines than
    VB Code:
    1. Frame(intFrame).BackColor = vbBlue
    2. Frame(intFrame).ForeColor = vbWhite


  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Condense code...

    Quote Originally Posted by Mark Gambo
    I think this is what you want:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim a as Long
    3.  
    4.     Call Button_Captions
    5.     Call Label_Captions
    6.    
    7.     Me.BackColor = vbBlue
    8.        
    9.      With Frame
    10.            For a = .LBound to .UBound    
    11.                 With .Item(a)
    12.                      .BackColor = vbBlue
    13.                      .ForeColor = vbWhite
    14.                 End With
    15.      End With
    16. End Sub
    Compile error:
    end with without with. (last end with -- interesting)

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Condense code...

    Quote Originally Posted by RhinoBull
    You can loop through control array (sample below) or controls collection (if you don't have control array):
    VB Code:
    1. Dim i%
    2.  
    3. On Error Resume Next
    4.  
    5. For i = Frame.Lbound To Frame.Ubound
    6.     Frame(i).BackColor = vbBlue
    7.     Frame(i).ForeColor = vbWhite
    8. Next i
    thanks for the sample Rhino. % is the same as a long right?

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Condense code...

    I'll be a bigger jerk and point out that

    VB Code:
    1. With Frame(intFrame)
    2.      .BackColor = vbBlue
    3.      .ForeColor = vbWhite
    4. End With

    requires only 61 characters

    VB Code:
    1. Frame(intFrame).BackColor = vbBlue
    2. Frame(intFrame).ForeColor = vbWhite

    While requires 65 characters (including spaces)

    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Condense code...

    % are integers. ! are longs.
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  10. #10
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Condense code...

    Quote Originally Posted by BrailleSchool
    Compile error:
    end with without with. (last end with -- interesting)

    ah, I forgot the "Next A", I'll fix my code and it will work now. That's what I get when I don't test my code before posting.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Condense code...

    Quote Originally Posted by RhinoBull
    You're welcome.
    % is a shortcut for Integer. When it comes to Control Arrays - Integer type is more than enough.
    Learn something new every day! love shortcuts. will have to go to MSDN online to see if i can read up about this stuff. would rather type on char instead of the whole darned thing.

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Condense code...

    Quote Originally Posted by chemicalNova
    % are integers. ! are longs.
    chem
    Sorry, but second type is wrong:
    ! - Single

    To find out more run ths sample:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim var1%, var2&, var3#, var4!, var5@, var6$, var7, var8 As Object
    3.  
    4.     Debug.Print "var1: " & TypeName(var1)
    5.     Debug.Print "var2: " & TypeName(var2)
    6.     Debug.Print "var3: " & TypeName(var3)
    7.     Debug.Print "var4: " & TypeName(var4)
    8.     Debug.Print "var5: " & TypeName(var5)
    9.     Debug.Print "var6: " & TypeName(var6)
    10.     Debug.Print "var7: " & TypeName(var7)
    11.     Debug.Print "var8: " & TypeName(var8)
    12.  
    13. End Sub

  14. #14
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Condense code...

    Quote Originally Posted by BrailleSchool
    Learn something new every day! love shortcuts. will have to go to MSDN online to see if i can read up about this stuff. would rather type on char instead of the whole darned thing.
    LOL... I wouldn't recommend to use it too often - only "old timers" may recognize these symbols - all "new commers" will get lost and frustrated, though.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Condense code...

    Quote Originally Posted by RhinoBull
    LOL... I wouldn't recommend to use it too often - only "old timers" may recognize these symbols - all "new commers" will get lost and frustrated, though.
    i would rather be an "old timer" than wear my keyboard out lol. anyway, i am old, im almos 30. lol.

  16. #16

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Condense code...

    Quote Originally Posted by RhinoBull
    Sorry, but second type is wrong:
    ! - Single

    To find out more run ths sample:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim var1%, var2&, var3#, var4!, var5@, var6$, var7, var8 As Object
    3.  
    4.     Debug.Print "var1: " & TypeName(var1)
    5.     Debug.Print "var2: " & TypeName(var2)
    6.     Debug.Print "var3: " & TypeName(var3)
    7.     Debug.Print "var4: " & TypeName(var4)
    8.     Debug.Print "var5: " & TypeName(var5)
    9.     Debug.Print "var6: " & TypeName(var6)
    10.     Debug.Print "var7: " & TypeName(var7)
    11.     Debug.Print "var8: " & TypeName(var8)
    12.  
    13. End Sub
    made a small app with this info so i dont forget. enclosed for all us young-timers lol

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