Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

Array Elements Combinatorics

Lets say we have an array with N elements. How we can have all the possible combinations between those elements?Is it possible to store those combinations to a database?e.g.{1,2,5,6,9}(1,2) (1,5) (1,6) (1,9) (2,5) (2,6) (2,9) (5,6) (5,9) (6,9) (1,2,5) (1,2,6) (1,2,9) (1,5,6) (1,5,9) (1,6,9) (2,5,6) (2,5,9) (5,6,9)(1,2,5,6) (1,2,5,9) (1,2,6,9) (1,5,6,9) (2,5,6,9)

Combinatorics - How To Combine Elements
Lets say we have N set of M elements (not every set hgas the same number of elements). How can we program to have all possible combinations between the elements, if we choose only one element from each set.

e.g.

{1,2}, {1,3,4}, {5,6}

1-1-5
1-1-6
1-3-5
1-3-6
1-4-5
1-4-6
2-1-5
2-1-6
2-3-5
2-3-6
2-4-5
2-4-6

Combinatorics - Elements In A Record
Lets say we have N sets of M elements.
Not every set has the same number of elements!!

How can we put every set as one record which contains these elements?

How can we program to have all possible combinations between the elements, if we choose only one element from each set (record).

e.g.

{1,2}, {1,3,4}, {5,6}

1-1-5
1-1-6
1-3-5
1-3-6
1-4-5
1-4-6
2-1-5
2-1-6
2-3-5
2-3-6
2-4-5
2-4-6

How To Get The Length Of Array And The Number Of Elements In Array
How to get the number of elements of array?

Tell How Many Elements Are In An Array
How do i tell how many elements are in an array? The array is created by another function, so i dont know how many there are by defining them in the varible like you normally would. Thanks.

Max Elements In Array?
both my text books don't provide an answer. ty for ur help.

No. Of Elements In Array
Hi, i was just wondering if there is a easy way to find out the number of elements in an array.

# Of Elements In Array
I have an array that was created using the 'Filter' function from another array. I need to know how many elements were returned in this new array, and really don't know how to go about that...

Efficiency is an issue as the original array had thousands of elements, and there may be hundreds or even thousands in the new one as well.

Help!

Im stuck

I can split a text file to an array ok but I would like to add 10 empty lines or elements at the end of the array.

How do I do this?

Would I use vbcrlf or would I loop through the array and add the elements.

Open Cdlg.FileName For Binary As #intFileHandle 'Open the text file

text = Space(LOF(1))

Get #1, , text

array = Split(text, vbCrLf)

thx for any help

How Do You Know How Many Elements An Array Has...?
I know this is probably a really noob question... but how...?
I thought that I remember myself being able to use array.UBound() or something like that, but it doesn't work anymore.. or maybe I just remember wrong... So how do you determine the length on an array?

How To Know Whether Array Is Having Any Elements Or Not?
Hi all

can any one tell "How to know whether array is having any elements or
not?"

thanks & regards,
Sridhar CS

How Many Elements In An Array
Hi!
I have a function that takes an array of integers as argument. This is a dynamic array so I don´t know how may elements in this array.
How do I find that out?
Jen

Delete All Elements Array
Hallo,
there is any way to delete all the elements of an array.
I have a global array:

Global lRow(excelLineNumber) As String

I try with:
reDim lRow(0)
reDim lRow

But it doesn't function.

Thanks.

Detecting Whether An Array Has Elements
I have an array, that I have dimensioned with zero elements:

Dim Cat()

I need to know if the user has loaded data into the array (causing it to be redimensioned to some, UNKNOWN size) before I call certain subroutines. I've tried:

If Cat()....

If Cat() = NULL....

If Ubound(Cat()) = 0....

They don't work. I get errors due to the subscript being out of range if the array isn't dimensioned to some size. In this case, so far, I simply position a detection statement at the start of the routine "If Ubound(Cat()) > 0", and if an error is generated because of the subscript problem, I determine that there must not be any elements in the array, and just exit either with or without an error message, depending on whether the user may be loading a form (which is where I check in one instance) in which some other function not requiring the array may be the desired goal. I then leave array related errors associated with functions called from the form to specific functions that MUST use the array.

Is there a better way to do this? There MAY be some element of a gamble in my use of the error generated by the "If Ubound(Cat()) > 0" statement for an array with no elements that I am simply missing, even if it is the only statement associated with the error message. It also makes it hard to use a "catch-all" error message for an entire routine, where I am entering a form and may want to enable access to some buttons that don't need the array information.

Thanks.

Check If Array Has 0 Elements
So I declare an array with an undefined amount of elements, such as "Dim Array() As Integer" with the intention of resizing it later. Is there a function I can use that will check to see if the array is still empty? Calling Ubound on it gives a Subscript Out Of Range error.

Removing Elements From A Array
Removing elements from a array as I scroll through a listing of files in a text list. As I find the file I wish to remove it from my array. Example 1.txt after finding the file I wish to remove it from my list. When I try Redim Preserve I get a “array is fixed or temp. locked”

How do I unlock to edit array or is there a better way to remove an element from my array ?

How To Compare Elements Of An Array
Hello!

Have a look at this

Dim Temp(1 to 5) as byte

Temp(1) = 1
Temp(2) = 2
Temp(3) = 2
Temp(4) = 3
Temp(5) = 4

As you can see, 2 of elemets above have same value.

I want to know how to detect if 2 elements have same value, and add them. In this case, the sum is 4.

Also, how to detect if there are 2 pairs, e.g:
Temp(1) = 1
Temp(2) = 1
Temp(3) = 2
Temp(4) = 2
Temp(5) = 5

Two pairs here is: Temp(1) = Temp(1) | Temp(3) = Temp(4)
The sum of both pairs = 2 + 4 = 6

Removing All Elements From An Array
hi there ...

Is there something special I need to do inorder to get this to work for me...

im running windows 2000 server ... and the array I'm attempting to verify that is empty or not is returned from the "Filter" method..

checkIfEmpty = Filter(stringArray, "somestring", True, vbTextCompare )

If (Not checkIfEmpty) = -1 Then

' this is not getting executed..

End If

Note : Filter apparently returns an empty array when "somestring" is not
found in 'stringArray'

thanks ..

deez

Checking If Array Has Elements
I have an array declared like this...

Dim a() as integer

It may or may not have been ReDim'ed to include elements. How can I check if it has elements or not? (Checking it with LBound throws an error.) I suppose I could just make a function to check it with LBound, and if it throws an error then return false, but I wondered if there's a better, more elegant way.

Counting Array Elements
is there an easy way to count the number of the element in an array? Im creating a flat array with the Split function and I want to know how substrings were entered into the array.

Number Of Elements In Array?
Is there a way in vb6 to find the number of array elements?

Anything similar to sizeof i can use?

Can I Randomize Array Elements?
If I have this:

Code:
Dim myarray(0 to 4, 0 to 3)]

For x = 0 to Ubound(myarray)

'get array info
'pass array info to a sub

Next x

This array has 4 elements that I pass to a sub that changes parameters of a calculation. It passes 5 diff sets of data [myarray(0 to 4, 0 to 3)]. There are times when I want to pass myarray(2,0) before I pass myarray(0,0). Is there any way to randomize with array elements get passed?

How To Convert Elements Of An Array
hi.

I was just wondering if anyone can tell me how I would be able to convert string elements of an array into integer values. For example, I have an array that encompasses a range of numbers; however, these numbers are recognized as strings, so when i sort let say- 1,2,5,3,12 ... i get 1,12,3,5-

if anyone can help... that'd be great. Thanks

Easy Way To Add All The Elements Of An Array?
Right now I'm writing out each array address and adding them together as follows:

MyArray(0,0) + MyArray(1,0) + MyArray(2,0) + MyArray(3,0)...

I'm doing this for 59 elements, then dividing this value by 60 for an average.

I'm just wondering if there is some other code that you can direct the addition of all the elements of the array more easily?

Removing All Elements From An Array
I declared an array like:

Dim MyArray() as Integer

In a procedure I have:

Redim MyArray(1 to 5)

How do I remove the 5 elements in this array?

I tried:

Redim MyArray()

But that doesn't work. Is it possible?

Wilbert

Number Of Elements In Array
Hello, I need to know how to get the number of elements in an array.
Like Len(), but not with a string but with an array.
Anyone who could help me out?

How To Split The Array Elements
In array have a big message like ("God is Great") .I want to split the words and stored into the different variables . a=God, b=is and c=Great.
pls give me a solution

Help With Adding The Same Elements Of The Array
I am new to programming and I have hard time at work

code goes in DB find a valeu and compare with a hardoced value form a Array
if found repalce and count.
same for locating the province and change the tax with values from the array and count

For j = 0 To 19
If DsPost("EMP_EE_Share") = dOldRate(j) Then
dCount_EeShareRate(j) = dCount_EeShareRate(j) + 1
i = 1
NewValue = dNewRate(j)
If DsPost("Posts RESNum") = 7 Then
Tax1 = dOnt_tax(j)
dCount_OntEeShareTax(j) = dCount_OntEeShareTax(j) + 1
Else
If DsPost("Posts RESNum") = 9 Then
Tax1 = dQue_tax(j)
dCount_QueEeShareTax(j) = dCount_QueEeShareTax(j) + 1
End If
End If
End If
Next

printing

My code for printing is

For j = 0 To 19

strAudit = dCount_OEeShareTax(j) & " records o tax share updated to " & CStr(Format(dOnt_tax(j), "#0.00"))
Print #intLogFNum, strAudit & strCR
Next

29 records O tax share updated to 6.93

0 records O tax share updated to 6.93

0 records O tax share updated to 6.93

9 records On tax share updated to 6.93

0 records tax share updated to 6.93

what I want to compare if value of the elements from the array are 6.93 and add 29 +0+ 9 so total value will be 38 ....

Number Of Elements In An Array
I have an array (called arrName). This array is created by using Split on the contents of a textbox. My delimiter for the Split is a space.

Is there an easier way of telling how many elements are in this array without looping through it first and incrementing a counter?

The problem I'm having is between names like:

Ann Smith
Ann Marie Smith

In the first example Ann becomes the first name and Smith the last which is correct.

However, in my second example Ann becomes the first name and Marie becomes the last whereas it should be first name equals Ann Marie and last name equals Smith.

So, my though is if there are 3 elements then I will store the first two in strFirstName, but if there are only 2 elements then I will store just the first in strFirstName.

Removing Array Elements
Hi

I have an array as follows:

ArrName(0)="Carl"
ArrName(1)="Sarah"
ArrName(2)="Fiona"
ArrName(3)="Paul"

Can you please let me know how I can remove ArrName(2) and decrease the arrName length by 1, for example. Would I have to do the following:

ArrName(2)=ArrName(3)
Remove ArrName(3)

Or is there an easier way

Number Of Elements In Array?
Hi,
I have this situation:
dim ar() as string
ar=somefunction()

question is how to get number of elements in ar array?

Thanks,

regard j

Dynamic Array Has Elements In It
I have a procedure that populates a dynamic array that is passed to it.
Before I call the procedure, I prepare the array with a Erase ArrayName statement.
Then I call the procedure, which will redim it to the approprate size and populate it.

Under certain circumstances however, the procedure has nothing to fill the array with, so it's left in the same state as was orginally passed (aka empty)

After the procedure runs, I check to see how many elements are present by using UBound, but this fails whenever the array is empty.

So my question is:
Does VB have something other then UBound and LBound for checking if a array has elements in it?

Thanks

Display Elements In Array
I started out with this code to read the attached file. What I want to be able to do is read the Name 1st then have the dates and numbers to follow looping thru each by the set of numbers they correspond to. All the names with 1's,2's,3's and so on. Plus I can't get it to print in anything big enough to view it.
Example:
sailwind
20050224 78 85
20050116 76 85

Sydsational
20050226 81 72
20050211 87 63
and so on for each name that is associated with #1, then go on to #2
How would this work ??

Dim strName() As String
Dim x As Integer

Open "C:Pace.TXT" For Input As #1

Do While Not EOF(1)
ReDim Preserve strName(x)
Input #1, strName(x)
x = x + 1
Loop

Close #1

Dim y As Variant

For Each y In strName
picture1.Print y
Next

Inserting Elements Into An Array
Hi all,

Complicated this one:
I have a richtextbox that I want the user to be able to select text with and then bold it. The app will then output the html.
ie:
VB Code:
rtb.text = "hello all at vb forums"

This text is inserted into a string array
VB Code:
myArray() = {"h","e","l","l","o", etc.....}

I then select the "all" word and click my bold button.
My program then determins the start of the selected text and redims the array then shifts each elements contents along by 3 so I can insert the "<B>" tag at the start of the selected text.
I then determine the end of the selected text and shift the rest of the elements contents up by 4 so I can insert the "</B>" tag.
the text in the rtb stays the same but a new string is created with the HTML formatting.
ie: hello <B>all</B> at vb forums

