Variable Declaration Inside A Loop?
Aug 26, 2011
For i As Integer = 1 To 10
Dim j As Integer = 10
Next
now my question is, Is memory allocated to j every time its executed inside for loop? or only value of 10 is assigned on subsequent iterations?
View 2 Replies
ADVERTISEMENT
Jan 27, 2012
wondering about the relatively efficiency of declaring oop variables in the loops, emselves, or declaring them before first use. Here are some examples:Declare early:
Dim ix As Integer
Dim currentNode As System.Xml.XmlNode
For ix = 1 To 100
[code].....
View 9 Replies
Mar 30, 2010
Using VB.NET .NetFramwork 3.5. This fails and strikes me as odd. Is this correct behavior:
Public Sub TestForEach()
For index As Integer = 1 To 10
Dim z As Integer
Assert.AreEqual(0, z)
z = index
Next
End Sub
I would expect z to always equal 0 as I thought the dim-ing of an integer would set the value to 0. If you run this. It fails at the second loop. For some reason z retains it's value of 1. I know I can manually initialize z to = 0, but I wanted to know if this is a bug or expected behavior.
View 9 Replies
Mar 27, 2012
Today I investigated a logical bug in our software and figured out that this is related to the way VB.NET thread variables inside a loop.Let's say I have the following code:
Dim numbers As New List(Of Integer) From {1, 2, 3, 4, 5}
For Each number As Integer In numbers
Dim isEven As Boolean
[code]....
The problem is that isEven is declared but not assigned.In this specific case, it would be correct to write dim isEven as Boolean = false but I haven't done this.In VB.NET, a variable that is declared inside a for loop keeps its value for the next itaration. This is by design: [URL]but this is also dangerous pitfall for programmers.
However, until now, I haven't been aware of this problem/behaviour. Until now.Most of our code base is C# anyway, which doesn't allow the use of an uninitialized variable, so there is no problem. But we have some legacy code that is written in VB.NET that we have to support. So the best thing would be to generate a warning or even an error in this specific case.But even with Option Explicit / Option Strict this does not generate a warning / an error.Is there a way make this a compile time error or maybe a way to check this with FxCop?
View 2 Replies
Feb 4, 2012
i just got 1 question how do u create a (in excel ) variable table (database) inside a function which could be called for filling and reading through "for to next" loop module
View 2 Replies
Mar 8, 2010
In this
Dim [end] As Point = e.Location
what is the significance of the [] 's?
View 4 Replies
Jan 19, 2011
I have the following form[code]...
and when I run my app, I get a SQL error that tells me that I need to declare a value for '@payperiodstartdate' but I know that that value is declared because the first query runs fine. I am told that the line where the error is is line 59, which is this line [code]...
View 1 Replies
May 17, 2010
I'm working on a home project using DirectShow.Net. to learn some VB.net. Most of the examples I've found have all been in C# so I'm looking through code for ideas and converting where I need to. I keep stumbling upon these declarations and I'm unsure how to convert it to a VB.Net statement.[code]Then the second part seems to be assigning the value but as its made up of two parts im unsure how that works?
View 2 Replies
Feb 1, 2010
[code].....
View 4 Replies
Oct 24, 2011
I have noticed in VB.Net that most Dim statements also include an assignment. Eg:Dim myvar As String = "Hello World"As this wasn't possible in VB6 I have always done the following:
Dim myvar As String
myvar = "Hello World"
View 3 Replies
Feb 20, 2012
im sure im mis-wording the concept but here it is anyways. I know in CSharp you can do
el.AppendChild(new UISize(file, "TSize") { CX = 95, CY = 20 });
which declares a temporary bucket variable and then assigns the associate property values to the variable. Which then sends it to the XMLElement AppendChild method. What is this design concept called? What is the conversion to VB.Net? I have tried using my own online utility that does a 90-95% conversion rate from C# <-> VB.Net. It has failed in this instance, and so need a hand-up on what i am looking to do to convert this from C# to VB.Net. I would really like to not have to do a long-declaration of a variable with assignments, if at all possible.
View 1 Replies
Apr 26, 2010
I'm making a call to my DLL file (prototyping 30+ functions), and want to be able to switch between different versions of the DLL quickly while in development. Thus, i want to replace the literal string constant that follows the "Lib" key word, with a variable string constant. In case there's any confusion in my use of the jargon. I am currently able to do this:
[Code]...
View 1 Replies
Nov 22, 2010
How could I create declaration(event) to a variable control in VB .net ? [code]please i need to know how to insert this (declaration) newweb_ DocumentCompleted it's similar to WebBrowser_DocumentCompleted but it's a variable
View 5 Replies
May 31, 2011
When I scroll down to the function shown below, and right click Analogues - go to definition it takes me to the top of the file, and lands on top of the
[Code]...
View 3 Replies
Jul 8, 2010
I was looking at some existing code and stumbled across a variable declaration I didn't understand.
public foo as Boolean?
What does the question mark signify?
View 2 Replies
Jan 4, 2011
I've been programming for many years in many languages and I've seen the variable declarations conventions change. With VS 2010 I've noticed you don't have to declare the variable type. I work alone so I can use any method I want. But, someday I may want to sell some of my code so I would like to keep my programming conventions current.
In VS 2010 which of these would be considered the best convention?
Dim srtFirstName = "Bob"
Dim strFirstName As String = "Bob"
Dim FirstName = "Bob"
Dim FirstName As String = "Bob"
View 5 Replies
Apr 21, 2010
Why are static variables set equal to 0 in the declaration when 0 would be the default value of the numeric variable anyway when it's first declared? Not including the "=0" in the static declaration seems to work with no problem.
View 2 Replies
Jun 21, 2011
I got problem regarding declaration of dynamic runtime array declaration Here is my code
[Code]...
View 5 Replies
Feb 19, 2010
I am sure this has had to have been answered somewhere but after looking on the web I cant find anything addressing variables in variables. For instance say I have var1, var2, var3, var4 decalred. How can I create a loop assignment? Something like var & i = "variable 1". So instead of "var1" I have the numeric piece be a variable.
View 2 Replies
Mar 28, 2012
I'm foolin round with stream reader/writer and I'm running into this problem: If I have my if/then statement inside my loop I get a million msgboxes(which I understand why), however if I put it outside my loop, and the if/then returns a false then the whole program freezes up. I can't move my mouse around, I can't click on any objects, ect. Here is what I'm using:
[Code]...
View 10 Replies
Sep 7, 2011
here is some simple code:
0: dim varA = 0
thread.sleep(1000)
GoTo 0
I was wondering how do I name each new variable a different name each time through the loop (i.e. varA1, varA2, varA3)
View 8 Replies
Feb 26, 2009
Im having a problem with a loop inside a C++ dll being called from VB. I want this loop to update a global variable, but when I call the function the variable does not update the first time round, but does so every subsequent time.
This is how I am trying to update the variable.
else
{
::nScore = nHighest;
[Code].....
As a workaroud I am forcing the variable to be what I want in the VB code
View 1 Replies
Jul 28, 2009
i trying to insert into database everytime a loop complete. but there is a syntax error saying "Incorrect syntax near '1'" at myCommand.ExecuteNonQuery(). here is my code and i really don't where went wrong. expert,
[Code]...
View 7 Replies
May 27, 2009
How do I get the position of the XML element in this loop?
For Each objNode In objDoc.SelectNodes("//books/book")Next
What I want in output would be something like
View 1 Replies
May 19, 2009
Is it possible to change many labels inside a for loop? Let's say I have labels 1 to 4. Can I do something like:
for i = 1 to 4
label%i.text = some text
next
View 2 Replies
Feb 25, 2011
I am having trouble using FOR loop with array in query.What I am trying to do is for all the data pulled out of database I convert it to an array list and then string (this works fine). After that I am trying to make a FOR loop query for each of the data pulled out and this is where i am having trouble.
[Code]...
View 5 Replies
Mar 23, 2012
I am writing a program and i need to declare matrices but there will be a different number to declare everytime the program is run so I was wondering if anyone knew how to declare them inside a for loop
eg.
For i = 1 to NumberOfMatrices
Dim matrix i (5,5) As Double
Next
View 4 Replies
May 18, 2010
I would like to be able to stop a loop while executing using the ESC key.I've found a lot about using the above key from within a Form (for example, to unload it), but very little for the use of the key within a Procedure (Sub, Function) and particularly with respect of preventing a loop from carrying on execution.
View 3 Replies
Jun 27, 2012
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As New Staff
[Code]....
Basically I am trying to update each record with 2 random numbers each time the button was clicked,my problem now is, the system will update the record but the data was wrong. Example, by right all data should be different (randomly string) but for some row it was updated with same data but in randomly, something row1 row2 row3 has exactly same data for column 1 and 2 then row 3 has distinct data, second time, row1 row2 same data row3 ro4 with different data. It is in random sequence. When I add a MsgBox to do testing in the For loop the data was updated correctly with all different data.
View 2 Replies
Apr 23, 2012
For my own basic understanding ... what is the difference between these two snippets?
Dim y As Integer
For x As Integer = 1 To 100
y = x
[code].....
View 3 Replies