Array and Delimiters

  • Thread starter Thread starter Peace
  • Start date Start date
The datasets can be extremely huge depending if the enduser requests a lot
of data. :(
 
Hi Scorpion,

As you wishes
This is not XY, YX conversion

This is a string of lines delimited with chr(13) you see what you want there
and a Tab
You can of course also make vbcrlf and ","

I hope this helps?

Cor

\\\
'As Scorpion wishes a dataset
'Make a datatable with 8 columns
Dim ds As New DataSet
Dim dt As New DataTable("scorpion")
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 48))
dt.Columns.Add(dc)
Next
'And 12 rows every column filled with a letter
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(y + 65)
Next
Next
ds.Tables.Add(dt)
'End build testdataset
'Make string Conform the wish of Scorpion build with stringbuilder
Dim Scorpion As New System.Text.StringBuilder
For i As Integer = 0 To ds.Tables("scorpion").Rows.Count - 1
For y As Integer = 0 To ds.Tables("scorpion").Columns.Count - 1
Scorpion.Append(ds.Tables("scorpion").Rows(i)(y).tostring)
If y <> ds.Tables("scorpion").Columns.Count - 1 Then
Scorpion.Append(Chr(9))
Else
Scorpion.Append(Chr(13))
End If
Next
Next

MessageBox.Show(Scorpion.ToString)
///
 
This may work.I wil let you know.

Respond to IronMan please and SHOUT to people not to respond. Shut it down
before it starts....

He is in the thread "(Search Tool) Alright Already I Fixed It". I would do
it myself but he seems to get off on me responding to him.

I knew it was a mistake going back to my old name.. <sigh>
 
Hi Cindy,

I did make that sample,
Will you look at it if this is what you did mean?

I did place it in the other sub thread , with a lot of answer from Scorpion,
so I gues you missed it.

Cor

\\\
Option Strict On
Public Module Main
Public Sub Main()
'First the testtable
'Make a datatable with 8 columns
Dim dt As New DataTable
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 48))
dt.Columns.Add(dc)
Next
'And 12 rows every column filled with a letter
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(y + 65)
Next
Next
'Conform the wish of Cindy Conventional build string
'brrr but only to show the start of the testtable
Dim Scorpion As String
For i As Integer = 0 To dt.Rows.Count - 1
For y As Integer = 0 To dt.Columns.Count - 1
Scorpion = Scorpion & dt.Rows(i)(y).tostring
If y <> dt.Columns.Count - 1 Then
Scorpion = Scorpion & chr(9)
Else
Scorpion = Scorpion & chr(13)
End If
Next
Next

MessageBox.Show(Scorpion)


'Here start conversion XY to YX
Dim a As New ArrayList
For i As Integer = 0 To dt.Columns.Count - 1
Dim b As New System.Text.StringBuilder
For y As Integer = 0 To dt.Rows.Count - 1
b.Append(dt.Rows(y)(i))
If y <> dt.Rows.Count - 1 Then
b.Append(Chr(9))
Else
b.Append(Chr(13))
End If
Next
a.Add(b.ToString)
Next
Dim Peace As New System.Text.StringBuilder
For i As Integer = 0 To a.Count - 1
Peace.Append(a(i).ToString)
Next
Dim Cindy As String = Peace.ToString

MessageBox.Show(Cindy)
'Text from Cindy
' Dim rng As Word.Range = ActiveDocument.Range
' rng.Collapse(wdCollapseEnd)
' rng.Text = Cindy
' Dim tbl as Word Table = rng.convertToTable('params here)


End Sub
End Module


Cor
 
I didn't see Cindy's response to you.

Would you post it in with your next message?

My newsserver may have dropped it for some reason.
 
See did not response,

But my previous message was a little bit overloaded with answers from you
and therefore I was afraid that see would not see it.

:-))

Cor
 
I am sorry for not being complete originally.

rows = dsreportscopy.Tables(0).Rows.Count
columns = dsreportscopy.Tables(0).Columns.Count

Dim DataArray(rows, columns) As Object
For c = 0 To columns - 1
DataArray(r, c) =
dsreportscopy.Tables(0).Columns.Item(c).ColumnName)
For r = 0 To rows - 1
DataArray(r, c) = dsreportscopy.Tables(0).Rows(r).Item(c))
Next
Next

Dim splitout As String
splitout = Join(DataArray(rows, columns), " ")

Since I'm entering this discussion late, you may have already solved your
problem. But here's my "suggestion"


My understanding is that if the Table has the following rows and columns:

A B C
D E F
G H I

it should give you a string that looks like:

A<tab>B<tab>C<cr><D<tab>E<tab>F<tab><cr>G<tab>H<tab>I<cr>


The Rows property of the DataTable has an ItemArray method that returns an
array of the items in the row. Perhaps you could do somthing like this:

Dim strDataStr As String

With dsreportscopy.Tables(0)
For x As Integer = 0 to .Rows.Count - 1
strDataStr &= String.Join(Chr(9),CType(.Rows(x).ItemArray,String())
strDataStr &= Chr(13)
Next
End With

This code is untested and I'm not sure if the ItemArray needs to be casted
to a string array. And if the rows and columns do not all contain string
data, I'm not sure how that will affect the outcome. Also, if there are
lots of concatenations, you may wish to use a StringBuilder.

If I am completely off base, please ignore this post.

HTH a little.
 
Any help you would give would please me greatly.

I have a array of my dataset and I wrote it to Excel without a problem. MS
Word is my issue. And I was suppose to have had it done many moons ago.

I cannot seem to find a way to get an array of a dataset (ArrayData (r,c)
r - rows, c = columns) into a MS Word table.

If anyone can help I would be most greatful.
 
Hi Cor,
I did make that sample,
Will you look at it if this is what you did mean?
I think the real judge of this will have to be scorp :-)
Does he get a comma-delimited string he can dump into Word?

I'm a bit over-loaded at the moment; brain's smokin' In
order to see whether the sample really works, I first need
some time to read up on datasets, etc! From a quick scan,
just looking at the string building logic, it looks like it
should work.

-- Cindy
 
Hi Scorpion53061,
I cannot seem to find a way to get an array of a dataset (ArrayData (r,c)
r - rows, c = columns) into a MS Word table.
You can't. Stop hitting your head on the wall, wipe up the blood, put a
band-aid on the bruise, take a deep breath, then read and think about what
we've been telling you.

Word doesn't know how to deal with an array like this. You HAVE to get this
into a delimited string. If you already have a dataset, forget about the
array and process the data set the way Cor or Chris is showing you, by
"walking" the records and building the string.

If all you have is the array, then loop through the array in order to build
the delimted string. In really old-fashioned, VB-speak, ugly code (yeah, I
know it should use UBound, but I'm not sure I remember how that goes for a
two-dimensional array):
For i = 0 to NrRows 'Records
For j = 0 to NrCols 'Fields
strData = strData & Array(i,j) & vbTAB
Next j
strData = strDAta & vbCR
Next i

-- Cindy
 
You can't. Stop hitting your head on the wall, wipe up the blood, put a
band-aid on the bruise, take a deep breath, then read and think about what
we've been telling you.

LOL

I will start over and try everything again....
 
Any help you would give would please me greatly.

I'm not familiar with Word automation. I was only pointing out a possible
method for taking your Dataset and turning it into a delimited string. How
to get that string into Word is beyond my feeble skills.

Sorry
 
Back
Top