dcsimg
Results 1 to 13 of 13

Thread: New to VB.Net

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    37

    New to VB.Net

    I'm slowly finding my way around VB.Net, but can't find how to do this:

    In Break mode in VB6 you can step through the code by pressing f8. Also there was an Immediate box where you could ask the value of a variable or do a calculation.

    Are these possible in VB.Net?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,914

    Re: New to VB.Net

    It's pretty much exactly the same. Depending on how you configured VS when you installed it, you may need to use F10 to step through your code. There will be corresponding items on the toolbar and in the main menu and they will tell you what the keyboard shortcut is. As for the Immediate window, it should be displayed at the bottom of the IDE by default when you're debugging but you can open it from the main menu if it's not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    37

    Re: New to VB.Net

    f10 works. Thanks
    I found an immediate window under Debug>Windows, but when I use it, I get this:

    ? HasPicture(1)
    Unable to evaluate the expression.
    Print 2 * 12
    Unable to evaluate the expression.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,914

    Re: New to VB.Net

    If you wanted to evaluate 2 * 12 and display the result in the Immediate window, I just tried:
    Code:
    ?2*12
    and it worked for me. I don't know what HasPicture(1) should do but maybe it's not valid in the current context. I just tried:
    Code:
    ?controls(0)
    and it output all the relevant information for the Button I added to my form. I'm not sure why you wouldn't see similar results.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    37

    Re: New to VB.Net

    It works with the question mark but not with 'Print'

    Print 2*2
    error BC30800: Method arguments must be enclosed in parentheses.

    Print (2*2)
    'Print (2*2)' threw an exception of type 'System.IO.IOException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146232800
    HelpLink: Nothing
    InnerException: Nothing
    Message: "Bad file name or number."
    Source: "Microsoft.VisualBasic"
    StackTrace: " at Microsoft.VisualBasic.FileSystem.Print(Int32 FileNumber, Object[] Output)"
    TargetSite: {Void Print(Int32, System.Object[])}

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

    Re: New to VB.Net

    Quote Originally Posted by PaMarn View Post
    It works with the question mark but not with 'Print'
    That would suggest that you should use a question mark. Maybe it would be a good idea to read up on how the Immediate window works in VS nowadays rather than assuming that it will work exactly as it did in VB6. It's obviously very similar but it's unlikely to be exactly the same.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,455

    Re: New to VB.Net

    When you type in Print( intellisense should show you the method it is going to call. In this case it would be the Print that expects a Filenumber and Output.
    VB.Net is very object oriented compared to VB6, so where the immediate window had a print statement associated with the window itself, VB.Net doesn't. You are calling a Print method of some class that will be executed and the result displayed in the immediate window.
    If you are at a breakpoint in your code, then objects that are in scope at the point you can use Debug.Print to display information, but even this isn't like the VB6.Print. The print is part of the debug class, and you may need to be more specific about what you want to print, and how it is formatted.

    The ? operation is a special operation of the immediate window and you can think of it not so much as equivalent to Print, but more of a request to inspect the object.

    If you're at a break in a running program and do the following
    ? Button1
    then you get a long list of all the top level properties of the button.
    If you do
    Debug.Print(Button1)
    Then you may get something, or not depending on your settings.
    I always have Option Strict and Option Explicit On by default, so I'll get an error saying that the Debug.Print method can't convert the Button1 object into a string.

    So, I can specify I want it converted to a string
    Debug.Print(Button1.ToString)
    and it will print out
    System.Windows.Forms.Button, Text: Button1
    i.e. Giving me the type of the object and the value of its Text property

    If you didn't have Option Strict On, then VB would automatically assume that you want to call the ToString method on the object since Debug.Print needs a string to print, so would work without complaining.

    Normally you should have Option Strict On, and be explicit about what you're doing rather than have VB making assumptions for you.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,138

    Re: New to VB.Net

    You'll also want to see the difference between F10 and F11. F10 steps over methods, while F11 steps into them. That can be a great convenience, either way, depending on what you want to do.

    I never use the Immediate window, myself. It's just one of those things, these days. There are multiple ways to accomplish nearly anything anymore. Rather than the Immediate window, I tend to use Shift+F9 for everything. Normally, I click on an item, or highlight an expression or condition, then press Shift+F9, which shows you the item, the evaluation, or whatever, but it also has a textbox showing what you highlighted. You can type anything into that textbox, so it works kind of like the Immediate window without the ?.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    37

    Re: New to VB.Net

    Getting somewhere now (I think!)
    If You set a break point, then Shift-f9 will give you the information you need, but if you simply stop the program running with Ctr-Break you get a message: "... does not exist in the current context."
    Also, I can't seem to change the valuable of a variable in break mode. The box that comes up has only a single-line text area at the top. If X = 11, and I type in X = 12 and press 'Reevaluate', it tells me 'X = 12 is false' and X remains at 11.
    Last edited by PaMarn; Feb 22nd, 2018 at 06:11 AM.

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,455

    Re: New to VB.Net

    If you do a Ctrl-Break then it would be unlikely you would break in your code, but rather in a Net library or VB runtime library. If you executed a step at that point, you should end up somewhere in your code, if you had code running, i.e. a timer event or a background thread loop. If the step doesn't stop, then you have to cause an event, e.g. hit a button, and then the code would stop at the first executable line in that event. Then you would be able to look at stuff within your code that is visible in the context of the code you're stopped in.

    If you hit Shift F9 to examine a value, you should be able to click on the value line in the big box to highlight it blue. If you type in a value the value will be updated.
    To be clear, the Expression should be just a variable name e.g. HangState, and the value will be displayed below. You click on the displayed line and you can change the value. You could then type an expression, e.g. HangState = 3 and hit Enter, or the reevaluate button and it will display the value of the express below.

    Of course, I'm still used to using the Immediate Window so always have it displayed at the bottom, and I would just type in HangState = 2 in the immediate window to set it.
    I would likely then rightclick on a line in the code and select "Set Next Statement" if I wanted to step through a particular line again. You could also just click on the line and hit Ctrl-F9 to set Next Statement, but I don't have that sequence built into my muscle memory.
    Last edited by passel; Feb 22nd, 2018 at 08:40 AM.

  11. #11
    PowerPoster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,094

    Re: New to VB.Net

    Quote Originally Posted by PaMarn View Post
    I'm slowly finding my way around VB.Net, but can't find how to do this:

    In Break mode in VB6 you can step through the code by pressing f8. Also there was an Immediate box where you could ask the value of a variable or do a calculation.

    Are these possible in VB.Net?
    There is an option in tool, options, keyboard to use VB 6.0 settings. I have .Net set to "Visual Basic 6" because I'm in-between environments all day. I keeps the keyboard consistent at least.
    Please remember next time...elections matter!

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,138

    Re: New to VB.Net

    To explain what happened with X=12 and reevaluate: What shows up in that textbox is an expression to evaluate, not a command to execute. Therefore, X=12 doesn't cause X to be set to 12, it evaluates whether X does or does not equal 12. This is pretty convenient at times, though you obviously wanted something else in this particular case. What you can do with this is that, if you have some complex condition such as:

    If (x=12) AndAlso N Is Nothing AndAlso (v > 1 OrElse v<-20) Then

    and you found that the condition ended up being false, you might reasonably wonder why it was false. Therefore, you could highlight each part of the expression and use Shift+F9 to evaluate each part to find which part(s) were False. So, you could check X=12, N Is Nothing, and (v > 1 OrElse v <-20), to see which one(s) of these were False.
    My usual boring signature: Nothing

  13. #13

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    37

    Re: New to VB.Net

    Thanks again, guys! What would I do without you!

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


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.