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

Reading Writing Values to a File 1

Status
Not open for further replies.

MyFlight

Technical User
Feb 4, 2002
193
OK,

Lets see if I can simplify what I want to do. I tend to get carried away in my explanations, and I apologize in advance.

NOTE: Most of the Script for sending this information from the TEXT File to the Comm Port is already working.
Mostly thanks to KNOB and HANK3.

1. Basically I am Connecting to a ROLM PhoneMail system (logging in and moving to the “Function:” Prompt).

2. Second I need to Purge the 1st Extension From the TestFile.text in PhoneMail.

a. If Successful write the sDone Variable (“COMPLETED”) to the 1st Line next to the Extension.
b. IF NOT Successful write the sProblem Variable (“INCOMPLETE”) to the 1st Line next to the Extension

3. Next I need to Modify the PhoneMail Box itself (i.e. Change the Password etc).

a. If Successful write the sDone Variable (“COMPLETED”) to the 1st Line next to the Extension.
b. IF NOT Successful write the sProblem Variable (“INCOMPLETE”) to the 1st Line next to the Extension

4. Upon Completion of the Script File I want to Save the Updated TestFile.txt File.

a. If Carrier is lost Save the File.
b. If Script completes successfully Save the File.

5. I have a Text File (will call it TestFile.txt), that contains a list of Values (Extensions).
a. I do not know if the Extension Length will remain Constant.
b. The Number of Extensions in the TestFile.txt will vary.

6. I would like to Transmit the 1st value in the TestFile.txt. (ALREADY Working)

a. If NO Error Message is received, insert the Word "COMPLETED", Next for the 1st Value.
b. If an ERROR message is received I want to insert the Word "INCOMPLETE", Next for the 1st Value.


7. If Dial Tone is LOST I would Like to Save the File so that I can Pick Up where the Script Left off. Please Note, this does not necessarily need to be automated (but it would be nice).

8. Assumption Number One: The Extensions are 4 Digits in length (For Arguments Sake, this may vary).

9. When I try to Update the File it either overwrites the Whole File, or writes all the information in one continuous line.

10. Here is an example of what I want to do.

EXAMPLE:

1234
1235
1236
1237
1238

UPDATED TEXT FILE:

1234 COMPLETED INCOMPLETE
1235 INCOMPLETE COMPLETED
1236 COMPLETED COMPLETED
1237 INCOMPLETE
1238


11. What I need to figure out is the portion of the Script file to write items 2a and 2b to the TextFile.txt.
a. I am Using the Following Variables in my Script File:
1. sLine ;Line of text Read from TestFIle.txt
2. sTok1 ;Variable
3. sDone = “COMPLETED” ; Used when Extension (From TestFile.txt) Is either Purged or Modified Successfully
4. sProblem = “INCOMPLETE” ; Used when Extension (From TestFile.txt) Is either NOT Purged or Modified.
5. fgets 1 sLine ;Retrieves the 1 Record in the TestFile.txt File


proc main
string szNewPswd,szSiteName,sTok1,sLine
string sEnter = "^M"
string sDone = "COMPLETE"
string sProblem = "INCOMPLETE"
sdlginput "Site Name" "Enter Site Name:" szSiteName ; Assigns Site Name to the Variable szSiteName
pause 1
sdlginput "New Password" "Enter the New DEFAULT Password:" szNewPswd ; Assigns Password to szNewPswd
pause 1
strcat szNewPswd sEnter

if isfile "C:\Temp Data Files\Raw Data\TestFile.txt" ; Verifies that File does Exist.
fopen 1 "C:\Temp Data Files\Raw Data\TestFile.txt" READ TEXT ; Opens Text File
while not feof 1
fgets 1 sLine
strtok sTok1 sLine "," 1 ; Assigns Text in First Field (From Text File) to Variable sTok1.
strreplace sLine " " " "
waitfor "Function: " FOREVER
transmit "PROFILE^M"
waitfor "Action: "
transmit "PURGE^M"
waitfor "Subscriber Name or Extension: "
transmit sTok1 ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
transmit "^M"
if waitfor "Function: " 10
transmit "PROFILE^M"
waitfor "Action: "
transmit "MODIFY^M"
waitfor "Subscriber Name or Extension: "
transmit sTok1 ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
transmit "^M"
if waitfor "PhoneMail Password : (Previous = ##########): " 10
transmit szNewPswd

;INSERT WRITE sDone TO TEXT FILE SCRIPT HERE

else
transmit ";^M"

;INSERT WRITE sProblem TO TEXT FILE SCRIPT HERE

endif
else
transmit ";^M"
waitfor "Function: "
transmit "PROFILE^M"
waitfor "Action: "
transmit "MODIFY^M"
waitfor "Subscriber Name or Extension: "
transmit sTok1 ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
transmit "^M"
if waitfor "PhoneMail Password : (Previous = ##########): " 10
transmit szNewPswd

;INSERT WRITE sDone TO TEXT FILE SCRIPT HERE

else
transmit ";^M"

;INSERT WRITE sProblem TO TEXT FILE SCRIPT HERE

endif
endif
endwhile
endif
fclose 1
fclose 2
transmit ";^M"
waitfor "Function: " forever
transmit "LOG^M"
waitfor "Action: " forever
transmit "LOG^M"
capture OFF
hangup
endproc

I HOPE I HAVE EXPLAINED THIS PROPERLY
 
Here's the script I came up with:

proc main
string sLine
string sDone = " COMPLETE"
string sProblem = " INCOMPLETE"
integer iLen

if isfile "C:\TestFile.txt" ; Verifies that File does Exist.
fopen 1 "C:\TestFile.txt" READWRITE TEXT ; Opens Text File
while not feof 1
fgets 1 sLine
strlen sLine iLen
if iLen == 0
exitwhile
endif

;INSERT WRITE sDone TO TEXT FILE SCRIPT HERE
fseek 1 (-2) 1
finsblock 1 9
fwrite 1 sDone 9

;INSERT WRITE sProblem TO TEXT FILE SCRIPT HERE
finsblock 1 11
fwrite 1 sProblem 11
fseek 1 2 1
endwhile
endif
fclose 1

endproc

I did some paring from your original script so I could just concentrate on the pertinent material. I added an integer variable called iLen, which holds the length of sLine. I also added a check on this value and exit the while loop if the length of sLine is zero. I also modified sDone and sProblem to add a space to the beginning of each string, since that is what you wanted the output to look like. Finally, I show how to insert the necessary text. The first fseek command backs up the file pointer two bytes to account for the carriage return and line feed at the end of each line of text (you might want to view your input file in a hex editor to make sure your text file is in this format). I then use the finsblock command to insert room for the string, then add the string using the fwrite command instead of the fputs command (the fwrite command does not add the carriage return and line feed that the fputs command would). I then use a second finsblock and fwrite command to add the second result string, then use fseek again to jump over the previously-read carriage return and line feed. This puts us in the proper position to read the next string.
aspect@aspectscripting.com
 
KNOB,

One problem left. I used a the following Extensions in MY TestFfile.txt (1244, 12334, 1235, 1241, 1236), this is the Format the File will ultimatly have. I would like to use a Hex Editor to check the File, but; One, I don't think I have the program, Two, I don't really know how to use it. The text file is something that is basically created by the Customer in Notepad, or Wordpad. When I incorporated your ideas into my script (by the way Thank you Very Much), I get the folowing:

Function: ;
Sat Sep 7, 2002 4:57 PM

Function: PROFILE
Sat Sep 7, 2002 4:57 PM

Action: PURGE

Subscriber Name or Extension: 1244

Cannot find this form.

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: MODIFY

Subscriber Name or Extension: 1244

Cannot find this form.

Subscriber Name or Extension: ;

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: PURGE

Subscriber Name or Extension: 34

Cannot find this form.

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: MODIFY

Subscriber Name or Extension: 34

Cannot find this form.

Subscriber Name or Extension: ;

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: PURGE

Subscriber Name or Extension: 35

Cannot find this form.

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: MODIFY

Subscriber Name or Extension: 35

Cannot find this form.

Subscriber Name or Extension: ;

Function: PROFILE
Sat Sep 7, 2002 4:58 PM

Action: PURGE

Subscriber Name or Extension: 41

Cannot find this form.

Function: PROFILE
Sat Sep 7, 2002 4:59 PM

Action: MODIFY

Subscriber Name or Extension: 41

Cannot find this form.

Subscriber Name or Extension: ;

Function: PROFILE
Sat Sep 7, 2002 4:59 PM

Action: PURGE

Subscriber Name or Extension: 36

Cannot find this form.

Function: PROFILE
Sat Sep 7, 2002 4:59 PM

Action: MODIFY

Subscriber Name or Extension: 36

Cannot find this form.

Subscriber Name or Extension:

After the First Extension it seems to only get the last 2 characters in the Extension.

Here is the Updated Script File:

Code:
proc main
string szNewPswd,szSiteName,sTok1,sLine
string sEnter = "^M"
string sDone = " COMPLETE"
string sProblem = " INCOMPLETE"
integer iLen
sdlginput "Site Name" "Enter Site Name:" szSiteName                         ; Assigns Site Name to the Variable szSiteName
   pause 1
