By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

Array and Delimiters

P: n/a
I am having trouble writing code to turn an array into a delimited string.

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

rows and columns are integers representing rows and columns quanitity of
datasets.

Could someone help show what I am doing wrong?
When ever I write splitout to to a text file nothing is there.
Nov 20 '05 #1
Share this Question
Share on Google+
33 Replies


P: n/a
"Peace" <Its the end of the world as we know it@here.com> schrieb
I am having trouble writing code to turn an array into a delimited
string.

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

rows and columns are integers representing rows and columns quanitity
of datasets.

Could someone help show what I am doing wrong?
When ever I write splitout to to a text file nothing is there.


How is DataArray declared? It would have to be a 2-dimensional array of
1-dimensional string arrays.

If DataArray is a string array, you can write
splitout = Join(DataArray, " ")

You can also use the shared method System.String.Join.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
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), " ")
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
"Peace" <Its the end of the world as we know it@here.com> schrieb
I am having trouble writing code to turn an array into a delimited
string.

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

rows and columns are integers representing rows and columns quanitity
of datasets.

Could someone help show what I am doing wrong?
When ever I write splitout to to a text file nothing is there.


How is DataArray declared? It would have to be a 2-dimensional array of
1-dimensional string arrays.

If DataArray is a string array, you can write
splitout = Join(DataArray, " ")

You can also use the shared method System.String.Join.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

P: n/a
"Peace" <Its the end of the world as we know it@here.com> schrieb
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), " ")


Why the first
DataArray(r, c) =
statement? It is outside the loop that uses 'r'.
How do you want to concatenate the dataTable content? One space between each
column and a new line for each record? How do you want to convert the values
to a string?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #4

P: n/a
Hi Armin,

One space (actually would prefer a tab but it was nto accepting Chr(9))
between each column and a new line for each record.

How would you have written this?

The end goal is:
(provided by cindy concerning writing an array to a MS Word table)
- Turn the array into a delimited string (using the VB Join function, for
example). The delimiter can be anything you like, just as long as it's a
character in the text. Or, you'd have to put the individual entries into
"quotes" so that it's clear where the character is NOT a delimiter.

- Assign this string to a RANGE in the Word document (rng.Text = s)

- convert the range (containing the delimited string) to a table (the
ConvertToTable method), assigning it to an object variable (Dim tbl as
Word.Table tbl = rng.ConvertToTable('set the params)

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
"Peace" <Its the end of the world as we know it@here.com> schrieb
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), " ")
Why the first
DataArray(r, c) =
statement? It is outside the loop that uses 'r'.
How do you want to concatenate the dataTable content? One space between

each column and a new line for each record? How do you want to convert the values to a string?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
Cor
Hi Peace,

Can you see if this fits your problem?

It makes from a datatable (the part after ds. with a dataset) a arraylist
with comma seperated strings.

Test it very good, because in this way I did not make it before and I become
always confused to check xy, yx

I hope it works for you?

Cor
\\\
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(",")
End If
Next
a.Add(b.ToString)
Next
///
Nov 20 '05 #6

P: n/a
Hi Cor / Peace,

It looks the basic approach here would work. You're building a comma-delimited
string, yes? However, you should loop columns for each row. Think of the data
as each record's fields are a column in a row:

Field1,Field2,Field3
Data1,Data2,Data3
Data1,Data2,Data3

If you're going this route, no need to put it into an array - you'll already
have the delimited string! Just keep on concatenating the string: After
processing each row, add a vbCR character to the string. (vbCR because this is
what Word understands as "new paragraph", and works with best when converting
delimited strings to tables).

Basically, if you'd copy paste my sample, above, into Word it would convert
with no problems into a table. This is the kind of end-result you need to
generate.
Can you see if this fits your problem?

It makes from a datatable (the part after ds. with a dataset) a arraylist
with comma seperated strings.

Test it very good, because in this way I did not make it before and I become
always confused to check xy, 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(",")
End If
Next
a.Add(b.ToString)
Next
///


-- Cindy

Nov 20 '05 #7

P: n/a
Cor
Hi Cindy,

I was not sure from the message of Peace if it had to be a csv file was what
you had said.

The arraylist and stringbuilder approach I use because that is very fast.
(Of course I could do it in one time)

