|
-
Nov 8th, 2005, 12:04 AM
#1
Thread Starter
PowerPoster
[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:
Private Sub Form_Load()
Call Button_Captions
Call Label_Captions
Me.BackColor = vbBlue
'THIS DOESNT WORK SO PROBABLY GOING WRONG SOMEWHERE. WANT
'TO CONDENSE THE ONES BELOW INTO ONE INSTEAD OF MULTIPLE.
Dim intFrame As Integer
With Frame(intFrame)
.BackColor = vbBlue
.ForeColor = vbWhite
End With
'With Frame(0)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(1)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(2)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(3)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(4)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(5)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
'With Frame(6)
' .BackColor = vbBlue
' .ForeColor = vbWhite
'End With
End Sub
Last edited by BrailleSchool; Nov 8th, 2005 at 12:58 AM.
-
Nov 8th, 2005, 12:12 AM
#2
Re: Condense code...
You can loop through control array (sample below) or controls collection (if you don't have control array):
VB Code:
Dim i%
On Error Resume Next
For i = Frame.Lbound To Frame.Ubound
Frame(i).BackColor = vbBlue
Frame(i).ForeColor = vbWhite
Next i
-
Nov 8th, 2005, 12:13 AM
#3
Re: Condense code...
 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:
Private Sub Form_Load()
Dim a as Long
Call Button_Captions
Call Label_Captions
Me.BackColor = vbBlue
With Frame
For a = .LBound to .UBound
With .Item(a)
.BackColor = vbBlue
.ForeColor = vbWhite
End With
Next a '<==== Edit :blush: :blush:
End With
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."
-
Nov 8th, 2005, 12:14 AM
#4
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."
-
Nov 8th, 2005, 12:16 AM
#5
Hyperactive Member
Re: Condense code...
I'll be a jerk and point out that
VB Code:
With Frame(intFrame)
.BackColor = vbBlue
.ForeColor = vbWhite
End With
is more lines than
VB Code:
Frame(intFrame).BackColor = vbBlue
Frame(intFrame).ForeColor = vbWhite
-
Nov 8th, 2005, 12:21 AM
#6
Thread Starter
PowerPoster
Re: Condense code...
 Originally Posted by Mark Gambo
I think this is what you want:
VB Code:
Private Sub Form_Load()
Dim a as Long
Call Button_Captions
Call Label_Captions
Me.BackColor = vbBlue
With Frame
For a = .LBound to .UBound
With .Item(a)
.BackColor = vbBlue
.ForeColor = vbWhite
End With
End With
End Sub
Compile error:
end with without with. (last end with -- interesting)
-
Nov 8th, 2005, 12:23 AM
#7
Thread Starter
PowerPoster
Re: Condense code...
 Originally Posted by RhinoBull
You can loop through control array (sample below) or controls collection (if you don't have control array):
VB Code:
Dim i%
On Error Resume Next
For i = Frame.Lbound To Frame.Ubound
Frame(i).BackColor = vbBlue
Frame(i).ForeColor = vbWhite
Next i
thanks for the sample Rhino. % is the same as a long right?
-
Nov 8th, 2005, 12:24 AM
#8
Re: Condense code...
I'll be a bigger jerk and point out that
VB Code:
With Frame(intFrame)
.BackColor = vbBlue
.ForeColor = vbWhite
End With
requires only 61 characters
VB Code:
Frame(intFrame).BackColor = vbBlue
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."
-
Nov 8th, 2005, 12:24 AM
#9
Re: Condense code...
% are integers. ! are longs.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Nov 8th, 2005, 12:25 AM
#10
Re: Condense code...
 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."
-
Nov 8th, 2005, 12:25 AM
#11
Re: Condense code...
 Originally Posted by BrailleSchool
thanks for the sample Rhino. % is the same as a long right?
You're welcome.
% is a shortcut for Integer. When it comes to Control Arrays - Integer type is more than enough.
-
Nov 8th, 2005, 12:27 AM
#12
Thread Starter
PowerPoster
Re: Condense code...
 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.
-
Nov 8th, 2005, 12:28 AM
#13
Re: Condense code...
 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:
Private Sub Command1_Click()
Dim var1%, var2&, var3#, var4!, var5@, var6$, var7, var8 As Object
Debug.Print "var1: " & TypeName(var1)
Debug.Print "var2: " & TypeName(var2)
Debug.Print "var3: " & TypeName(var3)
Debug.Print "var4: " & TypeName(var4)
Debug.Print "var5: " & TypeName(var5)
Debug.Print "var6: " & TypeName(var6)
Debug.Print "var7: " & TypeName(var7)
Debug.Print "var8: " & TypeName(var8)
End Sub
-
Nov 8th, 2005, 12:30 AM
#14
Re: Condense code...
 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.
-
Nov 8th, 2005, 12:36 AM
#15
Thread Starter
PowerPoster
Re: Condense code...
 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.
-
Nov 8th, 2005, 12:39 AM
#16
Re: Condense code...
Yea, sounds like old and it's OK with me. Use TypeName() if you ever need to find type of your variable (see sample code in one of my previous posts).
-
Nov 8th, 2005, 01:17 AM
#17
Thread Starter
PowerPoster
Re: Condense code...
 Originally Posted by RhinoBull
Sorry, but second type is wrong:
! - Single
To find out more run ths sample:
VB Code:
Private Sub Command1_Click()
Dim var1%, var2&, var3#, var4!, var5@, var6$, var7, var8 As Object
Debug.Print "var1: " & TypeName(var1)
Debug.Print "var2: " & TypeName(var2)
Debug.Print "var3: " & TypeName(var3)
Debug.Print "var4: " & TypeName(var4)
Debug.Print "var5: " & TypeName(var5)
Debug.Print "var6: " & TypeName(var6)
Debug.Print "var7: " & TypeName(var7)
Debug.Print "var8: " & TypeName(var8)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|