dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] Declare variable questioın...

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2015
    Location
    Earth
    Posts
    175

    Resolved [RESOLVED] Declare variable questioın...

    Hi beautiful people,
    Please look at this picture to understand my question.
    http://prntscr.com/8yvmb1
    Best regards

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,749

    Re: Declare variable questioın...

    Because you Declare (Dim) xlMailAccounts inside the With, EndWith block. After the EndWith it no longer exists.
    If you declared it on the line before the With line, it would exist until the end of the event handler sub.
    Just posting the code in the question would probably have been better than posting a link to an screen snapshot.

  3. #3

    Thread Starter
    Banned
    Join Date
    Oct 2015
    Location
    Earth
    Posts
    175

    Re: Declare variable questioın...

    Quote Originally Posted by passel View Post
    Because you Declare (Dim) xlMailAccounts inside the With, EndWith block.
    Hi passel,
    I know that.
    Why this issue is different than VBA?

  4. #4
    Junior Member
    Join Date
    Sep 2015
    Posts
    29

    Re: Declare variable questioın...

    It is because the variable xMailAccounts is declared inside the With and With End so it only functions inside there. If you want it to function outside of the loop you will need to declare the variable where ExcelApp is

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,732

    Re: Declare variable questioın...

    Quote Originally Posted by Herry Markowitz View Post
    Hi passel,
    I know that.
    Why this issue is different than VBA?
    Because they are completely different languages. It's like asking why you can't eat an orange peel but you can an apple skin... they're different.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,749

    Re: Declare variable questioın...

    Its actually an age old discussion (at least for the last 15 years or so) since VB.Net was first available in beta form.
    The nature of the language and the way it differs from VB6 is "extreme" enough that many in the Visual Basic community said it shouldn't have been called Visual Basic, but some new language and often referred to it as "Visual Fred".
    You can goggle Visual Fred to get some history.

    Bottom line, New Language...New Rules.

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Declare variable questioın...

    Quote Originally Posted by Herry Markowitz View Post
    Hi passel,
    I know that.
    Why this issue is different than VBA?
    You ask this question a lot. Almost every post you make has that in common: you are trying to write VB .NET as if it were VBA. That will only work so far.

    I'm not saying this because I think you are dumb, or a bad person. But the internet has a terrible tendency to just say "VB" as if all three things that currently count as VB are the same thing. They are not, and the varying levels of compatibility can be confusing. Think of it like the differences between French, the language with its origin in France, and "Cajun French", the language adopted by the Acadians who ultimately settled in South Louisiana. They're rooted in the same language, but the cultural histories are very different. While a French-speaker and a Cajun-speaker can communicate fairly well with each other, occasionally they have to stop and ask the other what a particular word means. There's several other similar-but-different languages, like Spanish and Portuguese. To be clear:
    • "Visual Basic" is a family of languages with a pedigree that stretches back to the 80s and beyond. Any language with a particular syntax is a "Visual Basic", so it's not specific enough to mean anything.
    • "VB6" is a Visual Basic language designed to make writing Windows applications easy, so long as "Windows" means everything roughly in the 98/ME/2000 timeframe. It needs its specific runtimes installed to operate, and is supported "as-is" on current Windows.
    • "VBA" is a scripting language used for Windows automation for the past few decades. It is based on the Visual Basic syntax. It's been integrated into many Microsoft products, and doesn't tend to be able to display UI without using one of those applications.
    • "VB .NET" is a Visual Basic language that runs on the .NET Framework. The .NET Framework is designed to facilitate pretty much all kinds of applications: GUI with WinForms/WPF, Windows 8/10 apps, console apps, ASP .NET, and with the right tools it can even make iOS/Android/Mac/Linux applications.


    Your VBA experience is only partially applicable to writing VB .NET applications. The fundamentals, like variables and arrays, are mostly the same. But there are also new fundamentals, like Classes and object-oriented programming. This impacts other fundamentals, like variables, because there's important differences in how Classes like Form are treated compared to how Structures like Integer are treated.

    It takes a lot of time to get used to how VB .NET treats types. In other Visual Basic languages, people got used to things being automatically converted. In the early 2000s, the programming community felt like this was dangerous. So when VB .NET was created, it adopted a stricter approach to type conversion. For example, VBA or VB6 might have been happy to treat "9/6/2015" as a string or a Date, depending on how you use it. VB .NET insists that a String is not a Date until you call DateTime.Parse(), or add the # symbols that make it a Date literal. This means you have to "unlearn" a lot of VBA tricks, or at least learn how to unravel why they don't work in .NET. That takes a little time.

    It is best to approach VB .NET as a new language, but that doesn't mean you have to start from scratch. But you shouldn't be so surprised when you find out that VBA and VB .NET have different behaviors. Instead, you should be writing down all the places where things don't work like you think, so you can remember them the next time it happens.

    It's OK to write code in terms of VBA, that you understand, then ask how to make it work in VB .NET. But we do sort of expect that eventually, you start absorbing the differences and fixing some of them on your own.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

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