none
BC2012 Error RRS feed

  • Question

  • It took me awhile, but I finally tracked down what this error is, and allegedly, what it takes to fix it.

    So, I attempted to run the following lines of code (the underlined, line is the one I believe the error comes from):

                _strError = "subLogin, ApproveLogin() routine" +
                vbNewLine +
                "You have " & _intLoop & "tries left before lockout."
                AccessDenied1008()

    What I got was the compiling error BC2012

    I did a little looking and it appears that VB does not like & and wants me to replace it with {0}.  OK, so I followed the instructions I found for doing so and came up with the following line to replace the one above:

    "You have {0}," _intLoop {0}, " tries left before lockout."

    I do not even have to run the application to see that it is incorrect. _intLoop is a class integer variable.  Can anyone tell me what I should be doing here?

    All I want to do is add the line to an error message telling the user that they have X tries left to login.


    gwboolean

    Sunday, September 24, 2017 9:51 PM

Answers

  • OK, I have done a little more work on this and I have figured out that this is used for a console WriteLine, which requires a Imports System.Console.

    A console write is not what I have in mind at all.  All I want is to put together a string that tells a user how many attempts he has left for a login.  So again, can anyone help me to understand what I can and cannot do here?


    gwboolean

    Hi

    Is this what you want?

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim _intLoop As Integer = 123
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim _strError As String = "subLogin, ApproveLogin() routine" & vbLf & "You have " & _intLoop.ToString & " tries left before lockout."
    
            '  _strError now contains
    
            '  subLogin, ApproveLogin() routine
            '  You have 123 tries left before lockout.
        End Sub
    


    Regards Les, Livingston, Scotland

    • Marked as answer by gwboolean Sunday, September 24, 2017 11:10 PM
    Sunday, September 24, 2017 10:25 PM

All replies

  • & is the concatenation symbol in VB not the +
    Sunday, September 24, 2017 10:02 PM
  • OK, I have done a little more work on this and I have figured out that this is used for a console WriteLine, which requires a Imports System.Console.

    A console write is not what I have in mind at all.  All I want is to put together a string that tells a user how many attempts he has left for a login.  So again, can anyone help me to understand what I can and cannot do here?


    gwboolean

    Sunday, September 24, 2017 10:02 PM
  • OK, I have done a little more work on this and I have figured out that this is used for a console WriteLine, which requires a Imports System.Console.

    A console write is not what I have in mind at all.  All I want is to put together a string that tells a user how many attempts he has left for a login.  So again, can anyone help me to understand what I can and cannot do here?


    gwboolean

    Hi

    Is this what you want?

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim _intLoop As Integer = 123
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim _strError As String = "subLogin, ApproveLogin() routine" & vbLf & "You have " & _intLoop.ToString & " tries left before lockout."
    
            '  _strError now contains
    
            '  subLogin, ApproveLogin() routine
            '  You have 123 tries left before lockout.
        End Sub
    


    Regards Les, Livingston, Scotland

    • Marked as answer by gwboolean Sunday, September 24, 2017 11:10 PM
    Sunday, September 24, 2017 10:25 PM
  • OK, I have done a little more work on this and I have figured out that this is used for a console WriteLine, which requires a Imports System.Console.

    There is no need for the change you made. Ampersand is the concatenation character in VB .Net

    _strError = "subLogin, ApproveLogin() routine" & vbNewLine & "You have " & _intLoop.ToString & "tries left before lockout."

    If that is creating an error for you then you need to show the full error message and the values of the variables at the time the error occurs.   BC2012 has nothing to do with that line of code.

    Sunday, September 24, 2017 10:29 PM
  • Les,

    I see.  That should get the job done.  I notice that Option Explicit is ON.  I usually, and currently, have that set to OFF.  I have no idea why, it is just the way someone once told me to roll.  I will turn that on and I am sure that it will help.


    gwboolean

    So how are things going for the retired in Scotland?  Certainly I am not suffering being retired here (the US).  Although in our political climate that looks to be something that is going to dramatically change soon.
    • Edited by gwboolean Sunday, September 24, 2017 11:10 PM
    Sunday, September 24, 2017 11:08 PM
  • Les,

    I see.  That should get the job done.  I notice that Option Explicit is ON.  I usually, and currently, have that set to OFF.  I have no idea why, it is just the way someone once told me to roll.  I will turn that on and I am sure that it will help.


    gwboolean

    So how are things going for the retired in Scotland?  Certainly I am not suffering being retired here (the US).  Although in our political climate that looks to be something that is going to dramatically change soon.

    Hi

    I can't complain myself, though I know of many others who would :)

    The Option Explicit On (and especially Option Strict On) are useful in helping to create code that runs smoothly. My use is always Option Strict On and Option Explicit On (for Option Infer, see Frank or Cor for arguments for and against)

    For example, where you have '

    ......."You have " & _intLoop & "trie.......

    intLoop is an Integer and would have been flagged using those Options to force you to make it a string.


    Regards Les, Livingston, Scotland



    • Edited by leshay Sunday, September 24, 2017 11:31 PM
    Sunday, September 24, 2017 11:28 PM