Setting Numbers In Array And For Loops

Sep 27, 2009

What I'm trying to do is: Set numbers (0-51, a deck of cards) in an array like card(0) = 23 (Which would represent, say, the Jack of Clubs). Then card(1) = 35. Now I have two arrays.

The first array is what I have mentioned above.
The second array is holding a Boolean value. So what I do is make a loop going through the card() array from 0-51. In this loop it generates a random number between 0 and 51. Then I check the second array (iCardUsed()) to see if it holds the random number.

So iRndNum = 13 (Say 13 was the random number)
loops through the second array checking if the there is a value of 13. If there isn't then I want it to set card(whatever it was on, say 12) = 13. then make iCardUsed(13) = true saying card 13 was true. I'm not too sure what to do if it was true, not false.

Alright, now that I explained what I was trying to accomplish, I'll post some code and the project.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iCard(0 To 51) As Integer
Dim iCardUsed(0 To 51) As Boolean
Dim iValue As Integer
[Code] .....

Now, this works, but there are some duplicates in the array. I'm not sure why there would be duplicates. It worked fine when I manually entered data so the logic of it is right. [URL].

View 20 Replies


ADVERTISEMENT

Use Loops To Display Numbers?

Oct 9, 2009

how to I use loops to display this?

[Code]...

View 5 Replies

Analyzing Numbers - Grading For Loops

Jan 15, 2012

I'm trying to analyze the number of a, b, c, d and e after applying the curve percentage selected by the user. Here is what I have so far. I'm using for loop and its adding the curves to the grade distribution.

Public Class frmHW13
'Variables
Dim grade As Double
Dim avail As Integer
Dim curved As Integer
[Code] .....

View 3 Replies

Loading Array Using Loops

Mar 12, 2012

firstly this is not exactly a problem but more like a quiz. I have 3 arrays which I will load data into from a dataset, in the future this set of data might expand and the code will get excessively long, how can I load the data as seen below using loops without using additional array?