My problem is now what if the user selects another portion of the text to bold. I can't shift the array elements of the formatted array as I don't know where in the formatted string the start location is since i've added new elements.

I'm sure I've not explained that clearly but I hope someone get's the idea!

Removing Elements Of An Array
ok.. i got this array that will be dimmed without bounds (dynamic) and i will allow a total of 5 elements in the array.. the reason i am not going to just dim it Dim MyArray(4) is because it is a HUGE UDT and I don't want to use up memory until I need to for it.. because the user might not open up 5 forms to need the 5 UDTs...

anyways... Lets say they do open 5 forms and I add a new element to the array and redim it..and then the close one of the forms.. i would want to remove that element from the array.. and move all remaining elements to the beginning..

so if they close the second form.. i would want to remove element 1 from the array (its 0 based) and move elemnts 2-4 up so that it would be a 4 element array...

how would i go about doing this??? did that make any sense?

Test If An Array Hos No Elements
Is it possible to detect an array that contains nothing? I dont mean an array of 5 elements that contain blank or nulls but an array that has been set up with dim arrayname() and then never used?

Delete All Elements Of An Array
how can i delete all rows og an array so the following code to be true

VB Code:
ubound(arr())=-1

Test Array For No Elements
How do I test an array to see if it does not have any elements? I can't use Ubound(myArray()) because that gives a compiler error.

pseudo-code: If myArray has elements do the following....

Getting Properties Using Array Elements
Hi,

I am trying to get the properties of an object by looping through using array elements, like:

For i = 0 To UBound(aryRecords)
aryAnother(i) = objName.aryRecords(i)
Next

I'm having no joy, any suggestions?

Evaluating Array Elements
OK, I am returning an array from a function and I need to evaluate whether or not that array contains any strings. UBound(ArrayName) does not work when there are not any elements in the array. How else can I find out?

Some How I can't get this code to work.
It works great when I only use 1 Array Element Group but when I use 2 I get a runtime error 340 and a message that says: "Control Array Element '1' Doesent exist"

Code:
Public iNumOfOperator As Integer
Public iNumOfOwner As Integer

iNumOfOwner = 1
iNumOfOperator = 9

Dim sFile As String
Dim iTextbox As Integer
On Error GoTo NoFile
.DialogTitle = "Open User Configuration.."
.Filter = "Usr File (.Usr)|*.usr"
.CancelError = True
.ShowOpen
sFile = .FileName
End With
On Error GoTo 0
Open sFile For Input As 1
While Not EOF(1)
Line Input #1, sFile

If Left(sFile, 6) = "[Owner" Then
iTextbox = Val(Trim(Mid(sFile, 7, InStr(sFile, "]") - 1)))
txtOwner(iTextbox) = ""
Else
txtOwner(iTextbox) = txtOwner(iTextbox) & sFile & vbCrLf
End If

If Left(sFile, 9) = "[Operator" Then
iTextbox = Val(Trim(Mid(sFile, 10, InStr(sFile, "]") - 1)))
txtOperator(iTextbox) = ""
Else
txtOperator(iTextbox) = txtOperator(iTextbox) & sFile & vbCrLf
End If

Wend
Close 1
NoFile:

End Sub

If you can Help me that would be great.

Thanks anyway.

-Lumin

Clearing Array Elements
Does anyone know of a simple, easy way to delete empty array elements?

For example:

champ(0) = "one"
champ(1) = "two"
champ(2) = ""
champ(3) = "eight"
champ(4) = ""
champ(5) = "twenty"

How can I get rid of champ(2) and champ(4) while leaving the rest of the data intact?

Thanks,

Chris

Removing Array Elements
I am writing a computer version of a board game. I have an array of the game cards that should pop up when the user lands on the correct space. I want to be able to select any one of these cards at random but never twice in one game. What would be a good way to go about this (remembering that a game may last several weeks, so it needs to be retained on disk what cards have been picked).
I have designed graphically the card and now I just want the correct message to pop up within the graphical representation as well as a couple parameters to define how much money is taken from or added to the players bank account.
Any ideas? I have considerd an array of pointers that a random number is used to select from the array a single element but then after it has been used removing the element from the array and reitinizing and all that is a pain. Thanks for your help.

