Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript array values not appearing in print display check

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Hello

I am not seeing the array value in my print display with the following code

The print displays only the print headers



dim sComment
dim aLine
dim sLine
dim aField
sComment="1:CPT:97140:1" & char(13)& char(10) & _
"2:CPT:97110:1" & char(13)& char(10) & _
"3:CPT:97035:1" & char(13)& char(10) & _
"4:CPT:97033:1" & char(13)& char(10) & _
"5:CPT:97010:1" & char(13)& char(10) & _
"6:CPT:97014:1" & char(13)& char(10) & _
"7:CPT:97001:1"

'note: sometimes linefeeds are used without carriage returns, the following straightens this out
'usually you should see carriage return followed by a line feed - but sometimes you'll find
'just a line feed or a carriage return all by itself
'we fix this by replacing line feeds with carriage returns and then replacing
'all double carriage returns with single carriage returns
sComment = replace(sComment,char(10),char(13)) 'replace line feeds with carriage returns
sComment = replace(sComment,char(13)& char(13),char(13)) 'replace double returns with single

aLine=split(sComment,char(13))

'dim iRow, aTarget (len(aLine), 4) 'creates an array to store the rows with the needed fields

dim iRow, aTarget(1, 4) 'creates an array to store the rows with the needed fields
Redim aTarget(len(aLine),4) 're-dimension the array to the proper size



iRow=0

for each sLine in aLine

If len(sLine)>0 then
aField=split(sLine,":")
'note: you may want to test the length

'now add the values to a multi dimensional array.
iRow=iRow+1 'increment rows and add to the target array
aTarget(iRow,1)=aField(1)
aTarget(iRow,2)=aField(2)
aTarget(iRow,3)=aField(3)
aTarget(iRow,4)=aField(4)


print ("aField(1)")
print aField(1) 'should show "1" first time through
print ("aField(2)")
print aField(2) 'should show "CPT"
print ("aField(3)")
print aField(3) 'should show "97140" first time through
print ("aField(4)")
print aField(4) 'should show "1
 
Code:
print (aField(1))

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Or
Code:
Dim I as integer

For I = 0 to unbound(afield)
  print (aField(I))
Next

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hello

I tried the for loop and I getting the following syntax error


"Expected end of statement

"Dim I as integer"

 
1) there are no type declarations in vbscript, so skip meant "Dim I", not "Dim I as integer".

2) what is "char(13)"??? did you mean chr(13)??? And what is "print"???

3) Redim aTarget(len(aLine),4) is wrong for two reasons; First, you want to redim the first element to be the "number of lines", which would be ubound(aline) not len(aline). But, you can't do that anyway, you can only redim the LAST element of a multidimensional array

4) Why do you need to store the information in an array at all? In other words, once you have extracted the information you want, what is your ultimate goal? In all these posts you keep making, it seems like you are not giving us the bigger picture... once you do, the solution will come quickly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top