#132884 - 2005-01-24 06:05 PM
Pulling the right data!!
|
GSUK
Starting to like KiXtart
Registered: 2004-03-10
Posts: 125
|
Hello everyone!
I have been frying my brain with this problem for several days now. Please bear with me while I try and explain what I need to do.
I have a file with a list of ID numbers and email addresses. Here is an example of the file:
1030,fred@hotmail.com 1030,john@hotmail.com 1030, 1041, 1041, 1043,fred@hotmail.com 1043, 1144, 1144,fred@hotmail.com 1150, 1150, 1150, 1150, 1150,
What I need the script to do is tell me which IDs have no associated email address. In this example the answer is 1041 and 1150.
Here's the code so far:
Code:
$Directory = "H:\kix\Reports\" $TempFile = ($Directory + "errors.txt") Del $TempFile /c $ID1 = "1" Open(1,$TempFile)
$ID = ReadLine(1) If @error = 0 While $ID <> 0 AND @ERROR = 0
? "Line is " $ID
$IDArray = Split($ID,",") ;Extract data from missing.txt $Count = 0 For Each $Element IN $IDArray Select Case $Count = 0 $IDx = $Element ;Set student ID Case $Count = 1 $email = $Element ;Set email address Case $Count = 2 ? "ERROR in file" EndSelect $Count = $Count + 1 Next ? "ID= " $IDx ? "email= " $email
If Len($email) = 0 ? "Setting flag" $Flag = "1" Else $Flag = "0" EndIf ? "Flag = " $Flag If $ID1 = "1" OR $IDx = $ID1 $ID1 = $IDx ? "ID1= " $ID1 Else If $Flag = "1" ? $IDx " has No email!" EndIf EndIf ? ""
$ID = ReadLine(1) Loop
Please excuse all the comments - it's a work in progress. 
I'm getting my knickers in a twist with this one! Any advice on how to proceed with this will be most appreciated.
Thanks in advance for all your help,
Glenn
|
|
Top
|
|
|
|
#132885 - 2005-01-24 06:37 PM
Re: Pulling the right data!!
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
look at READFILE() in the UDF forum...
then do something like:
look for value in element 2
$file='c:\dir\file.txt'
$array=readfile($file)
for each $line in $array
if instr($line,',')
$user=split($line,',')
if trim($user[1])=''
? $line
endif
else
? $line
endif
next
or
just look for @ symbol in the line
$file='c:\dir\file.txt'
$array=readfile($file)
for each $line in $array
if not instr($line,'@')
? $line
endif
next
|
|
Top
|
|
|
|
#132888 - 2005-01-25 09:37 AM
Re: Pulling the right data!!
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Jens,
You missed an important piece of information. Taking a small part of Glenn's example: Code:
1030,fred@hotmail.com 1030,john@hotmail.com 1030,
You code will incorrectly report "1030" as having no email addresses where in fact it has two.
You also have a typo 
Maciep's code it the way I would have approached it, and should do the job.
|
|
Top
|
|
|
|
#132890 - 2005-01-25 10:46 AM
Re: Pulling the right data!!
|
GSUK
Starting to like KiXtart
Registered: 2004-03-10
Posts: 125
|
maciep you're a star!! That works an absolute treat! Now all I have to do is get my head round how your script actually works. I've never used Ascan before.
Thanks for all your help guys.
Glenn.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 811 anonymous users online.
|
|
|