VB Programming Question About Nested Loops?

Jun 23, 2010

Today is not one of those days. I know there is an elegant solution to this problem, but I cannot see the endgame. Does anyone have any tips for making this snippet more elegant? It's a very basic example, but one that I think is common programming challenge. If I have unknown number of lists of string variables of unknown length (It is unknown to me until runtime), how can I use just one loop or a loop plus a nested loop to create a matrice of the values?Easy to re-create. Create a VB.NET Form application, drag over two richtext boxes and a button, then paste this into the form class

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[code].....

View 8 Replies


ADVERTISEMENT

Nested Recordset Loops In ADO.NET?

Feb 2, 2009

How do you do nested recordset loops in ADO.NET? In ADO, you could just open one firehose cursor for the outer loop and a static, client-side, read-only cursor for the inner loop and nest the loops. But you can only open one DataReader at a time and Datasets aren't read-only.

'Classic ADO Code
Dim rsOuter as New ADODB.Recordset
Dim rsInner as New ADODB.Recordset

[code]....

View 1 Replies

Using A For Loop And/or Nested For Loops?

Nov 4, 2011

how to create this sequence using a for loop and/or nested for loops?

1
2
3

[Code].....

View 2 Replies

2d Array Of Strings And Nested For Each Loops?

Feb 2, 2012

I'd like to be able to do something like this:

