dcsimg
Results 1 to 8 of 8

Thread: *ThisLine* Variable??

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    11

    *ThisLine* Variable??

    Hi all!,
    Sorry if this has already been asked, Im honestly not sure what to search for, i can't seem to express to google exactly what it is im looking for....
    As a total amateur coder, im not sure this is traditional but i use messageboxes to help me in bug tracking , so i can tell where the program is in its runtime. I usually say something to the effect of:

    MessageBox.Show("This is where we at", "ClassName.vb, Line: 14")

    as it gives me a pretty clear explanation of what the me from the past wanted to warn me about, and where to find the specific place in code... but of course, lines changes thru the build evolution. What i wonder is, is there a variable i can use that means "THIS LINE" like if i put it on line 23 it will return to me simply an integer value of 23

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    11

    Re: *ThisLine* Variable??

    Awesome, much appreciated... looks like that'll do it, though i am a bit surprised that there isnt a MUCH simpler way to go about it, on account that the built in debugger gives you the line info when it finds a break/error

  4. #4
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,013

    Re: *ThisLine* Variable??

    If you are catching the exception in a Try block, you can simply call the exception.ToString and it will return just about everything relevant, including the vbline
    Code:
    Try
        'FAIL
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,431

    Re: *ThisLine* Variable??

    Quote Originally Posted by ziro View Post
    Awesome, much appreciated... looks like that'll do it, though i am a bit surprised that there isnt a MUCH simpler way to go about it, on account that the built in debugger gives you the line info when it finds a break/error
    It's more complicated due to the way the code compiles when you run it...

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,757

    Re: *ThisLine* Variable??

    Quote Originally Posted by ziro View Post
    i am a bit surprised that there isnt a MUCH simpler way to go about it, on account that the built in debugger gives you the line info when it finds a break/error
    What makes you think that the way the debugger gets that info is any simpler?

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    11

    Re: *ThisLine* Variable??

    Nothing, as i said, it just surprises me. Anyways this seems simpler:

    MessageBox.Show("Stuff", "Class.vb" & New StackFrame(True).GetFileLineNumber)

    But i would like to know if there is a reason that i shouldn't use this, i know that a lot of times there are somewhat 'hidden' things happening when amateur coding

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,757

    Re: *ThisLine* Variable??

    That would be exactly how the attribute does it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width