(to make it even more efficient now I know it has to be a CSV File)
b.Append(dt.Rows(y)(i))
If y <> dt.Rows.Count - 1 Then
b.Append(",")
End If if y<>dt.Rows.count - 1 then
b.append(",")
else
b.append(vbcrlf)
end if

And after that it is just making from the strings in the arraylist a csv
file by

For ......... (but I did (and do not want to do everything), that is not
good for Peace) :-))

Although it is almost nothing to do it.

But if I understand it wrong about that csv textfile, please message me.

Cor

Hi Cor / Peace,

It looks the basic approach here would work. You're building a comma-delimited string, yes? However, you should loop columns for each row. Think of the data as each record's fields are a column in a row:

Field1,Field2,Field3
Data1,Data2,Data3
Data1,Data2,Data3

If you're going this route, no need to put it into an array - you'll already have the delimited string! Just keep on concatenating the string: After
processing each row, add a vbCR character to the string. (vbCR because this is what Word understands as "new paragraph", and works with best when converting delimited strings to tables).

Basically, if you'd copy paste my sample, above, into Word it would convert with no problems into a table. This is the kind of end-result you need to
generate.
Can you see if this fits your problem?

It makes from a datatable (the part after ds. with a dataset) a

arraylist with comma seperated strings.

Test it very good, because in this way I did not make it before and I become always confused to check xy, 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(",")
End If
Next
a.Add(b.ToString)
Next
///


-- Cindy

Nov 20 '05 #8

P: n/a
Cindy,

Are you saying if I copy and paste the array into word it will make a table
out of it?

I am sorry if I am not understanding.

"Cindy M -WordMVP-" <C.*********@hispeed.ch> wrote in message
news:VA.000090a5.0081e2ea@speedy...
Hi Cor / Peace,

It looks the basic approach here would work. You're building a comma-delimited string, yes? However, you should loop columns for each row. Think of the data as each record's fields are a column in a row:

Field1,Field2,Field3
Data1,Data2,Data3
Data1,Data2,Data3

If you're going this route, no need to put it into an array - you'll already have the delimited string! Just keep on concatenating the string: After
processing each row, add a vbCR character to the string. (vbCR because this is what Word understands as "new paragraph", and works with best when converting delimited strings to tables).

Basically, if you'd copy paste my sample, above, into Word it would convert with no problems into a table. This is the kind of end-result you need to
generate.
Can you see if this fits your problem?

It makes from a datatable (the part after ds. with a dataset) a arraylist with comma seperated strings.

Test it very good, because in this way I did not make it before and I become always confused to check xy, 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(",")
End If
Next
a.Add(b.ToString)
Next
///


-- Cindy

Nov 20 '05 #9

P: n/a
> For ......... (but I did (and do not want to do everything), that is not
good for Peace) :-))


I appreciate your concern about my wellbeing but it is not like I have not
tried and I have spent a good deal amount of time writing the excel sample
that was connected to this. I am putting in the legwork so please help if
you can. I also am in a production environment which I know you know what
that means and I have spent too much time on this already.

Nov 20 '05 #10

P: n/a
Cor
Hi Peace,

It is very easy to do and I will when I and you have both an answer from
Cindy,
I think it is extra about 4 lines of code.

Cor
I appreciate your concern about my wellbeing but it is not like I have not
tried and I have spent a good deal amount of time writing the excel sample
that was connected to this. I am putting in the legwork so please help if
you can. I also am in a production environment which I know you know what
that means and I have spent too much time on this already.

Nov 20 '05 #11

P: n/a
Thanks man.....

beginning to sweat this one.

"Cor" <no*@non.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi Peace,

It is very easy to do and I will when I and you have both an answer from
Cindy,
I think it is extra about 4 lines of code.

Cor
I appreciate your concern about my wellbeing but it is not like I have not tried and I have spent a good deal amount of time writing the excel sample that was connected to this. I am putting in the legwork so please help if you can. I also am in a production environment which I know you know what that means and I have spent too much time on this already.


Nov 20 '05 #12

P: n/a
Hi Cor,
But if I understand it wrong about that csv textfile

csv FORMAT, but not an actual file.