sdlginput "New Password" "Enter the New DEFAULT Password:" szNewPswd        ; Assigns Password to szNewPswd
   pause 1
strcat szNewPswd sEnter

if isfile "C:\Temp Data Files\Raw Data\TestFile.txt"                                               ; Verifies that File does Exist.
   fopen 1 "C:\Temp Data Files\Raw Data\TestFile.txt" READ TEXT                    ; Opens Text File 
   while not feof 1
      fgets 1 sLine
      strlen sLine iLen
      if iLen == 0
         exitwhile
      endif
      strtok sTok1 sLine " " 1                                ; Assigns Text in First Field (From Text File) to Variable sTok1.
;      strreplace sLine " " " "
      waitfor "Function: " FOREVER      
      transmit "PROFILE^M"
      waitfor "Action:  "
      transmit "PURGE^M"
      waitfor "Subscriber Name or Extension:  "
      transmit sTok1                           ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
      transmit "^M"
      if waitfor "Function:  " 10
         transmit "PROFILE^M"
         waitfor "Action:  "
         transmit "MODIFY^M"
         waitfor "Subscriber Name or Extension:  "
         transmit sTok1                           ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
         transmit "^M"
         if waitfor "PhoneMail Password  : (Previous = ##########):  " 10
            transmit szNewPswd
            fseek 1 (-4) 1
            finsblock 1 9
            fwrite 1 sDone 9
         else
            transmit ";^M"
            finsblock 1 11
            fwrite 1 sProblem 11
            fseek 1 2 1
         endif
      else
         transmit ";^M"
         waitfor "Function:  "
         transmit "PROFILE^M"
         waitfor "Action:  "
         transmit "MODIFY^M"
         waitfor "Subscriber Name or Extension:  "
         transmit sTok1                           ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
         transmit "^M"
         if waitfor "PhoneMail Password  : (Previous = ##########):  " 10
            transmit szNewPswd
            fseek 1 (-2) 1
            finsblock 1 9
            fwrite 1 sDone 9
         else
            transmit ";^M"
            finsblock 1 11
            fwrite 1 sProblem 11
            fseek 1 2 1
         endif
      endif
   endwhile
endif
   fclose 1
transmit ";^M"
   waitfor "Function: " forever
   transmit "LOG^M"
   waitfor "Action: " forever
   transmit "LOG^M"
   capture OFF
   hangup
endproc

Your help (Again), will be really appreciated (again).

 
Is there more than one extension on each line you read, or is there one extension per line?

You have one place where the fseek command is backing up four bytes instead of two bytes. Is that correct? The other location you use fseek is rewinding two bytes, as does my example script.
aspect@aspectscripting.com
 
KNOB,

AGAIN let me say thank you for your Help!!