Dim newdata(,) As String = New String(,) { _
{"foo", "bar"}, _
{"fum", "baz"} _

[code]....

If I change the outer loop to:

For Each str() As String In newdata

It builds ok but I don't get what I want. The outer loop process the elements of newdata as a 1d array and the inner loop sees each character of the strings from the outer loop.So...is there a way to use the for each structure and process a 2d string array? If so, what should I change? If not, what is the best alternative?

View 18 Replies

Using Nested Loops For Drawing Shapes?

Oct 12, 2009

I am trying to write a program that using a nested do while loop and If/If Else statement to draw a shape, and also using a nested do until and If/ElseIf statement to draw another shape.

View 18 Replies

VS 2008 - Two Nested For Loops And If Statements

Apr 1, 2009

I want to write two nested loops and inside them "two if statements" when I write an Else statement which has a messagebox saying that ID is not found.. it repeated many times depending on the for loops. I only want to be displayed once !!! but when I wrote my code like this (using exit sub), the message appears when the condition is right and appears when the condition is wrong. I tried to move this statement somewhere else but still I have problems with it.

With EMPDataSet
For I = 0 To .Personal.Rows.Count - 1
For j = 0 To .Work.Rows.Count - 1
If EMP_CPR = .Personal.Rows(I).Item("CPR") Then
txtName.Text = .Personal.Rows(I).Item("Full_Name")
[Code] .....

View 8 Replies

Nested If Loops Checking For Null And Empty

May 27, 2010

I constantly find myself having to do code similar to the following.[code]Is there anyway to check for both on a single line? When i'm checking a condition for a great number of answers, I sometimes end up with conditionals 6-sets deep. If i check for null first, an error still pops up, even though VB shouldn't check since the first condition failed. i.e.[code]

View 8 Replies

Parallel.For With Nested Loops Causing Inconsistent Iterations?

Dec 23, 2010

I'm trying to implement parallel computing using .NET 4 on an asp.net website housed on a clustered server consisting of 6-8 dual core servers. My original script contains two nested For...Next loops iterating through a range of values in a grid of x by y.

For each point in the grid (x,y), we should perform a computationally intensive subroutine called MakePartsMatrix which accesses a SQL server database with dataviews and manipulating the local variable "unfilled" which is passed in ByRef.

Without the parallel implementation, the nested for loops work fine except its slow -- taking about 60 seconds to run.

When I parallelize the outer For loop, the script is about 50% faster, completing its calculations in 20-30 seconds which is great. However, I have noticed that the parallelization causes random parts of the grid to be either completely skipped (eg, grid (1,5) is never evaluated by the MakePartsMatrix), or some points in the grid (eg, x=10 & y=5) to be evaluated multiple times, resulting in duplicate work.

When I parallelized only the inner For Loop, the script execution time also improves by 50%, but now the last row (y-1) in the grid is skipped entirely and the results in "unfilled" are completely wrong.

When I comment out the "MakePartsMatrix" subroutine, the parallellization (either inner or outer For loops) does appear to visit every point of the grid (x,y) once, and only once.

Dim ConcurrentListofResults As ConcurrentQueue(Of FindBestResults)
ConcurrentListofResults = New ConcurrentQueue(Of FindBestResults)
Dim FBSResultsItem As FindBestResults

[Code].....

View 11 Replies

VS 2008 Nested For Loops - Going Through ArrayList And Finding Duplicates?

May 16, 2010

I have an arraylist of a "Doctor" class containing Firstname, Lastname,etc. Some elements in this arraylist may be duplicates of others. I am trying to iterate through the arraylist and search for duplicates. Once i find a duplicate i want BOTH duplicates put into another array and removed from the original array.

here is my function

Public Function createArrayOfDuplicatesAndRemove(ByVal st As ArrayList)
Dim duplicates As New ArrayList()
Dim i, j As Integer

[code]....

How could something be out of range if i start at the end and work to the front?

View 5 Replies

VS 2010 - Nested For Loops Seem To Only Trigger Once Instead Of The Number Of Times That Specified

Dec 7, 2011

I am trying to code something with nested for loop with the following format:

[CODE]...........

However when the program hits the last value of 'For loop 1', the nested for loops seem to only trigger once instead of the number of times that i specified.

Private Sub populatedgv1()
'setup temptable to store Server data
Dim m_table As New DataTable

[CODE]........................

View 7 Replies

When Break Out Of Loop / Break All Nested Loops?

May 11, 2012

So I have some vb.net code, and I have a nested For loop inside a For loop, and then I have EXIT FOR statement, will it break out of one loop, or the whole chain?

View 2 Replies

Monthly Payment Calculation, For Loops To Do While Loops?

Oct 8, 2011

the purpose of the program is to display the monthly payments on the loan.My homework is to use do while loops instead of for loop.Here is the code for the for loop.

Option Explicit On
Option Strict On
Option Infer Off

[code].....

Now I'm having some trouble displaying the output using the do while loop, and I'm pretty sure it's a loop problem on my code. However, I cannot seemed to find out what's wrong. I looked at the examples of do while loop in my textbook, but I couldn't find anything useful to my problems of my program.This is the output for the do while loop.

Here's the do while loop code

Option Explicit On
Option Strict On
Option Infer Off

[code].....

View 3 Replies

Contain Functions(They All Have For Loops) Don't Work In For Loops?

Mar 6, 2011

When I use a For loop in a For loop the Contains Statement dosen't work! Even my custom one! I even tested mine and it works 100% And neither that or the String.Contains function work inside of For Loops And, I know both of them use loops to search through a string.

My function(It will atleast search once):

Function RealContains(ByVal load As String, ByVal needle As String) As Boolean
load = load.ToLower

[CODE].....................

View 10 Replies

Loop And Enumerate Properties Of Nested Classes In Nested Classes?

Sep 24, 2010

so far i got

code
For Each item As Reflection.FieldInfo In GetType(NameSpace.ClassWithNestedClasses).GetFields
rtfAppend(item.Name & ":" & Tab & item.GetValue(Me))
Next
For Each item As Reflection.PropertyInfo In GetType(NameSpace.ClassWithNestedClasses).GetProperties()

[code]...

which gets me the simple string vars and properties of my top class, but how can i apply this to loop through all sub classes and get there vars and props?

View 1 Replies

Best Programming Language For Programming Windows Applications?

Jan 28, 2012

I have recently taken a liking to programming, and have programmed a few games in C#,my friend has asked me to program an application for him to use in his shop. But I have no idea of what language is best suitable?

View 8 Replies

Game Programming :: Programming Such As OOP ?

Oct 30, 2011

I avidly create games in VB.net. Being a hobby programmer I give my games away for free. Since I'm a hobbiest without formal training I do try and educate myself on proper programming principles and follow them when programming such as OOP. There are however some things I have obviously missed being self-taught that perhaps I would know if I were formally educated. Once such issue that has really been my bane is how different classes (from now on referred to as objects) 'know' about each other WITHOUT programming specific interaction.

Okay imagine this, you have a space game and the following objects

[CODE]...............

Now each one of these objects has a Health, X,Y and Z private members and properties that are all inherited from clsSpaceEntity for argument sake. Now one way of programming collision between them would be to code out the following logic in the main game loop

[CODE].........................

Now this might seam okay if your talking about the simple example above but some of my games have tens or even HUNDREDS of objects that interact in this basic way. Is there a way in OOP to do the following... for each thing that inherits from clsSpaceEntity check against every other object that inherits this type (except itself) and if they collide then reduce health next? This sort of ability for a type of objects/class or whatever to be 'aware' of another and how they are the same/different and interact would save me tonnes and tonnes and TONNES of coding.

View 1 Replies

For Loops In VB?

Nov 24, 2011

I have a 5 by 5 matrix I want to populate and I would like to simplify this into for loops. As I understand, I would need 2 for loops to complete this task?

Dim x(4, 4) As Char
x(0, 0) = Mid(key, 1, 1)
x(0, 1) = Mid(key, 2, 1)
x(0, 2) = Mid(key, 3, 1)

[code]....

View 1 Replies

Use Loops In .NET?

Apr 23, 2012

EDIT:I have a ItemList : Dim ItemList As New List(Of String)I wanna append each element from itemlist to a new list for 10 times each, then to start over again.How can I make a loop for each element while there are still elements in the list (10 times each)?I tried this but it's not working.

Private crt As Integer = 0
Private limit As Integer = 0
Private Function getline() As String
Dim line As String = ""

[code]....

but I didn't know where to add the 10 times limit and also the current item number(crt)

View 1 Replies

Doing Loops In .net Using Regexs?

Mar 30, 2012

I'm writing a super small interpreter in vb.net because i need to execute a simple (invented) language so the app understand it and do what ever it needs to do.Everything went well until i reached the control structures and the loops.So my question its, in a code that its executed line by line using a simple for each how can i match the "WHILE ;" AND "ENDWHILE;" and execute the code within it?

The first thing that came to my mind its kind of flag the line of the reader and read the content from that line until find "ENDWHILE;" and the store that to execute late, so keep isolating the code in parts until I've all parts and then execute it.But i'm not so sure how to code it or if my reasoning its correct.PD: I'm using regexs.

View 1 Replies

For Each In Combobox - Loops Twice

Mar 22, 2011

I did For each Loop in my combobox, but I noticed that it loops twice. When it reaches the last item, it loops back to the first item. I code it typically: For each itm As Object in combobox.Items

[Code]....

View 5 Replies

For..Next Loops VB 2008?

Dec 7, 2009

have a problem where I have an application that allows someone to enter two integers. The app then displays all the odd numbers between both integers and all of the even numbers between both integers. There are two text boxes and two labels: even and odd. How would I code a For..Next loop for this type of app. The part where I get confused is what do I determine and how do I

View 18 Replies

How To Simplify Loops

Dec 5, 2011

I would like to simplify a do loop.

View 1 Replies

Looping Through Loops In XML?

Mar 24, 2010

This is for .net frameworke 3.5 and visual studio 2008 in VB.Net.Two things we would like to do: 1) loop repeating node blocks 2) loop (through repeating node blocks) within repeating node block loop
First thing:

How do you loop through an xml that has repeating node block (<STRUS name="1000A") and extract the following node? For example you want to extract the IdentificationCode in the node that has <SVALU name="ZRT" and is from pos="9".So, the following example has the IdentificationCodes (TGJ23, PGA12, TPX12)

<?xml version="1.0" encoding="UTF-8"?>
<DocSplitterReport xmlns:xsi="http://www.w3.org/2001/X .......
<STRUS name="ROOT" lineStart="-1" lineEnd="-1">
<STRUS name="TAC" lineStart="1" lineEnd="194">
<SVALUs>

[Code]...

View 9 Replies

Merge Two For Loops Into One?

Jun 27, 2009

Is it possible to merge two For Loops into one? I need this because I am using two for loops (1 to 100,000) to work with the data in a collection. The problem with this code is that it takes more than two hours two finish:

[Code]...

View 1 Replies

More Efficient For Each Loops?

Jul 26, 2011

Is there a more efficient way of doing this code?

For Each row As DataRow In dt.Rows
Dim ts1 As String = row(0).ToString
For index As Integer = 1 To 9[code]....

View 2 Replies

Using Names In Loops?

Sep 30, 2011

Im somewhat new to VB, my first time writing a mildly long program... have a program that will create an unknown number of textboxes, then later I will need it to manipulate those textboxes. I set it up so it names them txt1, txt2, txt3 etc..How can I write a loop that will refer to each of these textboxes by name so I can do what I need with them, ie for example in

For i =1 to x
txti.text = i
next

this would make no sense...how do i write the names correctly so the computer can understate and loop them as txt1, txt2,...?

View 3 Replies

Calculating From Multiple Txt Using Loops?

Oct 17, 2011

Basically I have 4 empty textboxes. I need to calculate the total and averages of the numbers entered in them. So far, I've declared 4 variables and made it equal to the text that was input by the user. I'm stuck with the calculations tough. The user doesn't have to use all 4 boxes. So if he/she only entered 2 numbers, the total is divided by 2, not by 4 for the average. I think I'm supposed to use a for... next loop because the maximum iterations I should do is 4, but I'm not sure how to the code even if it is supposed to use a for loop. Otherwise, the rest of my project seems to work fine.

View 5 Replies

Cinema Tickets Using Loops?

Mar 19, 2012

im new to this site and also a beginner on visual basic During form load, the number items required in the Adult ticket and Child ticket CBO's must be populated with code using a single For Loop.The Items Collection in Design mode must not be used to populate these CBO's1. Movie ticket prices, taxes, and fees are as follows:a. Adult Matinee - $9.25

[Code]...

View 19 Replies

Euclid's Algorithm And While Loops

Mar 17, 2011

I have visual studio 2008, and we have been given specific tasks to carry our for our course, we have been asked to implement euclid's algorithm by using a while loop, doing so without the visual part of visual basic whatever that means an example of a question they gave was 1)HCF(88,26)=2 how I would go about doing this, as I am thoroughly confused, and deadlines are fast approaching.

View 3 Replies

Factorial Calculations Using Loops?

Jul 17, 2010

Trying to figure out how to calculate factorials via loops. Cant seem to figure out where to start when using loops.

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved