p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   JOIN an array (http://p2p.wrox.com/showthread.php?t=20965)

Jen November 8th, 2004 02:40 PM

JOIN an array
Hi all

I need to take all instances of sub-item descriptions and pop them into another textbox as a concatenated string - so basically I am trying to define the sub-item descriptions as an array and then JOIN and TRIM them so that I end up with a string made up of all of these descriptions. I get a type mismatch error at the moment when I try to define Descrip as an array equal to the description field and when I take that line out (see below), I get a null string because it isn't pulling from anything. So basically my questions is: what am I doing wrong? And how do I join an array of strings into one result string?

This is my code:

Dim CountSub As Long
CountSub = Forms!frmPricingSheet!frmPricingsubform![SubItemCount]
Dim Descrip() As String
Descrip = Forms!frmPricingSheet!frmPricingsubform![Description] (Error here)

Dim CompDesc As String
ReDim Preserve Descrip(1 To CountSub) As String

CompDesc = ""
    For CountSub = 1 To UBound(Descrip)
        If Descrip(CountSub) <> "" Then
        If CompDesc = "" Then CompDesc = CompDesc & " "
        CompDesc = CompDesc & Trim(Descrip(CountSub))
    End If

Forms!frmPricingSheet![Description].Value = CompDesc



madhukp November 9th, 2004 05:38 AM

I could not understand your problem fully. What do you mean by "sub-item" ? May I know what is the object frmPricingsubform![Description] ? Is it a text box ? Are there a number of text boxes of this name in a form ?

I think you may have to use a control array of textboxes of same name. You can then join the texts as below.

strFinalString=Description(0).Text & Description(1).Text & .... & Description(n).Text

You have to have the number of textboxes in a variable say iNumTextboxes. Then the following script will do it.

For iLoop=0 to iNumTextboxes-1
    strFinalString=strFinalString & Description(iLoop).Text

Aal December 2nd, 2004 09:58 AM

Hi Jen . . .
Have u ever used this methode :

Dim mArr as Variant

    mArr = array(String1,String2,String3. . .)
    'this methode join the string automatically and read it as array
    '//now loops the mArr variable ( This methode almost similar with SPLIT methode. In this case the delimiter is " coma " ( the fixed delimeter ).

    For i = 1 to UBound(mArr)
        'Put the result in a Listbox for example
        list1.Additem mArr(i - 1)

Hope this, can help u to solve your problems . . .
and a, do you have some information about making Autorun Setup from CD's ?
However . . .have a nice coding Jen !!!

All times are GMT -4. The time now is 08:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.