In VB.net is there an option to force generation of the counter variable in the "Next" statement? - vb.net

Visual Basic .net automatically inserts a "Next" statement when you enter a "For" statement; e.g., if I type:
For i as integer = 1 to 10
a Next will automatically be inserted, so that the code looks like:
For i as integer = 1 to 10
Next
It is optional to put the counter variable ("i" in the above) in the Next statement, so that it would read:
Next i
I'd really like to make this the default, as it really helps when one has nested For statements. I can't find anything in the Visual Studio settings to do this; maybe it's partly buried somewhere in Intellisense. I thought perhaps someone out there has already figured this out.

You will want to modify the .snippet file associated with the pattern. For the one you are looking for it is, by default:
VisualStudioInstallDirectory\VB\Snippets\1033\common code patterns\conditionals and loops\ForEachNext.snippet
You can also track down the exact location by looking in
Tools > Code Snippets Manager..., select Visual Basic for the language and browse to Code Patterns - If, For Each, Try Catch, Property, etc - the file location will be listed there.

Related

MS Access: Query to list number of files in a series of folders

I have folders labeled by their keyfield, so 1, 2, ... 999, 1000. located in currentproject.path\RecordFiles\KeyFieldHere so like currentproject.path\RecordFiles\917.
I want to run a query that will count how many files are in each folder. I know this can be done with the DIR function through visual basic, but I can't seem to run it through a SQL query.
I've tried using this function in a SQL equation, so Expr1: [FlrFileCount("Y:\Education\Databases\RecordFiles\")] as one of the fields just to see if it can work, but it prompts me for a value and then returns nothing.
EDIT: I tried an approach using the FlrFileCount function in a continuous form, and it does work, BUT... I get an error after every single line. I have a field in a continuous form of =FlrFileCount([currentproject].[path] & "\recordfiles\" & [ID]), but when I run the form I get an error "Error 76, Error source: FlrFileCount, Error description: Path not found." Which is crazy because IT WORKS, it properly lists the number of files in the folder for each record.
I just need to get this functionality over into a SQL query so I can pull that data for mail merges.
I currently have something similar in a form. The form has an onload property to run a module (Link here) to create a list of all the files in the relevant folder to that record, and then I have another field that just counts the number of entries in the list. However a list can't be a value in a SQL query, so I don't think that code will help.
Thanks to Tim Williams, the answer was to put
=FlrFileCount(Currentproject.Path & "\recordfiles\" & [ID])
It seems the [currentproject].[path] part was where the error was. What's confusing is that in other places, MS Access adds the extra [] around currentproject and path, and I don't know why.
Thank you so much for your help! Now to the tricky part: Implementing a proper naming scheme by program ID across a sharepoint so that the relevant folder can be opened consistently even when program names change.

Load only select sections of Code in QlikView

I have a set of code that is rather large in Qlik. I have dates that are defined at the start of the script
i.e.
Let vBDate = Date(Date#('01/01/2015','MM/DD/YYYY'),'MM/DD/YYYY');
Let vEDate = Date(Date#('12/31/2015','MM/DD/YYYY'),'MM/DD/YYYY');
The entire code runs financial numbers based on a specific data source. Originally I had a version of this QVW for each data source. However, as often goes with financials the QVW constantly needs to be refined. So I merged them all into one code. I broke the Code up into different tabs so I can turn off the sources I don't want.
What I want to do is try to se a variable, either in the code, like this,
Let vROIType = 'Vendor';
or using the method answered in my first attempt at this question where the variable is defined on the designer side using a button.
The hope is that when the variable is set, then only the code associated with that variable will run in the reload and the other code will be skipped.
In my research I tried to create functions in the script and use code to call them, however the call would always error out. I also read about QVDs but many of my date variables are defined at the start of running it, and the QVD needs to be pre-run.
Any help would be appreciated.
As long as you wrap the appropriate sections of the script in the conditionals properly, this should accomplish it:
Create a variable via the Variable Overview window (ctrl + alt + v) like you mentioned to reference the correct script to be reloaded (vROIType)
Create a button or text box and set an action to change the value of the vROIType variable. You can just make two buttons so you can select the correct data source by clicking the appropriate button.
Either reload via the menu or create another text box/button with an action to reload your script.
Most importantly, use conditionals in your script to selectively run the correct portions based on the vROIType variable.
if vROIType = 'Vendor' then
Everything in the script you want run when the source is `Vendor`.
elseif vROIType = 'SomeOtherVendor' then
Everything in the script you want run when the source is ....
end if;
Upon reload, the script will look at the vROIType variable and use that to determine whether or not to run parts of the script. Here's a link to a simple example you can try if you have the paid version of Qlikview, otherwise it'll yell at you that you can't open third party .qvw's.

VBA object properties appear in lower case

Sometimes when developing you find that typical property names show up in lower case.
TempVars.Item("abc")
Might appear like this.
TempVars.item("abc")
Or
tbxMyTextbox.Value
Shows up as
tbxMyTextbox.value
The question is why does this happen and how do you fix it?
I've asked myself this question several times and seen others ask it in SO and elsewhere. In most cases the question comes up when searching for answers on other coding errors. Sometimes the developer (me too) wonders if there's something wrong that they're missing that causes this lower case issue.
A while back I ran across an answer (I'll add the original reference when I run across it again) that made the most sense and actually allowed me to correct this nagging issue.
Apparently it happens when you use a variable in lower case that has a name that's the same as a property.
So
Dim value as string
will result in
myObject.Value
appearing as
myObject.value
Solution?
Because VBE apparently considers this variable across the entire IDE -- apparently without regard to scope; the way to revert to the proper case is to temporarily create the variable in upper case and avoid naming variables with the same name as existing properties in your application.
So the solution for the .value / .Value issue above would be to temporarily include the line
Dim Value as string
in a module within your app. Run the code that includes this line.
Afterwards, remove this temporary line of code.
Then as hoped, .value properties will again appear as .Value and not .value.
Of course, we should avoid those reserved words in the first place, but if at some point that wasn't done the above should fix the issue.
Here are some reserved word links:
Microsoft - Access 2002 & later
Allen Browne's bad word list
Reserved Word search tool (various languages)
Thanks to #ScottCraner for the nudge about avoiding reserved words.
Try something like this:
CallByName(myObject, "value", VbGet)

VB.net Loop adding to combobox

Spent about an hour now, with multiple rages at my monitor. I have a variable which stores the amount of elements within an array.
I want to add the numbers '1' up to this variable number to a combobox. So that when i use the combobox, it gives the options of 1,2,3 etc up to the variable number. If anyone could help, that would a fantastic!!
Also, I tried a few different loops but caused visual studio to give an unable to access debug error when i tried to run the program. I am new to this so apologies if this seems basic.
The code I have below stores the count.
accno = custdetails.Count
You don't need to write the loop. This is a one-liner:
MyCombobox.Items.AddRange(Enumerable.Range(1, accno).ToArray())
I prefer that because it starts you thinking in terms of matching your presentation to a data source, which will help you a lot as you learn further.
But if you really want to:
For i As Integer = 1 to accno
MyCombobox.Items.Add(i)
Next

Text box not showing total

In my program I want to add some values together with a running total, and then show that total in a text box. When I try to run it, though, it just shows zero.
Here's the code I'm using
TotalPrice = TotalPrice + Price
Next
TxtLuggage.Text = TotalPrice
this chunk was a part of a For next loop.
How do I fix this.
Please do not take this as an offense, but I think you should read some book or at least a decent article on .NET debugging. This one looks like an easy to spot with just a bit of basic debugging.
See this one for example, and pay special attention on stepping through code, setting breakpoints and watches
What you should do:
set a breakpoint in the code in the problematic code line
when debugger breaks code execution there, see which object are you changing the property for. Does this property change the text box text value? Are you using a correct form instance?
does the For..Next loop set it to zero on its final pass?