Results 1 to 8 of 8

Thread: How to Skip code with a If Then Else

  1. #1

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Question

    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



  2. #2
    Lively Member
    Join Date
    Mar 2000
    Posts
    87
    Not sure exactly what you are after.

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Under what condition do you need to skip these lines of code???
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    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
    Dim

  5. #5
    Guest
    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

  6. #6
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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)
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  7. #7

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Smile k

    Thank you all, i got it now

  8. #8

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Question ?

    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

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