Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "seprate coulmn from line." in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 16th, 2008, 12:12 PM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default seprate coulmn from line.

this is exist function in my code.this is used for splitting coulmn form a line .
coulmn is seprated by comma.i have maximum 4 coulmns in a line.but problem is my fourth column can contain more than one value
like this
200044,ABC125,Y,FD,FC,FY
but problem is this is working fine if coulmn 4 has no value or only one value.but suppose it has more than one value like example i mentioned then in this case only it return first value of col 4 which is FD.but i want those value which is after FD.how to modify this function.basically this function is written in vb.
hope it makes some sense.
Code:
Function mbGetLineArray(ByVal vsSource As String, _
                                ByVal vlColumnCount As Long, _
                                ByRef rasLineArray() As String, _
                                Optional vsSeparator As String = ",") As Boolean


Dim bReturn As Boolean
Dim nPosition As Integer
Dim nLength As Integer
Dim n1 As Integer
    On Error GoTo ErrorHandler

    ReDim rasLineArray(vlColumnCount - 1)
  
    For n1 = 0 To (vlColumnCount - 2)
      If InStr(1, vsSource, ",") = 0 Then vsSource = vsSource & ","
      
      If Left(vsSource, 1) = """" Then
        vsSource = Mid(vsSource, 2)
        rasLineArray(n1) = Left(vsSource, InStr(1, vsSource, """,") - 1)
        
        nPosition = 1
        Do Until InStr(nPosition, rasLineArray(n1), """""") = 0
          nPosition = InStr(nPosition, rasLineArray(n1), """""")
          If nPosition = 1 Then
            rasLineArray(n1) = Mid(rasLineArray(n1), nPosition + 1)
          Else
            rasLineArray(n1) = Left(rasLineArray(n1), nPosition - 1) & Mid(rasLineArray(n1), nPosition + 1)
          End If
          nPosition = nPosition + 1
        Loop
        
        vsSource = Mid(vsSource, InStr(1, vsSource, """,") + 2)
      
      Else
        nLength = InStr(1, vsSource, ",") - 1
        If nLength = 0 Then
          'nothing to do for this element as it is blank, but we want to continue as
          'there are more elements to be parsed from this string.
        ElseIf nLength > 0 Then
          rasLineArray(n1) = Left(vsSource, nLength)
        Else
          'we have reached the final element so there is no point continuing to loop.
          'the final value will be handled by the code following the for-next loop.
          Exit For
        End If
        vsSource = Mid(vsSource, nLength + 2)
      End If
    Next n1
    
    If vsSource <> vbNullString Then
    
        If Left(vsSource, 1) = """" Then
          If InStr(1, vsSource, """,") <> 0 Then
            vsSource = Mid(vsSource, 2)
            vsSource = Left(vsSource, InStr(1, vsSource, """,") - 1)
            vsSource = Replace(vsSource, """""", """")
          Else
            vsSource = Mid(vsSource, 2)
            vsSource = Left(vsSource, Len(vsSource) - 1)
          End If
        Else
          If InStr(1, vsSource, ",") <> 0 Then
            vsSource = Left(vsSource, InStr(1, vsSource, ",") - 1)
          End If
        End If
        
        rasLineArray(n1) = Trim(vsSource)
        
    End If
    

End Function
vsSource - source string to split up
vlColumnCount - expected number of columns
[vsSeparator] - column separator (default to comma)
rasLineArray - array containing split up line
__________________
Love is physical attraction and mental destruction
Reply With Quote
Sponsored Links
  #2  
Old July 16th, 2008, 12:32 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 817
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Why not just use a different delimiter for that 4th element?
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
  #3  
Old July 16th, 2008, 12:36 PM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

no i can use bcoz csv file is coming from client.so i can not make any chnages to it.
Reply With Quote
  #4  
Old July 16th, 2008, 12:49 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 817
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

I see...will there always only be four positions? If so, when you are in the 4th position of the loop, you can perform some data formatting and then exit the loop.
Reply With Quote
  #5  
Old July 16th, 2008, 12:54 PM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

yes only 4 coulmns but 4 th one may more than one value with seprated comma.after spliiting i m passing values to stored procedure.so my arrayname(3) mean 4th coulmn has values like FD,FY,FH.this code is not written by me.so can u give me some idea where exactly i have to check 4 th coulmn and exit from loop.
Reply With Quote
  #6  
Old July 16th, 2008, 01:01 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 817
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

I'm not familiar with this function so it would be difficult for me to say. However, if you can attach a sample ASP page and populate the array used with some sample data, I might be able to give you a solution when I get home from work.
Reply With Quote
  #7  
Old July 16th, 2008, 02:26 PM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

this is the sample data rite now i have
200044,ABC125,Y,FD,FC,FY
200055,,,
200048,ABC124,N,FD
200044,ABC125,Y,FD,FC,FY,dd,ss

i have to done this at vb end only.its similar to vbscript
Reply With Quote
  #8  
Old July 16th, 2008, 06:32 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 817
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Wait, just realized that you said this is a VB file. Even though this is similar to ASP, I will move it to the Visual Basic forum if this is a VB file.

As for your code problem, look for the portion of the script where it is iterating through your array. This is where you will want to check if it is the 4th position or not. If it is, then exit the loop and continue processing as normal.
Reply With Quote
  #9  
Old July 17th, 2008, 04:53 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

hey i found the place where i have to do some stuff .but now how to go ahead now.what to do now?
Code:
 If nLength = 0 Then
          'nothing to do for this element as it is blank, but we want to continue as
          'there are more elements to be parsed from this string.
        ElseIf nLength > 0 Then
          rasLineArray(n1) = Left(vsSource, nLength)
        Else
          'we have reached the final element so there is no point continuing to loop.
          'the final value will be handled by the code following the for-next loop.
          Exit For
        End If
Reply With Quote
  #10  
Old July 17th, 2008, 08:30 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 126
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

i gotted now.here is final code
Code:
 ReDim rasLineArray(vlColumnCount - 1)
  
    For n1 = 0 To (vlColumnCount - 2)
      If InStr(1, vsSource, ",") = 0 Then vsSource = vsSource & ","
      
      If Left(vsSource, 1) = """" Then
        vsSource = Mid(vsSource, 2)
        rasLineArray(n1) = Left(vsSource, InStr(1, vsSource, """,") - 1)
        
        nPosition = 1
        Do Until InStr(nPosition, rasLineArray(n1), """""") = 0
          nPosition = InStr(nPosition, rasLineArray(n1), """""")
          If nPosition = 1 Then
            rasLineArray(n1) = Mid(rasLineArray(n1), nPosition + 1)
          Else
            rasLineArray(n1) = Left(rasLineArray(n1), nPosition - 1) & Mid(rasLineArray(n1), nPosition + 1)
          End If
          nPosition = nPosition + 1
        Loop
        
        vsSource = Mid(vsSource, InStr(1, vsSource, """,") + 2)
      
      Else
        nLength = InStr(1, vsSource, ",") - 1
        If nLength = 0 Then
          'nothing to do for this element as it is blank, but we want to continue as
          'there are more elements to be parsed from this string.
        ElseIf nLength > 0 Then
          rasLineArray(n1) = Left(vsSource, nLength)
        Else
          'we have reached the final element so there is no point continuing to loop.
          'the final value will be handled by the code following the for-next loop.
          Exit For
        End If
        vsSource = Mid(vsSource, nLength + 2)
      End If
    Next n1
    
    If vsSource <> vbNullString Then
    
        If Left(vsSource, 1) = """" Then
          If InStr(1, vsSource, """,") <> 0 Then
            vsSource = Mid(vsSource, 2)
            If Not vbFillLastColumn Then
              vsSource = Left(vsSource, InStr(1, vsSource, """,") - 1)
            End If
            vsSource = Replace(vsSource, """""", """")
          Else
            vsSource = Mid(vsSource, 2)
            vsSource = Left(vsSource, Len(vsSource) - 1)
          End If
        Else
          If InStr(1, vsSource, ",") <> 0 Then
            If Not vbFillLastColumn Then
               vsSource = Left(vsSource, InStr(1, vsSource, ",") - 1)
            End If
          End If
        End If
        
        rasLineArray(n1) = Trim(vsSource)
        
    End If

Comments on this post
jmurrayhead agrees: Good job, Guddu
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 01:43 PM.



Content Relevant URLs by vBSEO 3.2.0