This is my code.
SEARCH-RECORD.
PERFORM SEARCH-OPENING-PROCEDURE.
PERFORM SEARCH-CUSTOMER-RECORD.
PERFORM SEARCH-RECORDS
UNTIL CUST-NO = "0".
PERFORM SEARCH-CLOSING-PROCEDURE.
SEARCH-OPENING-PROCEDURE.
OPEN INPUT CUSTOMER-FILE.
SEARCH-CLOSING-PROCEDURE.
CLOSE CUSTOMER-FILE.
SEARCH-RECORDS.
PERFORM DISPLAY-ALL-FIELDS.
PERFORM SEARCH-CUSTOMER-RECORD.
ENTER-CUSTOMER-NO.
PERFORM ACCEPT-CUSTOMER-NO.
PERFORM RE-ACCEPT-CUSTOMER-NO
UNTIL CUST-NO NOT = SPACE.
ACCEPT-CUSTOMER-NO.
DISPLAY "ENTER CUSTOMER NO. (EX. C01)".
DISPLAY "ENTER 0 TO STOP".
ACCEPT CUST-NO.
INSPECT CUST-NO
CONVERTING LOWER-ALPHA
TO UPPER-ALPHA.
RE-ACCEPT-CUSTOMER-NO.
DISPLAY "CUSTOMER NO. MUST BE ENTERED!".
PERFORM ACCEPT-CUSTOMER-NO.
SEARCH-CUSTOMER-RECORD.
PERFORM ENTER-CUSTOMER-NO.
MOVE "N" TO RECORD-FOUND.
PERFORM FIND-CUSTOMER-NO
UNTIL RECORD-FOUND = "Y" OR CUST-NO = "0".
FIND-CUSTOMER-NO.
PERFORM READ-CUSTOMER-RECORD.
IF RECORD-FOUND = "N"
DISPLAY "CUSTOMER RECORD NOT FOUND"
PERFORM ENTER-CUSTOMER-NO.
READ-CUSTOMER-RECORD.
MOVE "Y" TO RECORD-FOUND.
READ CUSTOMER-FILE RECORD.
DISPLAY-ALL-FIELDS.
DISPLAY " ".
PERFORM DISPLAY-CUSTOMER-RECORD.
DISPLAY " ".
DISPLAY-CUSTOMER-RECORD.
DISPLAY " CUSTOMER NO.: " CUSTOMER-NO.
DISPLAY "1. CUSTOMER ID: " CUSTOMER-ID.
DISPLAY "2. CUSTOMER NAME: " CUSTOMER-NAME.
DISPLAY "3. CUSTOMER PRODUCT: " CUSTOMER-PRODUCT.
DISPLAY "4. CUSTOMER QUANTITY: " CUSTOMER-QUANTITY.
DISPLAY "5. CUSTOMER DATE: " CUSTOMER-DATE.
Just assume that I have complete records of C01,C02,C03,C04,C05.
My problem is that my CUSTOMER-FILE is in line sequential. So, whenever I try to search for a specific record like C04's record, it always show C01's record first, then C02's, C03's regardless of what I put in my search function. Is there any way that can do custom search? I don't know all the commands, thank you.
Here's why your logic always stops after looking at the first record: in READ-CUSTOMER-RECORD, you set your record-found flag without checking to see if you have a match (between the record you just read and the customer number you want). You need to keep reading until you reach the end of file (EOF) or you find the desired customer record. You need to detect the difference between "I didn't find it on this READ" and "I didn't find it at all."
So you want to change your logic to something like this. There are cleaner ways to code this, but it's the smallest change to what you have already:
SEARCH-CUSTOMER-RECORD.
PERFORM ENTER-CUSTOMER-NO.
MOVE "N" TO RECORD-FOUND.
MOVE "N" TO EOF-FLAG.
PERFORM FIND-CUSTOMER-NO
UNTIL RECORD-FOUND = "Y" OR CUST-NO = "0".
FIND-CUSTOMER-NO.
PERFORM READ-CUSTOMER-RECORD
UNTIL EOF-FLAG = "Y" OR RECORD-FOUND = "Y".
IF RECORD-FOUND = "N"
DISPLAY "CUSTOMER RECORD NOT FOUND"
PERFORM ENTER-CUSTOMER-NO.
READ-CUSTOMER-RECORD.
READ CUSTOMER-FILE RECORD
AT END
MOVE "Y" TO EOF-FLAG.
IF EOF-FLAG = "N"
IF CUSTOMER-NO = CUST-NO
MOVE "Y" TO RECORD-FOUND.
If you reach the end of the file, CUSTOMER-NUMBER doesn't have a well-defined value. That's why we have to guard the test with IF EOF-FLAG = "N". Again, there are other ways to do this, but I'm trying to keep it simple.
A general note on your coding style: there are places where you have redundant code that can be simplified and improved. Rather than performing SEARCH-CUSTOMER-RECORD and then displaying the results in SEARCH-RECORDS, you can recode it so that SEARCH-RECORDS does the search and then the display.
Update
One more very important point: when you start a new search, you need to close and re-open CUSTOMER-FILE. (This has the effect of moving the file pointer back to the beginning of the file.) If you don't do this, your second search will start reading the file from the point you left off, or from the end of file.
There are other file organizations that you will learn about that make this step unnecessary: they allow you to use the START statement.
Related
I am using Shiny to build a dynamic dashboard for the user. I used if statement to divide my code into two main parts. There is an input called "New Line" that user needs to enter "Yes" or "No" as the value for this parameter. If user selects "Yes" the first part of the code will be ran and if he selects "No", it means that the first part is ran before and just the second part of the code needs to be ran. In the second part, there are some parameters from the first part. I want for Shiny to save the results and parameters calculate from ("New Line"==Yes) and use it for the next runs("New Line"==No) until the user change the answer for "New Line" to "Yes" again.
I used observeEvent function and an action button in Shiny. But the problem is that the results of ("New Line"==Yes) can not be used for the next runs.
shinyserver(function(input,output)){
observeEvent(input$click,{
if(input$'New Line' == 'Yes'){}
if(input$'New Line' == 'No'){}
})
}
I expect whenever user enters No for the New Line and hits the action button, the code can use the variables that are calculated when the New Line was Yes. But now whenever I set New Line as No and hit the action button , R just runs the second if. I can copy and paste all the lines from first if to tell R to run all of them again but those line takes about 30 minutes and I do not want to repeat them.
You need to serialise your values somewhere.
One example:
shinyserver(function(input,output)){
observeEvent(input$click,{
if(input$'New Line' == 'Yes'){
data <- result_of_some_function()
some_other_things()
write.csv(data, "file.csv") # saving the data somewhere on disk
}
if(input$'New Line' == 'No'){
mypreviousdata = read.csv("file.csv")
something <- somefunction(mypreviousdata)
}
})
}
Other than saving to CSV, you might prefer a database or the user's cookies, or whatever.
I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}
I have a nested if statement is returning "False" rather than the expected outcome.
Scenario
Table "High VoltageCables" has data in it that default to numeric but may contain characters: kVa
Table "Master" checks "High VoltageCables" data as blank or not blank, and returns "Failed Check 1","Passed Check 1". This works fine.
Table "Meta" then checks the results of "Master" and then tests "High VoltageCables" data for length between 1 and 6, regardless of whether record is numeric or string.
Formula
=IF(MASTER!H2="Passed Check 1",IF(LEN('High VoltageCables'!O2)>=1,IF(LEN('High VoltageCables'!O2<6),"Passed Check 2","Failed Check 2")))
This is partially succesful, as it returns "Passed Check 2" for the following sample data in the source table "High VoltageCables".
1 numeric, or
1kVa str, or
50000 numeric
However if a field in "High VoltageCables"is blank, the formula returns "FALSE" rather than "Failed Check 1"
I inherited this task, (and would have preferred to do the whole thing in Access using relatively simple queries) - and unfortunately I am new to nested If statements, so I am probably missing something basic...
NB the data in High VoltageCables must default to numeric for a further check to work.
The first and second IF's seem to be missing the else part. They should be added at the end between the ))) like ), else ), else )
Every IF statement consists of IF( condition, truepart, falsepart) if you have two nested ifs it will be something like IF( condition, IF( condition2, truepart2, falsepart2), falsepart)
Hope that makes it a little clearer
You do have an unaccounted for FALSE in the middle IF. Try bring the latter two conditions together.
=IF(Master!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"))
It's still a bit unclear on what to show or not show if Master!H2 does not equal "Passed Check 1".
I failed to construct the formula with a concluding "else" - "Failed Check 1"
Using jeeped's and Tom's suggestion and adding the final "else" part I have solved the problem:
=IF(MASTER!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"),"Failed Check 1")
I am trying to send out a mass mail merge email to clients who are in an accreditation process. I am using an Excel spreadsheet in the merger, and in the datasheet if the client has taken a class I indicate it with the number of credit hours (so they can also be added up as part of the letter). However since I want the class name rather than the number of credits it is worth I used the "if...then...else.." field. So that if the credit number is greater than 0 than the Class Name is inserted or else it is blank. My Merge field therefore looks like this:
{ IF { MERGEFIELD M_2713_CLASS } = 6 "Class Name" ""}
Where the "6" is the number of credits. There are about 40 classes entered as a list (one below the other). The problem I am running into is getting the classes that the client has not taken and are therefore blank to not show up as a blank line. I am not a programmer by any meaning of the word but I know there is a way to do it, I just can't seem to figure out even with the help of Google. Any suggestions?
The traditional approach is along the following lines:
{ IF { MERGEFIELD M_2713_CLASS } = 6 "Class Name A
" }{ IF { MERGEFIELD M_2713_CLASS } = 7 "Class Name B
" }{ IF { MERGEFIELD M_2713_CLASS } = 8 "Class Name C
" }etc.
I.e. You press Enter to insert a paragraph mark inside the IF field, at the end of the text you want to insert., instead of outside the IF field.
The problem is this:
In my programme at first the user gets options for a first name - so hopefully he likes something from the options and he chooses it -so far everything is OK!
But then when he types space he starts receiving options for second name and a if he likes something and chooses it - then the Autocomplete just erases the first name. Is there any way I can change that?
hello Rich thank you very much or your response - now i've decided to change my task and here is what I made when a user types for example I character i get all the first names that start with I- so far no problem! ANd when he types the white space and K for example I make request to my web service that gets the middle names that starts with K or the last names that start with K (one of them should start with K for Iwelina), so in this case for Iwelina Ive got RADULSKA KOSEWA and KOSEWA NEDEWA! For the source of autocomplete I concatenate iwelina with (radulska kosewa)and iwelina with (KOSEWA NEDEWA) so at the end I've got IWELINA IELINA RADULSKA KOSEWA and IWELINA KOSEWA NEDEWA!!! the only problem is that when i type Iwelina K i get only IWELINA KOSEWA NEDEWA!!!here is the code for autocomlete
$('#input').autocomplete({
source: function(request, response) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term, " "));
var data = $.grep( srcAutoComp, function(value) {
return matcher.test( value.label || value.value || value );
});
response(data);
}
});
if you know how i can change it I will be glad for the help
I don't understand how, when the user begines to type the second name, he's getting results that are only the last name. For example, if he types "Joh" and selects "John" from the options, and then continues to type "John Do", then how is it possible that your drop down gives him results for only the last name, like "Doe"?
At any rate, assuming this is truly happening, you could just combine all combinations of first and last names in your source data and that will show "John Doe" in the drop down when the user types "Joh" selects "John" and then continues to type "John Do".
Another way to do this is with a complicated change to the search and response events to search after a space if it is there, and recombine it with the first string after the search for the last name is complete. If you give me your source data, I could put something together for this.