VS 2005 Each Loop An How Does It Works?
Apr 29, 2011i need assistance in for each loop in vb.net 2005. that what is this for, why we use it, what is its syntax and where we need to use etc etc etc....
View 3 Repliesi need assistance in for each loop in vb.net 2005. that what is this for, why we use it, what is its syntax and where we need to use etc etc etc....
View 3 RepliesI assigned an integer as 1, and looped my program using:[code]I can recieve the packets without looping, but once i loop, i receive nothing.
View 29 RepliesI am trying to understand how a for each loop works and am having some trouble. I am trying to create a program that will query a sql database, pull back the information and store it. I currently having it writing to a text file, and would like to take the information (such as name) and compare it to another list where the name is equal. However I am not exactly sure how the for each statement really works. I have looked at numerous sources and it doesn't make since to me as you can probably see from what I have put in here.
HTML
Public Class Form1
Public Sub newarrest()
Dim strsports As New System.Collections.Generic.List(Of String)
Dim employeelastname As New System.Collections.Generic.List(Of String)
Dim cnPodaci1 As New SqlConnection
[Code] .....
While Loop Works then doesn't?
View 1 RepliesAt the moment my problem is when the function is called If I run it without line 3' MsgBox("bfdbfbniu") the x & y aren't being returned, however when I put a msgbox they are? I don't understand why it would work with a textbox, in comparison to without one. I honestly think the msgbox() should have no effect;
'If CPU is second
If count4win = 1 Then
MsgBox("bfdbfbniu")
[Code].....
My For... Next Loop will not work and I cannot for the life of me figure out why. I have tried to display the results in a label and a text box with multiline enabled. Doesn't seem to matter. It's probably something obvious I have been overlooking for 2 hours.
Option Explicit On
Option Strict On
Option Infer Off
[Code].....
I have written a pontoon game for a college project but i have a problem in which my loop only works when there is a breakpoint in it.The counter is incrementing as i have used a msgbox to display it. The procedure runs the loop and returns the same value in all locations in the array. With a breakpoint it displays correctly in the array.
here is the
Dim aryCardValue(0 To 10) As Short
Dim aryCount(0 To 10) As Short
Dim i As Short
[code]....
I have used the cards procedure in other programs and it worked fine.
I�ve had success using the GET method to retrieve a series of web pages but my new challenge requires me to use a POST > GET combo. I can get it to work once just fine but no more. I get the feeling that something isn�t closing or completing properly. When I try to do the second GetRequestStream() I can see from my sniffer app that nothing is being sent so when the next command to stream the POST data to the request session it fails. I removed it all from the loop and simplified it as much as possible. Can someone tell me why it fails?
Also as a general question is my tack or reusing WebRequests viable? Or is there a �best practice� for looping a POST > GET combo? I�ve been assuming that since nothing in the WebRequest changes besides the post data I�m sending, even its length remains the same, that I should be able to re-use it.
Dim Cookie As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte()
[code]....
Note: The section after the �Experimental comment is a surrogate for the second iteration of the loop. The GET that normally follows the POST section has been removed.
My app is a fairly simple and im sure with the right knowledge this would take 2 minutes.. but sadly iv been at it for hours. So my scenario here is a huge network with 20+ file servers all with data spread out across them it can take hours to find the folder required.
Hence this app.. so it consist of a input box, progress bar and a button, using FileSystemObject I plan to interrogate a directory to see if a folder exists (folder specified by user input) however it need to check multiple directories, in my old app I used a list box which wrote to a text file allowing the user to add additional directories then using if statements proceeded through the servers.. however they have added that much that my IF's have ran out really because i know it should have been a loop
Imports System
Imports System.IO
Public Class Frm_main
Private Const FILE_NAME As String = "C:directories.txt"
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim Lines() As String = IO.File.ReadAllLines(FILE_NAME)
Dim Dir As String
[CODE]...................
I am developing an application using Visual Basic .NET 2005. The application works fine in the PC which Im using to develop it. I make the setup.exe I install the application in other PC and the application doesnt work but it I replace the app.exe with the one in my debug folder it will work.
View 3 RepliesI have a small problem, I have written a small application to update a database table. Now on my computer I have a copy of the database but using MSDE 2000 and when I run my application it works perfectly, however I also have a copy of the database attached to MS SQL 2005 on another computer. Now when I got an run my application on this machine, it fails with a "Time out" error. I have changed the timeout settings on the SQL Server however it then just sits there for ages, whereas when I run it on my development machine MSDE 2000 it loops through the code quickly.
[Code]...
CODE:
That code works to read the entry data and to recognise the correct data, and the incorrect. However, even if entry is correct, the error msgbox will appear (x times of how many records there are in file), despite being navigated to the menu. Anyway that the Else isn't triggered when data is correct. Also for it to appear just one instead of (x times of how many records there are in file.)
This is confusing the poop out of me.This is a loop at which, on the last iteration,decreases the size of the loop's maximum count, and also decreases the loop counter.
Dim maxValue As Integer = 5
Dim iCount As Integer
For iCount = 1 To maxValue
[code]......
I have more than ten groupboxes and will increase in future so I am trying to something like this:all groupboxes are visible = false and there is a textbox which shows a random number from range of 0 to number of groupboxes..Now I want make a certain groupbox visible whatever number is textbox for example:textbox1_text change event:textbox1 = 6..so groupbox6 should be visible = true and rest of them should be visible = false..I tried it manually still its not working.
View 4 RepliesI need to create a variable number of Group Boxes, at runtime, inside an existing Layout panel. The name of the Group Box also needs to contain the integer, from the loop, as part of its name. i.e x = 1 to 3 > GroupBox1, GroupBox2, GroupBox3
View 5 RepliesI am using the following code to return the long and lat of a property, how can I create a loop to return the same for multiple address's?
[Code]...
I'm making a rock paper scissors program and once I set the current_scene variable to 1, the MainLoop() sub doesn't keep looping, but the sub doesn't exit either. (Form1.vb is the most important file.)
View 9 RepliesI have a Collection, the keys are strings and the values are Collections. In the sub Collections the keys are strings and values are Singles/Floats. How would I loop through all of the data? I need to get the keys and values not just the values. I've tried this but it produces a cast error:
[Code]...
I have a spreadsheet with this code:
'insert link
sheet1.Hyperlinks.Add(sheet1.Range("P1"), "http://http://www.vbforums.com", "")
the code of the button (ribbon)
[CODE]...
When I press the button, it connects to the web site. when the sheet1 is selected, it works, but when the sheet2 is selected, not works, why? the path is sheet1,What's wrong?
Makes the following statement about the code below:
**"The computer evaluates the loop condition in the Do...Loop statment to determine whether the loop instructions should be processed. In this case, the inputsales <> String.Empty condition compares the contenst of the input sales variable to the String.Empty value. As you know the String.Empty value represents a zero length, or empty, string if the inputsales variable is empty, the loop condition evaluates to True and the computer process the loop instructions. *If on the other hand the inputsales variable is not empty, the loop condition evaluates to false and the computer skips over the loop instructions.
Based on the code I think it is the opposite: ...that while the inputsales value is not empty it should evaluate to true and process the loop and if it is empty it should evaluate to false and skip the loop?
See below.
Option Explicit On
Option Strict On
Imports System.Globalization
[CODE]...
My application uses 12 checkboxes. Dependant on the status (checked or unchecked) different action are required. I can't seem to be able to structure a for next loop to do this.
View 7 RepliesThe following code works fine, however if the user wants to cancel out from the openfiledialog they cant they are stuck in a loop. A loop I created in case they selected the wrong type of data file they could choose again. [Code]. I really need some help seeing where and how to let the user cancel out without the program continuing. I tried some dialog.dispose code but everywhere i seem to put it it generates an error somewhere.
View 4 RepliesPrivate Sub CopySelectedNodes(ByVal nodes As TreeNodeCollection)
For Each node As TreeNode In nodes
If node.Checked Then
'MessageBox.Show(node.FullPath)
Me.CopySelectedNodes(node.Nodes)
[Code] .....
This does not work, I want to loop through results so the textbox1 will be like 151,154,3,151, and I want to remove the last.
how do I set an object array using a loop so I don't have to type each button name?
[code]...
only problem with that is it assigns a string value. I need it to assign an object. any suggestions?
I often use a for/next loop to cycle through a collection to find a particular member of that collection based on some criteria. This works fine in every case except one: when I want to then erase the very member of the collection I just found. For example, if I wanted to give the heave-ho to every obect in a collection class that has a member veriable Color equal to Red:
[Code]...
The problem is once the collection class member is erased it makes to loop invalid because taking out the member reduces the total count of the collection in the middle of the loop. Eventually I get a "Index is out of range" error.This circumstance has bothered me every so often; I bet more experienced programmers have a different type of loop system that works better than this when you want to erase a collection member.
I'm selecting multiple files from a FileOpenDialog box. Now I want to store the names in an array. This is what I'm trying to do:
For i = 1 To fileOpenDialogOpen.FileNames.Length
ReDim Preserve fileList(i)
fileList(i) = fileOpenDialogOpen.FileNames(i).ToString()
[code].....
I'm trying to make a simple game tree.Previously I used nested loops:
[Code]...
I am trying to make a collection of controls that I can loop through. So I have this code in my form... Dim WizardFrameCollection As New Control.ControlCollection(Nothing)
I then try to add controls to the collection by I get a error "Object reference not set to an instance of an object." WizardFrameCollection.Add(Me.GroupBox1) I am not sure why I am getting this error. Groupbox1 is a groupbox that is on the form.
Private dt As DataTable
Private ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Row1 As DataRow
[code]....
I want to change the font to bold of the current row in the loop and i m also binding the datatable with datagrid as it is in code..
if I have the following vb code,
for i = 0 to dTable.Rows(i).Count -1
Dim sql As String = ""
Dim strConn As String = ConnString
[Code]....