That is correct. I guess I was tired when I was playing around with the script you sent me. There should only be 1 extension Per Line. Well, I made some changes and almost everything is working (with 5 Test Extensions only.

The Problem I have is that when the Script reaches the Last Extension in the File, it does not complete all actions. This is due to my using the WHEN TARGET Commands. I was wondering if there was a way to the let the script run for 2 minutes like a PAUSE or Waitfor Statement. However, I think that the PAUSE statement would not allow the WHEN TARGET commands to execute. I guess a WAITFOR statement would be best (i.e., IF Waitfor “NOTHING” 90 than a ENDIF).

Any suggestions?
 
KNOB,

Sorry, Here is my Current Script File:

Code:
proc main
string szNewPswd,szSiteName,sTok1,sLine
string fName = "C:\Temp Completed Reports\Completed "
string sEnter = "^M"
string sPurgeDone = " PURGE DONE"
string sPurgeProblem = " NOT PURGED"
string sPswdDone = " HAS NEW PASSWORD"
string sPswdProblem = " PSWD NOT CHANGED"
string fEnd = ".txt"
integer iLen

; Assigns Site Name to the Variable szSiteName
sdlginput "Site Name" "Enter Site Name:" szSiteName                         
   pause 1

; Assigns Password to szNewPswd
sdlginput "New Password" "Enter the New DEFAULT Password:" szNewPswd        
   pause 1
strcat szNewPswd sEnter
strcat fName szSiteName
strcat fName fEnd
when Target 0 "Extension            [" call Press_Enter
when Target 1 "Name (last first)   :" call Press_Enter
when Target 2 "Class Number        :" call Press_Enter
when Target 3 "  Enter T or F for each field):  " call Announce
when Target 4 "Group Name          :" call Press_Enter
when Target 5 "Referral Extension  : " call Press_Enter
when Target 6 "Volume Level        : " call Press_Enter
when Target 7 "Speed level         : " call Press_Enter
when Target 8 "Abbreviated Prompts?: " call Press_Enter
when Target 9 "Cannot find this form." call Exit_MailBox
when Target 10 "Alt Greeting Active?: (Previous =" call Press_Enter
when Target 11 "Software Mailbox ?  : (Previous =" call Press_Enter
when Target 12 "Failed Acc Attempt  : (Previous =" call Press_Zero

if isfile "C:\Temp Data Files\Raw Data\TestFile.txt"                                               ; Verifies that File does Exist.

   ; Opens Text File 
   fopen 1 "C:\Temp Data Files\Raw Data\TestFile.txt" READWRITE TEXT            
           
   ; Creates a New Text File With the Name:  Completed + the SiteName User Provides
   fopen 2 fName CREATE TEXT
   pause 20
   transmit "^M"

   ; Logs you into the PhoneMail System and gets you to the Function Prompt.
   Execute "Log-SA.wax"                     
      while not feof 1
      fgets 1 sLine
      strlen sLine iLen
      if iLen == 0
         exitwhile
      endif

      ; Assigns Text in First Field (From Text File) to Variable sTok1.
      strtok sTok1 sLine " " 1                                
      waitfor "Function: " FOREVER      
      transmit "PROFILE^M"
      waitfor "Action:  "
      transmit "PURGE^M"
      waitfor "Subscriber Name or Extension:  "

      ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
      transmit sTok1                           
      transmit "^M"

      if waitfor "Function:  " 10
         fwrite 2 sTok1 6
         finsblock 2 11
         fwrite 2 sPurgeProblem 11
         transmit "PROFILE^M"
         waitfor "Action:  "
         transmit "MODIFY^M"
         waitfor "Subscriber Name or Extension:  "

         ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
         transmit sTok1                           
         transmit "^M"
         if waitfor "PhoneMail Password  : (Previous = ##########):  " 10
            transmit szNewPswd
            finsblock 2 17
            fputs 2 sPswdDone
         else
            transmit ";^M"
            finsblock 2 17
            fputs 2 sPswdProblem
         endif
      else
         transmit ";^M"
         fwrite 2 sTok1 6
         finsblock 2 11
         fwrite 2 sPurgeDone 11
         waitfor "Function:  "
         transmit "PROFILE^M"
         waitfor "Action:  "
         transmit "MODIFY^M"
         waitfor "Subscriber Name or Extension:  "
         
         ; Sends the Text Value (Assigned to Variable sTok1) to the PhoneMail System.
         transmit sTok1                           
         transmit "^M"
         if waitfor "PhoneMail Password  : (Previous = ##########):  " 10
            transmit szNewPswd
            finsblock 2 17
            fputs 2 sPswdDone
         else
            transmit ";^M"
            finsblock 2 17
            fputs 2 sPswdProblem
         endif
      endif
   endwhile
endif
   fclose 1
   fclose 2
transmit ";^M"
   waitfor "Function: " forever
   transmit "LOG^M"
   waitfor "Action: " forever
   transmit "LOG^M"
   capture OFF
   hangup
endproc
proc Announce
      pause 1
   transmit "F T F^M"
endproc
proc Exit_MailBox
   pause 1
   transmit ";^M"
endproc
proc New_MailBox
   integer sNext = 0
   sNext = 0
   longjmp 0 sNext
endproc
proc Press_Enter
      pause 1
   transmit "^M"
endproc
proc Press_Zero
   pause 1
   transmit "0;^M"
      pause 1
   transmit ";^M"
endproc
 
What happens when you reach the last extension? You could use the when clear comman to turn off a particular when command if it causes trouble during the last line (although I'm not sure how you would know it's the last line until the script encounters EOF). I'm not familiar with the system you're calling into, so I don't know if I can offer anything more concrete (if you want to post another screenshot, that would be helpful).
aspect@aspectscripting.com
 
When I do the fwrite
i.e
fwrite 0 strTest 29
fwrite 0 "test" 4
fwrite 0 "some" 4

it puts it all in one line. How can I prevent this. Thanks
 
Since fwrite writes raw data, you need to add the carriage returns and linefeeds yourself (or use the fputs command on a file that has been fopened with the TEXT keyword). Here's a sample script that should get you going:

proc main
string sCR, sLF

strfmt sCR "%c" 13 ;string to hold carriage return
strfmt sLF "%c" 10 ;string to hold linefeed

fopen 0 "c:\test.txt" READWRITE
fwrite 0 "foo" 3
fwrite 0 sCR 1
fwrite 0 "bar" 3
fwrite 0 sLF 1
fclose 0
endproc aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top