syntax help

Results 1 to 2 of 2

Thread: syntax help

  1. #1
    Join Date
    Dec 1969

    Default syntax help

    I want to modify a string of 80 characters by inserting various set of strings/chars at different points and lengths. For example if my string is 1234567890, after going thru the string the new string could be co34f678e0.<BR><BR>costcenter = string I&#039;m trying to modify<BR>arrSegments = 2-d array of description(0), starting pos(1) and length(2). i don&#039;t use description so I only access 1 & 2.<BR>codeArray = 1-d array containing the string that must be inserted at various points in the costcenter<BR><BR>I get a type mismatch at this point in the code:<BR>Mid( strModifiedCostCenter, arrSegments(2, intCounter), arrSegments(1, intCounter) ) = newcostcenter<BR><BR>I suspect VBScript doesn&#039;t like the syntax. A co-worker of mine who used this same function in VB didn&#039;t have problems though. Wiil someone pls tell me how to fix this? Thanks.<BR><BR>Function ModifyCostCenter()<BR> dim intCounter<BR> strModifiedCostCenter = costcenter & Space(80 - Len(costcenter))<BR> if numOfSegs &#062; 1 then &#039;recordcount is more than 1<BR> for intCounter = 0 to numOfSegs - 1<BR> &#039; if starting position for first record is not zero<BR> if arrSegments(2,intCounter) &#060;&#062; 0 Then<BR> &#039; if code entered exceeds that of required length<BR> if len(codeArray(intCounter)) &#062; arrSegments(1,intCounter) then<BR> Mid( strModifiedCostCenter, arrSegments(2, intCounter), arrSegments(1, intCounter) ) = Left( codeArray(intCounter), arrSegments(1, intCounter) )<BR> else<BR> newCostCenter = codeArray(intCounter) & Space( arrSegments(1, intCounter) - Len( codeArray(intCounter) ) )<BR> Mid( strModifiedCostCenter, arrSegments(2, intCounter), arrSegments(1, intCounter) ) = newcostcenter<BR> &#039;Mid( strModifiedCostCenter, 1, 5 ) = newcostcenter<BR> end if<BR> else<BR> Mid(strModifiedCostCenter, 1, 80) = codeArray(0) & Space( 80 - len( codeArray(0) ) )<BR> end if<BR> next<BR> else<BR> &#039;if recordcount is 1 or nothing<BR> Mid(strModifiedCostCenter, 1, 80) = codeArray(0) & Space(80 - len(codeArray(0)))<BR> end if<BR> ModifyCostCenter = strModifiedCostCenter<BR>End function

  2. #2
    Join Date
    Dec 1969

    Default You're close

    Mid() returns a section of a string. You want to Replace() that section with your new section.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts