Results 1 to 2 of 2

Thread: [2005] Advice on best method for null checking multiple items depending on the value

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    1

    Unhappy [2005] Advice on best method for null checking multiple items depending on the value

    Hello everyone,

    I am new to this forum, and glad I found this place as I have been browsing the forums and found some very interesting topics. I do have a question on some coding that I cannot figure out no matter how many times I sit and think about it.

    I am using Visual Basic 2005 - Express Edition. I learned Visual Basic (before .net) along time ago, but never completed the full course. I know I need to finish it, and would like to learning more advanced .NET stuff.

    Brief over view of my application: My Application is just a small tool bar for work that will hold our most used applications so that we quickly access them instead of having to search all over the place for them. There is an 'Application Administration' dialog which has five tabs (One for each application button). The user can enable or disable each application button as they see the need to.

    What I need is to check each tab to see if:
    A) chkEnableApp1.checked = True & if so, check to see if:
    a.) txtApp1Name.text = "", if so: prompt with message box
    b.) txtApp1Location.text = "", if so: prompt with message box

    if a.) & b.) are not blank, then check to see on the same tab if chkEnableSApp1.checked = true & if so, check to see if:
    a.) txtSapp1Name.Text = "", if so: prompt with message box
    b.) txtSapp1Location.text = "", if so: prompt with message box

    If none of those boxes are blank, then check next tab, until all five application tabs have been checked. Once they are error free, call SBAppLauncherSaveSettings.



    Sorry, I hope this all makes sense to everyone.

    I have tried searching google multiple times, and this forum a few times.
    This seems like it might help, http://www.vbforums.com/showthread.p...iple+textboxes
    but I am not sure.

    I also tried using:
    VB Code:
    1. if chkEnableApp1.Checked = True then
    2.      if txtApp1Name.Text = "" Then
    3.           txtApp1Name.Focus()
    4.           MsgBox("Error. Application one is not named.")
    5.      elseif txtApp1Location.Text = "" Then
    6.           txtApp1Location.Focus()
    7.           MsgBox("Error. Application one has no location.")
    8.      end if
    9. elseif chkEnableSApp1.Checked = True then
    10.      if txtSapp1Name.Text = "' then
    11.          txtSApp1Name.focus()
    12.          MsgBox("Error. Sub Application one is not named.")
    13.     elseif txtSApp1Location.Text = "" then
    14.          txtSapp1Location.focus()
    15.          MsgBox("Error. Sub Application one has no location.")
    16.    end if
    17. elseif .... etc..

    It never goes past the first inner if then else statement because the outer if then else statement is still true, so no need to continue to check and see about the rest. Maybe I am just not thinking fully today. I hope someone can shed some light on this and point me in the right direction.

    Thanks very much,
    Kei
    Last edited by kurashima; Jan 7th, 2007 at 02:47 PM. Reason: Edited Subject for hopefully a responce. Old subject seemed to basic for what I am asking.

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] Advice on best method for null checking multiple items depending on the value

    I think you were intending the following...

    VB Code:
    1. If chkEnableApp1.Checked Then
    2.             If txtApp1Name.Text = "" Then
    3.                 txtApp1Name.Focus()
    4.                 MsgBox("Error. Application one is not named.")
    5.             ElseIf txtApp1Location.Text = "" Then
    6.                 txtApp1Location.Focus()
    7.                 MsgBox("Error. Application one has no location.")
    8.             ElseIf chkEnableSApp1.Checked Then
    9.                 If txtSapp1Name.Text = "" Then
    10.                     txtSApp1Name.focus()
    11.                     MsgBox("Error. Sub Application one is not named.")
    12.                 ElseIf txtSApp1Location.Text = "" Then
    13.                     txtSapp1Location.Focus()
    14.                     MsgBox("Error. Sub Application one has no location.")
    15.                 End If
    16.             End If
    17.         End If
    It would be better to setup an array of controls, you could then cycle through the groups of controls on each tab using a For loop (less code).
    That would then end up something like this...
    VB Code:
    1. For i = 0 To NumberofTabs - 1
    2.             If chkApp(i).Checked Then
    3.                 If txtAppName(i).Text = "" Then
    4.                     txtAppName(i).Focus()
    5.                     MsgBox("Error. Application " & i.ToString & " is not named.")
    6.                 ElseIf txtAppLocation(i).Text = "" Then
    7.                     txtAppLocation(i).Focus()
    8.                     MsgBox("Error. " & txtAppName(i) & " has no location.")
    9.                 ElseIf chkEnableSApp(i).Checked Then
    10.                     If txtSappName(i).Text = "" Then
    11.                         txtSAppName(i).focus()
    12.                         MsgBox("Error. Sub Application " & i.ToString & " is not named.")
    13.                     ElseIf txtSAppLocation(i).Text = "" Then
    14.                         txtSappLocation(i).Focus()
    15.                         MsgBox("Error. " & txtSappName(i) & " has no location.")
    16.                     End If
    17.                 End If
    18.             End If
    19.         Next

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