need VB.Net help

Discussion in 'OT Technology' started by ManinCamo, Mar 26, 2004.

  1. ManinCamo

    ManinCamo I wear big boy pants.

    Joined:
    Jul 5, 2001
    Messages:
    4,670
    Likes Received:
    0
    Location:
    '01 OG
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    A good rule of thumb is that after every ELSE statement, you have to END IF right after you're done. So:

    Code:
             If Branch = "A" Then
                    branchout = "Army"
                    USA = USA + 1
                    If Rank = "P" Then
                        rankout = "Private"
                    ElseIf Rank = "L" Then
                        rankout = "Lieutenant"
                        Lt = Lt + 1
                    Else
                        rankout = "INVALID"
                        sw.WriteLine("Error in Rank Code")
                        errmsg = "Error in Record"
    
                        If Branch = "N" Then
                            branchout = "Navy"
                            USN = USN + 1
                            If Rank = "E" Then
                                rankout = "Ensign"
                                Ens = Ens + 1
                            ElseIf Rank = "C" Then
                                rankout = "Captain"
                                Capt = Capt + 1
                            Else
                                rankout = "INVALID"
                                sw.WriteLine("Error in Rank Code")
                                errmsg = "Error in Record"
    should be:

    Code:
        If Branch = "A" Then
               branchout = "Army"
               USA = USA + 1
               If Rank = "P" Then
                   rankout = "Private"
               ElseIf Rank = "L" Then
                   rankout = "Lieutenant"
                   Lt = Lt + 1
               Else
                   rankout = "INVALID"
                   sw.WriteLine("Error in Rank Code")
                   errmsg = "Error in Record"
               End If
        ElseIf Branch = "N" Then
               branchout = "Navy"
                   USN = USN + 1
                   If Rank = "E" Then
                       rankout = "Ensign"
                       Ens = Ens + 1
                   ElseIf Rank = "C" Then
                       rankout = "Captain"
                       Capt = Capt + 1
                   Else
                       rankout = "INVALID"
                       sw.WriteLine("Error in Rank Code")
                       errmsg = "Error in Record"
                   End If
        ElseIf ....
    Personally I prefer the Select statement over a number of If and ElseIf statements:

    Select Case Branch

    Case "N"

    Navyshit...

    Case "A"

    Armyshit...

    Case Else

    Other shit or reject

    End Select
     
    Last edited: Mar 26, 2004
  3. Spiral Out

    Spiral Out Active Member

    Joined:
    Mar 30, 2002
    Messages:
    12,287
    Likes Received:
    0
    Location:
    Florida
    Something like this...

    Code:
       If Branch = "A" Then
       		branchout = "Army"
       		USA = USA + 1
       		If Rank = "P" Then
       			 rankout = "Private"
       		ElseIf Rank = "L" Then
       			 rankout = "Lieutenant"
       			 Lt = Lt + 1
       		Else
       			 rankout = "INVALID"
       			 sw.WriteLine("Error in Rank Code")
       			 errmsg = "Error in Record"
       		End If
       ElseIf Branch = "N" Then
       	branchout = "Navy"
       		USN = USN + 1
       		If Rank = "E" Then
       		   rankout = "Ensign"
       		   Ens = Ens + 1
       		ElseIf Rank = "C" Then
       		   rankout = "Captain"
       		   Capt = Capt + 1
       		Else
       		   rankout = "INVALID"
       		   sw.WriteLine("Error in Rank Code")
       		   errmsg = "Error in Record"
       	End If
       ElseIf Branch = "F" Then
       		branchout = "AirForce"
       		USAF = USAF + 1
       		If Rank = "A" Then
       		   rankout = "Airman"
       		ElseIf Rank = "M" Then
       		   rankout = "Major"
       		   Maj = Maj + 1
       		Else
       		   rankout = "INVALID"
       		   sw.WriteLine("Error in Rank Code")
       		   errmsg = "Error in Record"
       	End If
       ElseIf Branch = "M" Then
       	   branchout = "Marines"
       	   USMC = USMC + 1
       	   If Rank = "G" Then
       		   rankout = "General"
       		   Gen = Gen + 1
       	   ElseIf Rank = "C" Then
       		   rankout = "Colonel"
       		   Col = Col + 1
       	   Else
       		   rankout = "INVALID"
       		   sw.WriteLine("Error in Rank Code")
       		   errmsg = "Error in Record"
       	End If
       End If
     
  4. ManinCamo

    ManinCamo I wear big boy pants.

    Joined:
    Jul 5, 2001
    Messages:
    4,670
    Likes Received:
    0
    Location:
    '01 OG
    thanks guys, i figured out the structer portion of that right before i checked back here, and what you guys suggested works great for the second part of the text box, which is all the counters and whatnot...

    I'm still having trouble with the first listbox, which lists the personel name, branch, rank, status, length of service, and error message..... it will list ONE item, and its not the first, or the last...


    [​IMG]


    i know the alignment is off bad, i'm not worried about that right now, i will fix that after i get the program working
     
  5. ManinCamo

    ManinCamo I wear big boy pants.

    Joined:
    Jul 5, 2001
    Messages:
    4,670
    Likes Received:
    0
    Location:
    '01 OG
    [​IMG]

    here's a more readable copy of the the output. I need the list all the personel in the file, not just what. someone want to take a look over my code again and see if they can find the error?

    I appreciate the help guys thanks, :)
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    lst1 line at the bottom should be above the loop command for starters
     
  7. ManinCamo

    ManinCamo I wear big boy pants.

    Joined:
    Jul 5, 2001
    Messages:
    4,670
    Likes Received:
    0
    Location:
    '01 OG

    :bowdown: :bowdown: :bowdown: :bowdown: :bowdown: :bowdown: :bowdown:


    always helps to have a second set of eyes look at it.

    that fixed it.


    one LAST thing...

    i need to filter the years of service to <=7, >=14 and have it say invalid if its outside the criteria.

    how do I go about doing that?
     
  8. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Code:
    If service <=7 or service >= 14 then
         okay
    else
         not okay
    end if
    or

    Code:
    if service >7 and service <14 then
         not okay
    else
         okay
    end if
    I'm guessing you DON'T want people who have served between 8 and 13 years right?
     

Share This Page