-
Nov 4th, 2015, 05:20 AM
#1
Thread Starter
Banned
[RESOLVED] Declare variable questioın...
Hi beautiful people,
Please look at this picture to understand my question.
http://prntscr.com/8yvmb1
Best regards
-
Nov 4th, 2015, 05:31 AM
#2
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.
-
Nov 4th, 2015, 05:46 AM
#3
Thread Starter
Banned
Re: Declare variable questioın...
Originally Posted by passel
Because you Declare (Dim) xlMailAccounts inside the With, EndWith block.
Hi passel,
I know that.
Why this issue is different than VBA?
-
Nov 4th, 2015, 06:44 AM
#4
Junior Member
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
-
Nov 4th, 2015, 07:24 AM
#5
Re: Declare variable questioın...
Originally Posted by Herry Markowitz
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
-
Nov 4th, 2015, 07:58 AM
#6
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.
-
Nov 4th, 2015, 11:41 AM
#7
Re: Declare variable questioın...
Originally Posted by Herry Markowitz
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|