------------------
SCUZ

Removing Array Elements
I am writing a computer version of a board game. I have an array of the game cards that should pop up when the user lands on the correct space. I want to be able to select any one of these cards at random but never twice in one game. What would be a good way to go about this (remembering that a game may last several weeks, so it needs to be retained on disk what cards have been picked).
I have designed graphically the card and now I just want the correct message to pop up within the graphical representation as well as a couple parameters to define how much money is taken from or added to the players bank account.
Any ideas? I have considerd an array of pointers that a random number is used to select from the array a single element but then after it has been used removing the element from the array and reitinizing and all that is a pain. Thanks for your help.

------------------
SCUZ

Comparing Elements In An Array
Hye friends,
I am doing a project in VB 6.0.

I have a 2-d array declared as

[code]Dim myarray() as Variant.[/code]
I am using this array to store the data from a table named-:Table_Of_Weightage in a descending order on basis

of the weightage for which i am opening the table using a recordset named adoSortWeight,in a descending order
This Table has two fields
Rem_Abbr Rem_Weight

Sorting the array in the descending order like this:

.Open "SELECT Rem_Abbr,Rem_Weight FROM Table_Of_Weightage ORDER BY Rem_Weight

MsgBox .RecordCount
End With

Using a for loop and i taking all the data present in a database table->Table_Of_Weightage and storing all of it

in this array like this...

[code]For i = 0 To adoSortWeight.RecordCount - 1 Step 1
Next i[/code]

the whole table after sorting would look like this...

Rem_Abbr Rem_Weight
abies-n 20
bov 20
gels 20
calc 19
ars 19
act-r 19
cann 18
ail 18
alum 18
dig 17
equis 17
gins 16
gland 16
hip 15
ip 15
kali-s 15
kreos 14
ziz 14

Now what i require to do is,after getting all the elements in a single array i.e. myarray() in a descending order,I

have to compare the Rem_Weight fields with each other and choose the five unique grades.

I want to know this: After storing all the elements of the table in a descending order,compare from start all the

element and pick up the first five uniques grades...
i.e. take the first weightage of the array i.e.=20.Since 20 is the highest grade,while comparision just store it in a

variable
Then one by one compare all the elements i.e of myarray(i,1) only and check like this

ug1=myarray(i,1)(highest grade value=20 would be stored)
then ignore the weightages or Rem_Weight fields having a value 20 and see which is the next one lesser than

20.suppose it is 19 then store it again in a variable.
ug2=19
similarly ug3=18,ug4=17,ug5=16.
Here 20,19,18,17,16 are five uniques grades.
So the first thing i would like to know is how to do the comparisions accordingly and get the five unique grades....
Please let me know as soon as possible...
Niyati

How To Get Total No. Of Elements In An Array?
Hi,
I have a array of size 10
This array contain 5 elements (0 to 4)of total 10(UBound)
Now i want to know how many elements are stored in the array at runtime
How can i get that?

Sofjack

Check If Array Has Elements
How do I check if a dynamic array has elements. I am reading command line arguments into an array and trying to check if something was actually passed:
I have this so far:
Dim sCommandArray
msCommand = Command\$()      'get the command line information
sCommandArray = Split(msCommand)
'? how do I che check if sCommandArray has anything???
If UBound(sCommandArray) > 0 Then

thanks!!

Control Array Elements
I am trying to paste a pile of text boxes onto a large form in groups
of 15 when I try to copy the first group (0-14)and paste it below the
elements are numbered backwards.(29-15) Is there a way to copy and
paste these elements so each paste is a continuation of the element
numbers in the same order as the first? or maybe a better way of
handling groups of 15???

Thanks
Fain

Number Of Elements In Array
I wonder how I can see how many elements there are in an array, for example:

dim array() as string

for n=0 to ( int(10-2+1) * rnd + 2)
array(n) = "Element"
next n

How can I get the number of elements that have been created?

Assigning Array Elements ...
hi friends,
i m extremly in need of a logical help in vb if possible pl reply as soon as u read thisone.

how should i Assign values to predefined array ??

dim ExportTables (5) as string

if ... = ... then
exportTables = Aarray ("a1", "a2")
end if

if ... <> ... then
exportTables = Aarray ("T1", "T2")
end if

here t1 and t2 should be added after a2 in ExportTables array ..

Upendra Patil