Why is the Visual Studio debugger skipping valid lines? - vb.net

I am working on a VB.NET program in Visual Studio 2017. There is a patch of code that the debugger skips completely over every time. I have rewritten it a dozen times trying to make it work. Code optimization is turned off. I have tried deleting every single file in the Solution folder and subfolders except for the source files and rebuilding from scratch. No change. Google hasn't given me a solution.
In this case, ClientList has two elements, so the .Count is 2.I want to traverse it from the last element to the first, so I use a for loop on line 209.While debugging, I verify the count is 2, so the debugger should work its way through the for loop twice. But after line 209, it jumps straight to line 228.
I included the second loop for comparison because it always debugs fine, even though it's doing the same thing, iterating through the elements of ClientList.
Can anyone solve this for me? I've spent most of the day on this and can't get any further until I have a solution.

Add Step -1 to the For-statement and it should work as expected.
For ClientIndex As Integer = ClientList.Count -1 To 0 Step -1
Excerpt from the documentation:
The default value of step is 1.
Means, without Step -1 the value of the loop counter is incremented and thus the loop never runs because 1 (ClientList.Count-1) is already greater than 0.

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.

Visual Studio Fortran Stuck at Reassigning values from one variable to another

See attached screenshot.
I ran the code, stopped it at a break point, and F11 the steps until the line ccs2 = ccs2_2.
I checked both of these variables have the same dimensions, same number of elements that actually have value (they are both 6x6x10000 and only the first 6x6x219 elements have values).
I have ran this algorithm before and I have never had this problem. What you see in the screenshot is the visual studio stuck at this point with no error and no notifications for what seems like forever (been at least 10 minutes for each time I tried) when I pressed F11 to try to execute ccs2 = ccs2_2.
I checked I don't have any memory or CPU problems. When I pause the execution from the top, the progress marker goes back to the line and when I checked the variables, I find the first 6x6x219 values now match up, but the program won't advance forward.
Updates: I attempted to limit the range to just the elements that have values such as ccs2(1:6,1:6,1:219) = ccs2_2(1:6,1:6,1:219). It still takes a long time, but for some reason, visual studio reports that it only took 2059 ms, but the actual time was definitely way more than 20 seconds. I changed heap arrays from 0 back to nothing and the new time is supposedly 1978 ms but it definitely took more than 19 seconds.
I tried using an explicit loop to assign only the elements with value and it took less than 1 ms.
When you step over a huge array assignment statement, the debugger, internally, does single step by instruction until the statement number changes. I see your arrays are very large, and the debugger isn't "stuck", it is just taking a long time to step over.
Try as an alternative setting a breakpoint on the next statement and hitting Go.

VBA ShapeRange.Rotation Property randomly stops working

I am trying to rotate a shape. Below is the relevant snippet.
Sheets("Sheet1").Shapes.Range(Array("Down Arrow 8")).Select
Selection.ShapeRange.Rotation = 90 + Sheets("Sheet2").Range("H8")
My problem is that the last line randomly works and randomly doesn't! I used to have it as a number (instead of a to string) but this refuses to work! It worked fine, then I made some changes to the macro and then it helpfully returned Error 438 - Object doesn't support this property or method. I fiddled around, debugged, etc (without ever changing the code) and it started working! Then I made some more changes and it stopped working and it seems to have stopped working for good. I literally copied this code from a recorded macro.
What I have tried:
Using CStr() to convert the value to a string
Declaring a variable and using the variable
What I really don't understand is why it would work without me changing the code and them stop working without me changing the code (i.e. the relevant lines)
A few things. First, avoid select. It isn't necessary and will save you a lot of headache and time in the future. Second, you can reference the shape by its name right from the Shapes object, assuming you are only intending to rotate one shape with the code. Finally, are you certain the value in Sheets("Sheet2").Range("H8") is numeric? If not, this could cause an error. The code below handles the first two issues. Beyond that, we'll need to see more code to determine the error.
Sheets("Sheet1").Shapes("Down Arrow 8").Rotation = 90 + Sheets("Sheet2").Range("H8")

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

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.

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