[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

While Loops - How To Initialize Multidimensional Array

Jul 12, 2011

I am trying to initialize a multidimensional array. Here is my syntax; this does not create errors but it does not store all values either. Although it correctly prints out all records in this snippet,

dFirstWeek = CDate(FirstWeek)
dFirstWeek = DateAdd(DateInterval.WeekOfYear, -1, dFirstWeek)
Dim dFirstDay As Date
Dim arrWeekYear(5000, 1) As Date
Dim i As Integer = 0
Dim j As Integer = 0
[Code] .....

But this time, only one "j" record appears per "i" record. Why is this? And then after these few records, many dates resembling null dates appear: "1/1/0001". So why do all records appear in upper section, but not from lower? Did I insert values wrongly into this array? And it does not have to have fixed number of rows, just a fixed number of columns.

View 3 Replies

VS 2008 - Make A Loop From 1 To 100 And Make It Everytime It Loops Display Incrementing Numbers To The Screen?

Aug 23, 2009

How do I make a loop from 1 to 100 and make it everytime it loops display incrementing numbers to the screen?

View 1 Replies

Loops And Arrays - After The Loop Is Completed - Pull A Value From The Array And Display It?

Apr 15, 2012

i have a array set up, and i need the array to be global, but i can only get vb to accept it in a button, in addition, after the loop is completed, i am trying to pull a value from the array and display it but am getting an error.the code is as follows:

Public Class Form1
Friend staten As String
Friend statea As String[code].....

View 7 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

Having To Average Three Numbers Setting Up?

Jul 12, 2009

I am having to average three numbers setting this up I need to use sub procedures. I cannot figure out what I am missing.

Public Class Main
Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage.Click
Dim num1, num2, num3 As Double
Dim average As Double

[code]....

View 3 Replies

Initialize An Indefinite (eg. Decimal) Array Without Setting Boundaries On The Array Length?

Nov 10, 2009

initialize an indefinite (eg. Decimal) array without setting boundaries on the array length?

View 2 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

Setting An Array To Part Of Another Array?

Jan 28, 2010

I want to create a second array identical to a portion of a second array, but can't figure out how.

For example if I have Array1=("One","Two","Three","Four")
and I want Array2=("Two","Three")

Is there a simple command to do this?

View 2 Replies

Write An Array Into My.setting?

Jan 11, 2010

How do i write an array into my.setting? do i need to do a loop and write each value of the array into the setting? What about a 2d array?How to get the .count of the 2d array in my.setting?

View 2 Replies

Setting Up Array And Putting It In Textbox

Nov 21, 2011

Any hints on how to place these monthly sales numbers in an array so they show up in 3 separate text boxes (one for domestic sales, one for international sales and one for total sales. (i.e .User enters Month number in a month text box and the above information should show up in the3 individual text boxes).

'Basic Info:
'Month Domestic International
'1 100,000 150,000
'2 90,000 120,000
'3 75,000 210,000
'4 88,000 50,000
'5 125,000 220,000
'6 63,000 80,000

Public Class MainForm
Private totals(,) As String = {{"100,000", "150,000"},
{"90,000", "120,000"},
{"75,000", "210,000"},
{"88,000", "50,000"},
{"125,000", "220,000"},
{"63,000", "80,000"}}

View 1 Replies

Getting And Setting Single Bits In A Byte-array Using .net?

Jul 5, 2011

I have a byte array with 512 Elements and need to get and set a single bit of a byte in this array.The operation must not change any other bits, only the specified one.So if I have a byte like &B00110011 and would like to change the third bit to 1 it should be &B00110111.

Like this:Dim myarray(511) as byte myarray(3).2 = 1 ---> This would change the third bit (start counting at 0) of the third byte to 1 I know it should be easily possible using bit-masking but I don't have the time to try for days to get it working.

View 2 Replies

Check To See If At Least 3 Numbers In The Array Are The Same?

Feb 8, 2009

I have a question about working with arrays

I don't have any code written out I just want to know the best way to do this sort of senario to put into a flowchart, the program i'm working on isn't homework, its just practice and the book I have is less than helpful with what i'm working on.

I want to check to see if at least 3 numbers in the array are the same but no less so that it meets a certain requirement how would I check this?

View 3 Replies

Matching Numbers In An Array?

Jan 11, 2011

I am working on an application that llops through a dataset. Within each loop, I need to test to see if the datarow number is contained within an array. For example:For Each Page in Pages Test to see if page number is found in array (i.e. page number = 3, array = 1, 3, 4, 7, 8)Next Page The test would match on record numbers 1, 3, 4, 7, 8.

View 2 Replies

Numbers Change When Put Into An Array?

Jun 2, 2011

I have a datagrid in my form and numbers are input it. I then loaded one of the columns into an array. This is the piece of my code that loads the array:

Me.dgv.CurrentCell = dgv(1, 0)
For i = 0 To (Me.dgv.RowCount - 1)
Receipts(i) = Convert.ToSingle(dgv(1, i).Value)
Next i

The first value is -2912895.29. I put the program in break-mode and it keeps loading the first value as -2912895.25. I checked and it loads all of the values a few cents off.

View 2 Replies

Random Numbers In Your Array?

Feb 22, 2011

How Can I random the numbers in my array but they will not repeat the array value. The array number starts from 11 to 14.

Or how can I random 4 buttons.text that uses array to call their text?

View 4 Replies

Shuffle Array Of Numbers?

May 16, 2012

I am trying to shuffle an array of numbers it is randomizing but the numbers are been repeated is not what I need., I need the array to be shuffled but keeping the same numbers.For example if I do a first shuffle numbers may look like this in random order

2,4,5,1,3

Next shuffle maybe

3,5,4,2,1 and so on

But my problem is it repeating e.g. like this.

0,3,3,4,5 or 4,5,5,3,3

[code].....

View 2 Replies

Checkbox Control Array And Setting Colors Using For Loop?

Aug 19, 2009

I have 15 checkboxes of control array and at run time fill any 4 or 5 or 6 check boxes with color using colordialog. How can i send the colors to the sql server table using for loop using code at runtime

View 1 Replies

VB 2005 - Multiple PictureBoxes And Setting Up Control Array

Sep 7, 2005

I have a VB2005 project that displays 16 pictureboxes in a 4x4 grid which display CD album covers. In VB6 I could set up a control array i.e. picCD(0) to picCD(15), which made drawing the CD covers a snap. How do I accomplish this in VB2005?

It seems extremely cumbersome to have code like: If Len(path(0)) < 1 Then
If Not IsNothing(PictureBox1.Image) Then
PictureBox1.Image.Dispose()
PictureBox1.Image = Nothing
End If
[Code] .....

View 5 Replies

Array - Randomly Generate Numbers

Apr 14, 2010

I am making an application that randomly generates numbers. I then have to find out if those numbers are even or odd. Then place them in the corresponding array ( EvenNumbers() or OddNumbers() ). Then display the random numbers array then the even and odd numbers array. I am up to the point where I have the generated numbers and can tell if they are even or odd, but can't get them into an array. I am trying to do it like this....

[Code]...

View 10 Replies

Array And Use Of Flag To Shuffle Numbers?

Apr 10, 2011

i am trying to find out how it shuffles the number 1, 2, 3 and 4 without repeating the same number within the series. So far, I think that "i" begins as 1 and RN is a randomized number between 1 and 4. The do while loop checks if "i" is the same as RN and spits out the flag as true or false. Then "i" is increased 1 at a time and so does the number of elements in the array. I believe that the array a(4) and the for loop does something that "remembers" the same numerical value not to be repeated. I'm not sure exactly what the for loop does and how the flag make this thing work.

Lets say, a case where i=1 and the RN=3, the flag becomes false. Therefore, a(1)=3. Then, i increments by 1 and a(j) becomes a(2), which puts out the values 1 and 2. Since both numbers are flag=false, it increments again. Because a(i) = RN, a(2) becomes = 3. How can this be? It has a(1) equal to 3 and a(2) also equal to 3. Each array is supposed to have NON-OVERLAPPING numbers.

The result of doing shuffle() is a random set of numbers that don't overlap:

1234, 1243, 1342, 1324, 2341, 3412, 4321, 3214, and so on.
but never 1111, 1112, 3333 or 3242.

To find out how exactly it works, I tried to delete some lines, tweak the numbers. The result of that is either numbers change to repeats, all zeros or a logical error. The following is the code placed in the module and can be used for other forms and in this case it is used for the labels in form1 windows form:

Sub Shuffle()
Dim a(4), i, j, RN As Integer
Dim flag As Boolean

[code]....

View 2 Replies

Array Shorting, Numbers As Text?

Sep 25, 2011

While split a textline with numbers (integers), i get an array with numbers as string.Is it possible to short them? Array.short does not work as it shorts according the first number of the integer

[Code]...

View 5 Replies

Create An Array Of 10 Random Numbers?

Apr 19, 2011

I have not messed with VB much and I have been trying to do something that has me stumped. I wanted to create an array of 10 random numbers. Each of these numbers then is printed onto a label. From here I have two more labels that show the highest and lowest value. I got the first part, 10 random numbers show up but then things get shaky. This is what I have thus far.

[Code]...

View 1 Replies

Find Consecutive Numbers In An Array?

Oct 31, 2011

I need to find consecutive numbers in an array and return a string which tells the range and numbers that don't form a range.I found some of the already asked questions but none of them is in VB.Net:Add to array consecutive numbersIf the array of numbers looks like {11,12,67,68,69,70,92,97} then returned string should be of the form 11,12, 67 through 70, 92 and 97.

View 1 Replies

Find Duplicate Numbers From An Array?

Sep 22, 2009

I am having trouble in finding duplicate numbers in an array.the first one is to create an array with duplicates and then display the number that has been duplicated and how many times it has been duplicated.

Here is my uncompleted code:

Dim arry(4) As Double
arry(0) = 4
arry(1) = 44

[code]....

View 14 Replies

Find The Mode Of An Array Of Numbers?

May 6, 2010

how do i find the Mode of an array of numbers.this is what i have so far, sacount1 is the max index

For j = 1 To SAcount1
If NFAI(j) = NFAI(j - 1) Then
x1 = x1 + 1[code].....

View 14 Replies







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