Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

arrays

 
   Database Help (Home) -> Visual Basic RSS
Next:  Calculate a percentage using 2 different query to..  
Author Message
Rob41

External


Since: Apr 07, 2004
Posts: 2



(Msg. 1) Posted: Tue Feb 22, 2005 3:26 pm
Post subject: arrays
Archived from groups: microsoft>public>vb>database (more info?)

is there a way to concatenate the contents of an array (looping through the
array) and storing each item in a comma delimited string?

Thanks!

 >> Stay informed about: arrays 
Back to top
Login to vote
Wart

External


Since: Jul 28, 2004
Posts: 7



(Msg. 2) Posted: Tue Feb 22, 2005 3:40 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rob,
Something like
Dim liCounter as Integer
dim lsString as String
for liCounter = LBound(MyArray) to UBound(MyArray)
lsString = lsString & MyArray(liCounter)
next

This assumes that MyArray is a one dimesional array. For N dimension arrays,
just wrap the For Next loop in other For Next loops for the other
dimensions.

HTH,
CF

"Rob" wrote in message

 > is there a way to concatenate the contents of an array (looping through
 > the
 > array) and storing each item in a comma delimited string?
 >
 > Thanks!
 >
 ><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: arrays 
Back to top
Login to vote
Veign2

External


Since: Feb 04, 2004
Posts: 123



(Msg. 3) Posted: Tue Feb 22, 2005 3:40 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

What have you tried? Just loop through the array adding the contents to
some variable. If the arrays hold any substantial amount of data you will
want to get away from string concatenation and use a CopyMemory API method -
will be way too slow with concatenation...

String Builder Class:
<a style='text-decoration: underline;' href="http://www.vbaccelerator.com/home/VB/Code/Techniques/StringBuilder/article.asp" target="_blank">http://www.vbaccelerator.com/home/VB/Code/Techniques/StringBuilder/article.asp</a>

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
<a style='text-decoration: underline;' href="http://www.veign.com/vrc_main.asp" target="_blank">http://www.veign.com/vrc_main.asp</a>
--

"Rob" wrote in message

 > is there a way to concatenate the contents of an array (looping through
the
 > array) and storing each item in a comma delimited string?
 >
 > Thanks!
 >
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: arrays 
Back to top
Login to vote
Rob41

External


Since: Apr 07, 2004
Posts: 2



(Msg. 4) Posted: Tue Feb 22, 2005 4:18 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Wart,

I'm still receiving the same results with your code which is similar to
mine:

For myCounter = 0 To myArrayCount - 1
Debug.Print myTestArray(myCounter)
strSQL = " where code = '" & myTestArray(myCounter)
MsgBox strSQL
Next myCounter

The above array contains 2 records based from a sql statement. When I run
the above, strSQL contains the correct data however, when the next myCounter
retrieves the next record, the first record is no longer available. Thus,
trying to concatenate the first to the last record ( the array will never
ever have more than 3 records).

The end results would be a string concatenated in to a sql statement
something like this where "myarrayrecord_#' are the records in the array:

"select * from table1 where code = 'myarrayrecord_1' and code =
'myarrayrecord_2'"

Thanks,
rob

"Wart" wrote in message

 > Rob,
 > Something like
 > Dim liCounter as Integer
 > dim lsString as String
 > for liCounter = LBound(MyArray) to UBound(MyArray)
 > lsString = lsString & MyArray(liCounter)
 > next
 >
 > This assumes that MyArray is a one dimesional array. For N dimension
arrays,
 > just wrap the For Next loop in other For Next loops for the other
 > dimensions.
 >
 > HTH,
 > CF
 >


  > > is there a way to concatenate the contents of an array (looping through
  > > the
  > > array) and storing each item in a comma delimited string?
  > >
  > > Thanks!
  > >
  > >
 >
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: arrays 
Back to top
Login to vote
Paul Clement

External


Since: Sep 02, 2003
Posts: 236



(Msg. 5) Posted: Wed Feb 23, 2005 12:10 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 22 Feb 2005 14:26:09 -0500, "Rob" wrote:

¤ is there a way to concatenate the contents of an array (looping through the
¤ array) and storing each item in a comma delimited string?
¤

How about the Join function?


Paul ~~~ pclement.DeleteThis@ameritech.net
Microsoft MVP (Visual Basic)
 >> Stay informed about: arrays 
