Results 1 to 2 of 2

Thread: [RESOLVED] How to optimize this?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [RESOLVED] How to optimize this?

    Hi i have this code:
    VB Code:
    1. Private Sub Done_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Done.Click
    2.         ErrN.Dispose()
    3.         ErrC.Dispose()
    4.         Dim Err As Boolean = True
    5.         If Titulo.Text.Length = 0 Then
    6.             ErrN.SetError(Titulo, "Tem que inserir um nome!")
    7.             Err = False
    8.         End If
    9.         If M1.Text.Length = 0 Then
    10.             ErrN.SetError(M1, "Tem que inserir um nome!")
    11.             Err = False
    12.         End If
    13.         If C1.SelectedIndex <> -1 And M1.Text.Length = 0 Then
    14.             ErrN.SetError(M1, "Tem que inserir um nome!")
    15.             Err = False
    16.         End If
    17.         If C2.SelectedIndex <> -1 And M2.Text.Length = 0 Then
    18.             ErrN.SetError(M2, "Tem que inserir um nome!")
    19.             Err = False
    20.         End If
    21.         If C3.SelectedIndex <> -1 And M3.Text.Length = 0 Then
    22.             ErrN.SetError(M3, "Tem que inserir um nome!")
    23.             Err = False
    24.         End If
    25.        
    26.         If M1.Text.Length > 0 And C1.SelectedIndex = -1 Then
    27.             ErrC.SetError(C1, "Tem que selecionar um modo!")
    28.             Err = False
    29.         End If
    30.         If M2.Text.Length > 0 And C2.SelectedIndex = -1 Then
    31.             ErrC.SetError(C2, "Tem que selecionar um modo!")
    32.             Err = False
    33.         End If
    34.         If M3.Text.Length > 0 And C3.SelectedIndex = -1 Then
    35.             ErrC.SetError(C3, "Tem que selecionar um modo!")
    36.             Err = False
    37.         End If
    38.        
    39.         If Err = True Then
    40.             'If any error occurs then...
    41.         End If
    42.     End Sub
    Can this be done in a simplier way like with less lines?
    Last edited by Lasering; May 5th, 2007 at 12:33 PM.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

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