Dim strTest(recordSet.Count)() As String
While index < recordSet.Count
strTest(index)(recordset.item(index).getvalue(0).tostring,
recordset.item(index).getvalue(0).tostring,
recordset.item(index).getvalue(0).tostring)
index +=1
End While
Then once the array i populated above, i need to find the if another variable is contained in the second dimension of the second paren contains the value of my variable like this.
if strTest.Contains(someVariable) then
extract the index and get the other two values in the array
end if
so basically is how do i perform the second block of code here.
For Each set As String() in strtest
If set(1).Equals(someVariable) Then
'Get set(0) and set(2)
End If
Next
Loop through the array pulling the items as an array and check the middle item. I think that's what your question was saying.
Perhaps you can use strTest.IndexOf()?
Related
I have ArrayList with multi dimensional values in Structure as ArrayList
Structure
(0)=> Mstructure.ABCD
Area (these are value of ABCD)
Name
(1)=> Mstructure.EFGH
Area
Name
I want to know the index of string ABCD.
I tried
Dim myIndex as Integer = Structure.IndexOf("ABCD")
Dim myIndex = Array.IndexOf(Structure.ToArray(), myString)
This returned only -1. I want to get 0 if string is ABCD
EDITED
Structure is defined as ArrayList. I can iterate over it if I use loop e.g
Structure(i).GetType().Name = "ABCD"
I have checked if it exists in the ArrayList
Dim result = Structure.ToArray().Any(Function(x) x.ToString().Contains("ABCD"))
But I want to know the index of the multidimensional ArrayList without looping it. I want to get the index of Mstructure.ABCD. Msttructure.ABCD has values inside it but without knowing those values I want to get the index value.
(0){Mstructure.ABCD}
(1){Mstructure.EFGH}
(2){Mstructure.IJKL}
hhmmm i would use collections instead, or create an object with multi collections to make it easier for me... Have you thought of that?
I have a file array which carries strings in the following format:
"abc12345.xxx_xxx001.001045"
The string stored in above format helps me do a portion of my job
Now, having stored this, I want to extract a portion of this string and store it an array
How do I extract "abc12345" alone from this string and store it an array?
I tried using the split command. The problem am facing is:
PN(0) stores abc12345
PN(1) stores xxx_xx001
PN(2) stores 001045
I want abc12345 to be stored as PN(0) and next subsequent part number to be stored as PN(1)
Copy Code
Dim PN As New ArrayList()
For Each element In file1array
PN = element.split("."c)
Next
Assuming that every element contains a period and the first segment is the part number,
pn = file1Array.Select(
function(element as string)
return element.Split("."c)(0)
end function
).ToArray()
This would return pn as an array of string, not an ArrayList.
It's saying, for each element in file1Array, split element into an array and return the first element in that array (the part number.)
Then take all of those values and put them in an array.
You can use substring and indexOf:
Dim list As New ArrayList()
For Each Str As String In file1array
list.Add(Str.Substring(0, Str.IndexOf(".")))
Next
Why not just use the split function like you are doing and just concatenate index 1 and 2 to make the result you want?
Dim PN As New ArrayList()
For Each element In file1array
PN = element.split("."c)
PN(1) = PN(1) & PN(2)
Next
I have 2 strings as:
STRING 1:
#serial1#code1#true#serial2#code2#false#serial3#code3#true
STRING 2:
#serial1#code1#false#serial2#code2#false#serial3#code3#false
what i need is information(serial1,code1,true/false) for the group for which it is changed. Like in above example i want data only for (serial1,code1,t/f) and (serial3,code3,t/f)
STRING1 is loaded on page_load and STRING2 will be loaded after click of save button. So i want to hit the database for only those values which are changed not for all the values.
Please suggest some suitable logic.
Thanks in Advance.
You can use String.Split() to turn your string into a String Array, and then evaluate the array items.
Example:
strOriginal() = string1.Split("#")
strChanged() = string2.Split("#")
' Assuming both strings had the same number of elements...
For i as Integer = 0 to strOriginal.Length - 1
If strOriginal(i) <> strChanged(i) Then
' Your DB write logic here...
End If
Next
I am using a Dictionary to create a key to a List Of DataRow. I want to iterate through each key and remove rows in the List. This will throw an out of range exception when I explicitly try to remove a row. How can I alter my code to accomplish this?
For Each g As KeyValuePair(Of [String], List(Of DataRow)) In grouped
For Each row As DataRow In g.Value
If CInt(segment(1)) <= 4 Then
'THIS THROWS AN OUT OF RANGE EXCEPTION
g.Value.Remove(row)
End If
Next
Next
I only want to remove specific rows based on criteria. Can someone post an example? I am on an old browser the "add comment" function does not work
Can you show a code example of how to use a predicate based on row.Item("ID") with the RemoveAll function?
I tried this and am getting an exception
g.Value.RemoveAll(Function(l) l.Item(Con.ID) Is l.Item(Con.ID).ToString)
Use List.RemoveAll. Not only will this make the act of removing all of the items easier than trying to remove items in some form of looping construct, but it will be dramatically more efficient as the List can reorganize all of the items once at the end, rather than moving the items down one index at a time over and over.
I figured it out using a reverse For loop. I did not see an examlpe on how to use the RemoveAll. Please post an example if you have time
For i As Integer = g.Value.Count - 1 To 0 Step -1
Dim row As DataRow = CType(g.Value(i), DataRow)
Dim segment() As String = row.Item(c._ID).ToString.Split("-"c)
If CInt(segment(1)) <= 4 Then
g.Value.Remove(row)
End If
Next i
I apologize in advance if this has been answered before, but I couldn't seem to find exactly what I was looking for when I searched.
I'm not too familiar with VB. I was wondering if it was possible to read an entire column of a table in an Access database and put the data into an array using VB?
If you are using Access VBA you can use the Recordset.GetRows method.
This creates a two-dimensional array which matches the design of your recordset, and it takes a single parameter which is the number of rows to retrieve. To retrieve all rows, either get the .RecordCount before populating the array, or put in a number which you know is larger than required.
For example:
Sub ReadIntoArray()
Dim rstName As Recordset
Dim varName As Variant
Set rstName = CurrentDb.OpenRecordset("SELECT FirstName, LastName FROM tblContact")
varName = rstFirstName.GetRows(1000) ' Gets the first 1000 records
' Retrieve the 16th value from the 1st column
Debug.Print varName(0, 15)
' Get the 100th value from the 2nd column
Debug.Print varName(1, 99)
End Sub