Peace needs to put his data in a delimited string format,
carried in a string variable (strMyData, let's call it).
The field delimiter doesn't have to be a comma, it could
also be a TAB character (Chr(9)) (which he has indicated
he'd prefer, as I recall), or anything else. Record
delimiter *must* be a Chr(13).

Once he has that, it has to go into a Word range, then it
can be converted to a Word table, roughly like this:

Dim rng as Word.Range = ActiveDocument.Range
rng.Collapse wdCollapseEnd
rng.Text = strMyData
Dim tbl as Word Table = rng.convertToTable('params here)

Thanks for providing the datatable to string manipulation
stuff in "NET-speak" :-)

-- Cindy

Nov 20 '05 #13

P: n/a
Hi Cindy,
this is peace I thought it was safe to go back to my old name.....
SO then, to create the delimited string with my array called datasetarray
how would I do this?

"Cindy M -WordMVP-" <C.*********@hispeed.ch> wrote in message
news:VA.000090b7.008df781@speedy...
Hi Cor,
But if I understand it wrong about that csv textfile

csv FORMAT, but not an actual file.

Peace needs to put his data in a delimited string format,
carried in a string variable (strMyData, let's call it).
The field delimiter doesn't have to be a comma, it could
also be a TAB character (Chr(9)) (which he has indicated
he'd prefer, as I recall), or anything else. Record
delimiter *must* be a Chr(13).

Once he has that, it has to go into a Word range, then it
can be converted to a Word table, roughly like this:

Dim rng as Word.Range = ActiveDocument.Range
rng.Collapse wdCollapseEnd
rng.Text = strMyData
Dim tbl as Word Table = rng.convertToTable('params here)

Thanks for providing the datatable to string manipulation
stuff in "NET-speak" :-)

-- Cindy

Nov 20 '05 #14

P: n/a
Hi Scorpion53061,
SO then, to create the delimited string with my array called datasetarray
how would I do this?

Cor was actually taking care of this part? I'm not that conversant in
NET-speak, yet, to be able to give you "good" code for the non-Word part.

Note that in the original discussion on your question about how to make a
table in Word I gave you an EXAMPLE what you could do. I didn't say you HAD
to have an array. It all depends on where you're starting from...

From the additional information you've provided since, in this thread, it
looks like you should go directly from your data to the delimited string;
an array would be an extra (and unnecessary) step.

What you NEED is the delimited string. How you get there depends entirely
on the specific circumstances. Use what's most efficient or convenient.

-- Cindy

Nov 20 '05 #15

P: n/a
sure. The whole exercise was because writing a dataset cell by cell in a
Word table was taking too long.

So hopefully if I can get this array to a delimited string I will be okay
from there. I will wait for Cor.

Thank you much for your help!!

"Cindy M -WordMVP-" <C.*********@hispeed.ch> wrote in message
news:VA.000090ca.0100e8fb@speedy...
Hi Scorpion53061,
SO then, to create the delimited string with my array called datasetarray how would I do this?
Cor was actually taking care of this part? I'm not that conversant in
NET-speak, yet, to be able to give you "good" code for the non-Word part.

Note that in the original discussion on your question about how to make a
table in Word I gave you an EXAMPLE what you could do. I didn't say you

HAD to have an array. It all depends on where you're starting from...

From the additional information you've provided since, in this thread, it
looks like you should go directly from your data to the delimited string;
an array would be an extra (and unnecessary) step.

What you NEED is the delimited string. How you get there depends entirely
on the specific circumstances. Use what's most efficient or convenient.

-- Cindy

Nov 20 '05 #16

P: n/a
Cor
Hi Peace,

Complete with test .
The first part is only to build up a table.

I hope it is also as Cindy told it, so lets wait her comments?

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
///
I hope this helps a little bit?

Cor
Nov 20 '05 #17

P: n/a
Cor,

Frustration.........
"Cor" <no*@non.com> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hi Peace,

Complete with test .
The first part is only to build up a table.

I hope it is also as Cindy told it, so lets wait her comments?

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
///
I hope this helps a little bit?

Cor

Nov 20 '05 #18

P: n/a
Cor
??

Frustration.........

Not at all, what do you mean?

Cor
Nov 20 '05 #19

P: n/a
I am frustrated due to lack of the ability to communicate what I am trying
to do. But that is my bad for not explaining it well.

A dataarray with 2 elements (dataarray(r,c)) where r = the rows of a dataset
and c is the columns of a dataset.

We want to write that dataarray to a delimited string.

It is back to the drawing board on this
"Cor" <no*@non.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl...
??

Frustration.........

Not at all, what do you mean?

Cor

Nov 20 '05 #20

P: n/a
Cor
Hi Scorpion,

That is the first part of the sample, just run and try it.
(Although if you wish is I will rewrite the first part also using the
stringbuilder (two rows of code), that is a little bit nicer if it is real a
hugh dataset)

I used a datatable,
but if you read
ds.tables(0) you have a datatable.

The second part of the sample changes xy to yx

Cor
I am frustrated due to lack of the ability to communicate what I am trying
to do. But that is my bad for not explaining it well.

A dataarray with 2 elements (dataarray(r,c)) where r = the rows of a dataset and c is the columns of a dataset.

We want to write that dataarray to a delimited string.

Nov 20 '05 #21

P: n/a
The datasets can be extremely huge depending if the enduser requests a lot
of data. :(

"Cor" <no*@non.com> wrote in message
news:u2**************@TK2MSFTNGP12.phx.gbl...
Hi Scorpion,

That is the first part of the sample, just run and try it.
(Although if you wish is I will rewrite the first part also using the
stringbuilder (two rows of code), that is a little bit nicer if it is real a hugh dataset)

I used a datatable,
but if you read
ds.tables(0) you have a datatable.

The second part of the sample changes xy to yx

Cor
I am frustrated due to lack of the ability to communicate what I am trying to do. But that is my bad for not explaining it well.

A dataarray with 2 elements (dataarray(r,c)) where r = the rows of a

dataset
and c is the columns of a dataset.

We want to write that dataarray to a delimited string.


Nov 20 '05 #22

P: n/a
Cor
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).t ostring)
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)
///
Nov 20 '05 #23

P: n/a
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>
"Cor" <no*@non.com> wrote in message
news:OF**************@tk2msftngp13.phx.gbl...
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).t ostring)
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)
///

