Page 1 of 1 1
Topic Options
#132884 - 2005-01-24 06:05 PM Pulling the right data!!
GSUK Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#132886 - 2005-01-24 07:09 PM Re: Pulling the right data!!
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I think the issues Glenn is having is with the duplicates. This should work.

Code:

dim $idArray
dim $emailArray
$ = open(1,'c:\blah.txt')
$curLine = trim(readline(1))
while @error=0
$lineArray = split($curLine,',')
$index = ascan($idArray, $lineArray[0])
if $index < 0
redim preserve $idArray[ubound($idArray)+1]
redim preserve $emailArray[ubound($emailArray)+1]
$idArray[ubound($idArray)] = $lineArray[0]
$emailArray[ubound($emailArray)] = $lineArray[1]
else
if not $emailArray[$index] and $lineArray[1]
$emailArray[$index] = $lineArray[1]
endif
endif
$curLine = trim(readline(1))
loop
$ = close(1)
for $j = 0 to ubound($emailArray)
if not $emailArray[$j]
$idArray[$j] ?
endif
next

_________________________
Eric

Top
#132887 - 2005-01-25 04:58 AM Re: Pulling the right data!!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Code:

$file='c:\dir\file.txt'
$array=readfile($file)
for each $item in $array
if right($item,1)=',' and not instr($item,$empties)
$empties=$emptied+$item
endif
next
if $empties
$empties=split(left($empties,-1),',')
endif
;now print array of empty IDs
for each $item in $empties
? 'ID = '+$item
next

_________________________
There are two types of vessels, submarines and targets.

Top
#132888 - 2005-01-25 09:37 AM Re: Pulling the right data!!
Richard H. Administrator Offline
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
#132889 - 2005-01-25 10:23 AM Re: Pulling the right data!!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I tested Macieps' code and it worked fine for me. No need for another UDF either as his includes all that is needed.
Top
#132890 - 2005-01-25 10:46 AM Re: Pulling the right data!!
GSUK Offline
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
#132891 - 2005-01-25 03:25 PM Re: Pulling the right data!!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Rich: Your're right, oversaw the 1030 special case. Darn assumptions.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.059 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org