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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array declaration

Status
Not open for further replies.

bhas

Programmer
Mar 17, 2004
30
US
Is declaring an array like this correct?

Function Check_Val(ByRef arrArray)
Dim row As Integer, j As Integer
For row = LBound(arrArray) To UBound(arrArray) - 1
For j = row + 1 To UBound(arrArray)
If arrArrray(j) = arrArray(row) Then
Check_Val = arrArray(row)
Exit Function
End If
Next
Next
Check_Val = ""
End Function
 
VBScript does not support strong typing. You can only use Variant data.

What you have looks like VB syntax instead.

Try:

[tt]Dim row, j[/tt]

VBScript arrays always have a lower bound of zero (0) so while LBound() works it is largely redundant.

Then there is the question of your function's parameter. Is it truly an array, or possibly a Variant containing an array?

For an array you'd probably want:

[tt]Function Check_Val(ByRef arrArray())[/tt]

For the most part this won't matter in VBScript however.
 
Hello bhas,

You've a typo arrArrray(j). Correct it and the function should perform. Dim row, j should be as dilettante said. Also keep the same problem in one single thread.

regards - tsuji
 
Additional notes:

If any problem might occur, it may be related to the arrArray itself not properly made before passing to the function. Example:
Code:
arrArray=array(2,3,5,3,4,2)
wscript.echo check_val(arrArray)

Function Check_Val(ByRef arrArray)
Dim row , j 
For row = LBound(arrArray) To UBound(arrArray) - 1
For j = row + 1 To UBound(arrArray)
If arrArray(j) <> arrArray(row) Then
Check_Val = arrArray(row) 
Exit Function
End If
Next
Next
Check_Val = ""
End Function
- tsuji
 
Tsuji,
Thanks for your reply but i dont know the data in the array.
I am looking at a field which has numbers and if there are duplicates in the field.
I want the function to return only those numbers which does not have duplicates.
Thanks for your effort.
 
hello,
desperately need help on this
 
I am looking at a field which has numbers and if there are duplicates in the field
How are the numbers put in the field ?
Which sort of field ?
Any chance you could post some snippets helping us helping you ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
This is bascially Biztalk mapper field.
we have a text file which has series of columns having data and this data is bascially patient details like patname,acession number,dob etc..
These acession numbers repeat sometimes if the patient details are multiple.
so what i would like to do is to look at the data and remove the duplicate numbers and take the others and map.
For doing this we have to create a vbscript function which will do this for us in the mapping.
Can you help please!
 
Some input examples and expected results will be helpfull, don't you think so ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Input examples: There are about fields in the file.
This file has details about accession numbers and patient details like name ,sex, dob,procedure code etc. This accession numbers are unique for each patient. But they are repeating for every procedure code the patient has undergone.
So if a patient has four procedure codes i would like to see only once the detials of the accession number and patient details but the procedure code has to repeat for four time since it has four code but the patient detials has to be only once.
Example:1. Accession numbers 1324-9, patient name roger smith, DOB 14/06/1992, procedure code 124567.
2. Acession numbers 1324-9, patient name roger smith, dob 14/06/1992, procedure code 12890.

So from the example above i want a accession number the two procedure code.
How do i do this in vbscript.
Thanks for your answer.
Please respond urgent

 
And what have you so far ?
How you read and parse the input file ?
How you write the output file ?
I guess a Dictionary object instead of an array is an answer for your intent.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
This is what i ahve so far.
I am not sure about the dictionary object?
Can you send me the code for this.
That will be great help.
Please respond

Function Check_Val(ByRef arrArray)
arrArray=array(33999-9,1090668-7,1108756-0,1117483-4)
arrArray1=array(25429-8,382605-3,586545-3,596723-6,597718-0,597853-3,598866-4)
Dim row , j , row1, k
For row = LBound(arrArray) To UBound(arrArray) - 1
For j = row + 1 To UBound(arrArray)
For row1 = LBound(arrArray) To UBound(arrArray1) - 1
For k = row + 1 To UBound(arrArray1)
If arrArray(j) = arrArray(row) Then
Check_Val = arrArray1(row1)
Exit Function
End If
If arrArray(k) <> arrArray(row) Then
Check_Val = arrArray1(row1)
Exit Function
End If
Next
Next
Next
Next
Check_Val = arrArray1(row1)
End Function
 
Where is the code reading and parsing the input file ?
Where is the code calling your Check_Val function with an array parameter you destroy within the function ?
Where is the code writing the result ?
Please, read carefully the link to the faq in my signature.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 

Here are my answers
Where is the code reading and parsing the input file ?
The for loop with lbound and ubound is doing that right?

Where is the code calling your Check_Val function with an array parameter you destroy within the function ?
Where is the code writing the result ?

At the end i am returning the value that is being used for the map.
I am totaly new to the vbscript, can you help please?
 
bhas said:
Example:1. Accession numbers 1324-9, patient name roger smith, DOB 14/06/1992, procedure code 124567.
2. Acession numbers 1324-9, patient name roger smith, dob 14/06/1992, procedure code 12890
Can you post your entire script (except your broken Check-Val function) that read and parse your above example ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I dont have any other script.
like i said i am new to this and i am not sure how to go about it.
can you tell me how to write the script that reads and parses the example.
Thanks for your answer.
 
Do a keyword search in this forum for fso split, study the examples so get and come back with what you have written on your own.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I did and pulled this file from that bunch and this is what i found.
But i dont know how to look for the duplicate value from the file.
any help please


Const ForReading = 1
Dim fso, MyFile, Text, Fail
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso_OpenTextFile("E:\LabCorpNovBC10.txt", ForReading)

Do While myFile.AtEndOfStream <> True

teststr = myfile.readline
if instr(Accession, "") > 0 then exit do

loop
myfile.close
linewewant = split(teststr,"=")
numaddressesfree = linewewant(1)
 
Assuming you're only interested in the Accession numbers lines of your input file and that the expected result of your example is something like this:
Accession numbers 1324-9, patient name roger smith, DOB 14/06/1992, procedure code 124567. procedure code 12890
You can try something like this:
Const ForReading = 1
Dim fso, MyFile, teststr, a, d, k, i
Set d = CreateObject("Scripting.Dictionary")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso_OpenTextFile("E:\LabCorpNovBC10.txt", ForReading)
Do While MyFile.AtEndOfStream <> True
teststr = myFile.ReadLine
If InStr(1,teststr,"Accession",1) > 0 Then
a=Split(teststr,",")
k=a(0)
If d.Exists(k) Then
d.Item(k) = d.Item(k) & a(UBound(a))
Else
d.Add k,teststr
End If
End If
Loop
MyFile.Close
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
a = d.Items
For i = 0 To d.Count-1
MyFile.WriteLine a(i)
Next
MyFile.Close

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks a lot for your help.
Biztalk mapper accepts only functions, so is it anyway i can write this in a function.
Also what if i have to do samething what you have done for accession number to other patient details like dob, sex, name etc.
Thanks again for your help and support.
Please respond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top