none
vb.net 2012 elseif question RRS feed

  • Question

  • In a vb.net 2012 application I have the following code that works:    
    Protected _schoolyear As Integer
        Protected _schoolyearcheck As String   
        If (IsDBNull(_schoolyearcheck)) Or (Not IsNumeric(_schoolyearcheck)) Or CInt(_schoolyearcheck < 2000) Or (CInt(_schoolyearcheck) = _schoolyear) Then
                _schoolyear = _schoolyear
            ElseIf CInt(_schoolyearcheck) + 1 = _schoolyear Then
                _schoolyear = CInt(_schoolyearcheck)
            End If
    However the first if test  that has the line of     '_schoolyear = _schoolyear' if just a place holder. Basically at this point I want to not make it to the next elseif. The code is a placeholder.
    Can you tell me what vb.net statement that I can use that would be a placeholder that I can use?

    Friday, August 2, 2019 3:47 PM

Answers

  • Hi,

    Considering the small amount of code, you can use the GoTo statement to end the current If judgment. Jump directly to where you want to jump. Click the link above to see how to use GoTo.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/goto-statement

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 5, 2019 2:57 AM

All replies

  • Hi

    I have no idea what you are wanting.

    You say if the code execution reaches the line where _schoolyear = _schoolyear that you do not want it to execute the very next statement - the ElseIf - all that doesn't make sense as if the execution reaches that line, it would then skip the ElseIf and exit the loop.

    What is a 'place holder'?

    Might be an idea to say what you want to happen.


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, August 2, 2019 5:16 PM
    Friday, August 2, 2019 5:14 PM
  • The placeholder does nothing.  I just want to exit out of the elseif logic at that point.

    In C#, I would use the word 'continue'.

    Friday, August 2, 2019 6:21 PM
  • Just remove

    _schoolyear = _schoolyear


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Friday, August 2, 2019 6:26 PM
  • Maybe try this too:

       If Not ( the long condition . . . ) AndAlso CInt(_schoolyearcheck) + 1 = _schoolyear Then

          _schoolyear = CInt(_schoolyearcheck)

       End If

    Note that instead of CInt(_schoolyearcheck < 2000) you probably need CInt(_schoolyearcheck) < 2000.

    Friday, August 2, 2019 6:36 PM
  • Change your Or in OrElse that is shortcircuited, 

    Or is a boolean operator in VB for Net all are evaluated


    Success
    Cor

    Saturday, August 3, 2019 3:22 AM
  • Hi,

    Considering the small amount of code, you can use the GoTo statement to end the current If judgment. Jump directly to where you want to jump. Click the link above to see how to use GoTo.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/goto-statement

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 5, 2019 2:57 AM