Nov 20 '05 #24

P: n/a
Cor
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
Nov 20 '05 #25

P: n/a
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.

"Cor" <no*@non.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #26

P: n/a
Cor
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 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.

Nov 20 '05 #27

P: n/a
On Wed, 31 Dec 2003 12:13:00 -0600, Peace wrote:
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), " ")
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
"Peace" <Its the end of the world as we know it@here.com> schrieb
I am having trouble writing code to turn an array into a delimited
string.

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

rows and columns are integers representing rows and columns quanitity
of datasets.

Could someone help show what I am doing wrong?
When ever I write splitout to to a text file nothing is there.


How is DataArray declared? It would have to be a 2-dimensional array of
1-dimensional string arrays.

If DataArray is a string array, you can write
splitout = Join(DataArray, " ")

You can also use the shared method System.String.Join.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


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<ta b>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.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #28

P: n/a
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.
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:18******************************@40tude.net.. .
On Wed, 31 Dec 2003 12:13:00 -0600, Peace wrote:
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), " ")
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
"Peace" <Its the end of the world as we know it@here.com> schrieb
I am having trouble writing code to turn an array into a delimited
string.

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

rows and columns are integers representing rows and columns quanitity
of datasets.

Could someone help show what I am doing wrong?
When ever I write splitout to to a text file nothing is there.

How is DataArray declared? It would have to be a 2-dimensional array of
1-dimensional string arrays.

If DataArray is a string array, you can write
splitout = Join(DataArray, " ")

You can also use the shared method System.String.Join.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


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<ta b>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.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #29

P: n/a
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

Nov 20 '05 #30

P: n/a
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

Nov 20 '05 #31

P: n/a
> 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....
Nov 20 '05 #32

P: n/a
On Thu, 8 Jan 2004 11:40:39 -0600, scorpion53061 wrote:
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

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #33

P: n/a
Cor
Hi Cindy,

Thanks for the response even if you are busy.

Cor
Nov 20 '05 #34

This discussion thread is closed

Replies have been disabled for this discussion.