Back to top
Login to vote
Veign2

External


Since: Feb 04, 2004
Posts: 123



(Msg. 6) Posted: Wed Feb 23, 2005 1:24 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

doh!...Totally forgot about that one...Thats just too simple<g>

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Paul Clement" wrote in message

> On Tue, 22 Feb 2005 14:26:09 -0500, "Rob" wrote:
>
> ¤ is there a way to concatenate the contents of an array (looping through
the
> ¤ array) and storing each item in a comma delimited string?
> ¤
>
> How about the Join function?
>
>
> Paul ~~~ pclement.DeleteThis@ameritech.net
> Microsoft MVP (Visual Basic)
 >> Stay informed about: arrays 
Back to top
Login to vote
Wart

External


Since: Jul 28, 2004
Posts: 7



(Msg. 7) Posted: Fri Mar 11, 2005 1:22 pm
Post subject: Re: arrays [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rob,
Sorry for the delay -
The key in my code was the lsString = lsString & ...
This takes the current variable value and adds the new element value to it,
thus concatenating the previous element values.
Your example simply replaces the value in the strSQL with the current
myTestArray(myCounter) value without preserving the previous values.
Your code should be something like
For myCounter = 0 To myArrayCount - 1
Debug.Print myTestArray(myCounter)
If strSQL = "" Then
'Initial pass through
strSQL = " where code = '" & myTestArray(myCounter)
else
'Concatenate the next values onto the previous values
strSQL = strSQL & " '" & myTestArray(myCounter)

end if
strSQL = " where code = '" & myTestArray(myCounter)
MsgBox strSQL
Next myCounter

HTH,
CF
"Rob" wrote in message

> Wart,
>
> I'm still receiving the same results with your code which is similar to
> mine:
>
> For myCounter = 0 To myArrayCount - 1
> Debug.Print myTestArray(myCounter)
> strSQL = " where code = '" & myTestArray(myCounter)
> MsgBox strSQL
> Next myCounter
>
> The above array contains 2 records based from a sql statement. When I run
> the above, strSQL contains the correct data however, when the next
> myCounter
> retrieves the next record, the first record is no longer available. Thus,
> trying to concatenate the first to the last record ( the array will never
> ever have more than 3 records).
>
> The end results would be a string concatenated in to a sql statement
> something like this where "myarrayrecord_#' are the records in the array:
>
> "select * from table1 where code = 'myarrayrecord_1' and code =
> 'myarrayrecord_2'"
>
> Thanks,
> rob
>
> "Wart" wrote in message
>
>> Rob,
>> Something like
>> Dim liCounter as Integer
>> dim lsString as String
>> for liCounter = LBound(MyArray) to UBound(MyArray)
>> lsString = lsString & MyArray(liCounter)
>> next
>>
>> This assumes that MyArray is a one dimesional array. For N dimension
> arrays,
>> just wrap the For Next loop in other For Next loops for the other
>> dimensions.
>>
>> HTH,
>> CF
>>
>> "Rob" wrote in message
>>
>> > is there a way to concatenate the contents of an array (looping through
>> > the
>> > array) and storing each item in a comma delimited string?
>> >
>> > Thanks!
>> >
>> >
>>
>>
>
>
 >> Stay informed about: arrays 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
sql query returns in wrong format - Hi, Hope someone can help me with this. I have MS SQL 2000 database where i have Table "PriceList" and there a column "Pricemk" wich is data type "money". All data in this column is in form "10001,35". So why when...

DataReport PageBreak - Hi everyone, I would like to know how to force pagebreak in a datareport for example after 5 records printed. Thank you all

Possible Use of a Cursor - I have a complex query that I hope I can explain it well enough for everyone to understand. I have a table that contains information for work instructions. Contained in the table are "MACHINE_PROC" these are groupings of machining processes....

Scroll Bars - Is there a way to find the size of scrollbars on a system using Visual Basic 6.0? I know how to look and change them on the display properties, but I don't know how to access that information from within Visual Basic.

Can I Update entire record in SQL ? - Heya, I am working on making a SQL database an exact mirror of a local Access database. I check the .mdb database every few minutes for new entries, if there are new entries, I retrieve them and write them to an exact replica table in SQL. This all work...
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]