-
is there anyway to skip a certin part of code with the If Then And Else Statement. i need to skip the following part of code
Dim f As Form, c As Control
' Get Form Object from Collection of Forms
For Each f In Forms
' Change Backcolor as form to a Random Color
f.BackColor = picBackcolor.BackColor
' Will loop through every kind of control currently on form
For Each c In f.Controls
' Determine is current control is a Label
If TypeOf c Is Label Then
'Change BackColor property to a Random Color
c.ForeColor = picFontcolor.BackColor
End If
Next c
Next f
-
Not sure exactly what you are after.
-
Under what condition do you need to skip these lines of code???
-
you didn't give us a condition at which you want to skip this code...so here is an example:
Code:
If Text1.Text = "Skip" Then
Exit Sub
Else
Dim f As Form, c As Control
' Get Form Object from Collection of Forms
For Each f In Forms
' Change Backcolor as form to a Random Color
f.BackColor = picBackcolor.BackColor
' Will loop through every kind of control currently on form
For Each c In f.Controls
' Determine is current control is a Label
If TypeOf c Is Label Then
'Change BackColor property to a Random Color
c.ForeColor = picFontcolor.BackColor
End If
Next c
Next f
End If
Hope that helps,
D!m
-
You can also d very naughty things with the infamous Goto statement, which allows you to jump to a label.
Not recommended, but it will work.
(I can't believe I just recommended using Goto :()
- gaffa
-
if you do use goto, you will find 500 vb coders knocking your door to beat then livin' **** out of you.
Gaffa, you lookin' for a slap or what ;-?
td.
(beer)
-
k
Thank you all, i got it now
-
?
ok here is the code for my entire form and when some one clicks the CANCEL button i need the form and label colors to go back to how they were before that form loaded.
Private Sub cmdApply_Click()
If (txtOwner.Text = "") And (txtName.Text = "") Then
frmMain.Caption = "Main"
Else
frmMain.Caption = txtName.Text + "-" + txtOwner.Text
End If
If (picBackcolor.BackColor = &H8000000F) And (picFontcolor.BackColor = &H8000000F) Then
Exit Sub
End If
Load frmAbout
Load frmCreateWrestler
Load frmEditWrestler
Load frmHelp
Load frmMain
Load frmOptions
Load frmWrestlerInfo
Dim f As Form, c As Control
' Get Form Object from Collection of Forms
For Each f In Forms
' Change Backcolor as form to a Random Color
f.BackColor = picBackcolor.BackColor
' Will loop through every kind of control currently on form
For Each c In f.Controls
' Determine is current control is a Label
If TypeOf c Is Label Then
'Change BackColor property to a Random Color
c.ForeColor = picFontcolor.BackColor
'Change BackStyle To Transparent
c.BackStyle = 0
End If
Next c
Next f
End Sub
Private Sub cmdCancel_Click()
Load frmAbout
Load frmCreateWrestler
Load frmEditWrestler
Load frmHelp
Load frmMain
Load frmOptions
Load frmWrestlerInfo
Dim f As Form, c As Control
' Get Form Object from Collection of Forms
For Each f In Forms
' Change Backcolor as form to a Random Color
f.BackColor = &H8000000F
' Will loop through every kind of control currently on form
For Each c In f.Controls
' Determine is current control is a Label
If TypeOf c Is Label Then
'Change BackColor property to a Random Color
c.ForeColor = &H404040
End If
Next c
Next f:
frmMain.Caption = "Main"
Unload Me
End Sub
Private Sub cmdOk_Click()
If (txtOwner.Text = "") And (txtName.Text = "") Then
frmMain.Caption = "Main"
Else
frmMain.Caption = txtName.Text + "-" + txtOwner.Text
End If
If (picBackcolor.BackColor = &H8000000F) And (picFontcolor.BackColor = &H8000000F) Then
Exit Sub
End If
Load frmAbout
Load frmCreateWrestler
Load frmEditWrestler
Load frmHelp
Load frmMain
Load frmOptions
Load frmWrestlerInfo
Dim f As Form, c As Control
' Get Form Object from Collection of Forms
For Each f In Forms
' Change Backcolor as form to a Random Color
f.BackColor = picBackcolor.BackColor
' Will loop through every kind of control currently on form
For Each c In f.Controls
' Determine is current control is a Label
If TypeOf c Is Label Then
'Change BackColor property to a Random Color
c.ForeColor = picFontcolor.BackColor
'Change BackStyle To Transparent
c.BackStyle = 0
End If
Next c
Next f
Unload Me
End Sub
Private Sub Form_Load()
frmMain.Caption = "":
Me.BackColor = picBackcolor.BackColor
End Sub
Private Sub picBackcolor_Click()
Dim CustomColours() As Byte
'Define array for custom colours.
ReDim CustomColours(0 To 15) As Byte
'Resize the array to hold the elements
Dim tChooseColour As CHOOSECOLOR
'Declare a user-defined variable for the ChooseColour
'type structure.
With tChooseColour
.hwndOwner = Me.hWnd
'Set the handle for the owner of the window.
.lpCustColors = StrConv(CustomColours, vbUnicode)
'Pass the custom colours array after converting
'it to Unicode using the StrConv function.
.flags = 0&
'For this sample, we do not need to use this.
.lStructSize = Len(tChooseColour)
'Set the size of the type structure
End With
If ShowColour(tChooseColour) = 0 Then Exit Sub
'Call the API function and display the ChooseColour
'Common Dialog box, and if the users clicks on cancel
'then the function will return 0.
picBackcolor.BackColor = tChooseColour.rgbResult
'Set the back colour of the form to the colour
'that the user selected.
End Sub
Private Sub picFontcolor_Click()
Dim CustomColours() As Byte
'Define array for custom colours.
ReDim CustomColours(0 To 15) As Byte
'Resize the array to hold the elements
Dim tChooseColour As CHOOSECOLOR
'Declare a user-defined variable for the ChooseColour
'type structure.
With tChooseColour
.hwndOwner = Me.hWnd
'Set the handle for the owner of the window.
.lpCustColors = StrConv(CustomColours, vbUnicode)
'Pass the custom colours array after converting
'it to Unicode using the StrConv function.
.flags = 0&
'For this sample, we do not need to use this.
.lStructSize = Len(tChooseColour)
'Set the size of the type structure
End With
If ShowColour(tChooseColour) = 0 Then Exit Sub
'Call the API function and display the ChooseColour
'Common Dialog box, and if the users clicks on cancel
'then the function will return 0.
picFontcolor.BackColor = tChooseColour.rgbResult
'Set the back colour of the form to the colour
'that the user selected.
End Sub