Jump to content

Select ... Case Coding Problem


ioliver
 Share

Recommended Posts

I have a script that creates an online address book, using a text file formatted like this:

FirstName LastName,EmailAddress

One entry per Line.

I want to have AutoIt, put a Capitol Letter before each section of names...

Here's what I have so far:

; crate_contacts_html.au3
; October 8, 2004

; Crates the contacts.html page.
; REQUIRED: The contacts.txt file.  Should be Name,Email Address.  One per line.

RunWait(@ComSpec & " /c " & "sort c:\AwakeningRetreat\contacts.txt /O c:\AwakeningRetreat\contacts-abc.txt")
$contacts = FileOpen("c:\AwakeningRetreat\contacts-abc.txt",0)
$html = FileOpen("c:\AwakeningRetreat\contacts.html",2)
FileWriteLine($html, "<html>")
FileWriteLine($html, "<head>")
FileWriteLine($html, "<title> Awakening Community Contact List </title>")
FileWriteLine($html, "</head>")
FileWriteLine($html, "<body bgcolor='white'>")
FileWriteLine($html, "<body>")
FileWriteLine($html, "<h1> <font color='black'> Awakening Community Contact List </font> </h1>")
FileWriteLine($html, "<hr>")
FileWriteLine($html, "<blockquote>")
FileWriteLine($html, "<h4> <font color='black'> Contacts: </font> <h4>")
$abc = 0
While 1
  $line = FileReadLine($contacts)
  If @error = -1 Then ExitLoop
  $array = StringSplit($line,",")
  Call("ABCLabel")
  FileWriteLine($html, $array[1] & ", <a href=mailto:" & $array[2] & ">" & $array[2] & "</a><br>")
Wend
FileWriteLine($html, "</blockquote>")
FileWriteLine($html, "If your name is not on the list, or if you have a correction, please send an email to <myemailaddress>")
FileWriteLine($html, "</body>")

; Cleanup
FileClose($html)
FileClose($contacts)
FileDelete("c:\AwakeningRetreat\contacts-abc.txt")

MsgBox(0, "create_contacts_html.au3", "Complete!")

Func ABCLabel()
  Select
    Case $abc < 1
           If StringLeft($line,1) = "A" Then
             FileWriteLine($html, "<h3>A</h3>")
             $abc = 1
           EndIf

    Case $abc < 2
           If StringLeft($line,1) = "B" Then
             FileWriteLine($html, "<h3>B</h3>")
             $abc = 2
           EndIf

    Case $abc < 3
           If StringLeft($line,1) = "C" Then
             FileWriteLine($html, "<h3>C</h3>")
             $abc = 3
           EndIf

    Case $abc < 4
           If StringLeft($line,1) = "D" Then
             FileWriteLine($html, "<h3>D</h3>")
             $abc = 4
           EndIf
           
    Case $abc < 5
           If StringLeft($line,1) = "E" Then
             FileWriteLine($html, "<h3>E</h3>")
             $abc = 5
           EndIf

    Case $abc < 6
           If StringLeft($line,1) = "F" Then
             FileWriteLine($html, "<h3>F</h3>")
             $abc = 6
           EndIf
           
    Case $abc < 7
           If StringLeft($line,1) = "G" Then
             FileWriteLine($html, "<h3>G</h3>")
             $abc = 7
           EndIf

    Case $abc < 8
           If StringLeft($line,1) = "H" Then
             FileWriteLine($html, "<h3>H</h3>")
             $abc = 8
           EndIf

  EndSelect
EndFunc

The function works well as long as there is a FirstName with each letter of the Alphabet, but if there is no "G" for example then the Function keeps selecting the Case $abc < 7 and never gets to $abc <8. I know why this happens. I just can't come up with a way around it...

Any suggestions are appericated.

Thanks for all your hlep,

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

  • Developers

this function will also fill the gaps (untested):

Global $ABC = Asc("A") - 1
;
Func ABCLabel()
   $StartLetter = Asc(StringUpper(StringLeft($line, 1)))
   If $StartLetter = $ABC Then Return
   For $x = $ABC + 1 To $StartLetter
      FileWriteLine($html, "<h3>G</h3>")
      $ABC = $x
   Next
EndFunc  ;==>ABCLabel
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...