how to compare listbox items with memo field in a table in foxpro for exact match? - visual-foxpro

I am having an Inv table having tags as the field containing memo type, Now how to compare list box items with Inv.tags(memo) weather any of the records in inv.tags are matching with listbox items , this is the code i have written,
Create Cursor mycursor(RecordS c(50))
IFExists=.F.
For nCount = 0 To Thisform.list3.ListCount
Append Blank
Replace RecordS With Alltrim(Thisform.list3.List(nCount))
IFExists=.T.
Endfor
Delete From mycursor Where RecordS==""
lcMessage = ""
select mycursor
scan
lcMessage = lcMessage + transform(records) + chr(13)
ENDSCAN
lbMessage = ""
select inv
scan
lbMessage = lbMessage + transform(tags) + chr(13)
ENDSCAN
IF ALLTRIM(lcMessage) == ALLTRIM(lbMessage)
MESSAGEBOX('Success',64,'Status')
ELSE
MESSAGEBOX('Mis Match',16,'Status')
ENDIF
i am getting the result as mismatch even if the records are matching. Thank You!

It seems like it is mismatching, because you start the index of your listbox at 0. In VFP, indexes start at 1 and the listbox control will return an empty string, when referencing "Thisform.list3.List(0)".
Anyways, I could not reproduce the problem either, so this is just a suggestion.

Related

How to loop through a webtable using HP UFT and print the text for each row in column 1 and 2

Hello can someone help me loop through a web table using HP UFT to read a WebTable and loop through each row, print the text for each row in column 1 and 2 and finally compare the text to whats on the webpage
Set myTable = Browser("page").Page("activity Center").WebTable("readonlygrid-xxxx")
TotalRows = myTable.RowCount
msgbox TotalRows
Total = 0
For i = 2 to TotalRows
For x = 2 to TotalRows
strinbx = myTable.GetCellData(i,1)
strinbx2 = myTable.GetCellData(x,2)
print strinbx & strinbx2
Next
Next
I don't understand why you have two loops for the rows. If you only want the first two columns of each row you need something like this:
For row = 1 to myTable.RowCount
column1 = myTable.GetCellData(row, 1)
column2 = myTable.GetCellData(row, 1)
Print column1 & " - " & column2
Next
I also don't understand what you mean by "compare the text to whats on the webpage", the values you get are what's on the webpage.

Specifying starting value in sorting/Sort starting from middle - Progress openedge

Scenario: I have a char field(name:priority) in my table where values are stored as 1,2,3 and blank("").
for each mytable no-lock by priority:
This query sorts in this order: blank,1,2,3.
for each mytable no-lock by priority desc:
And,this query sorts records like this: 3,2,1 and blank.
But i need to sort the records like this: 1,2,3 and then blank. In ascending order but skipping the blank and starting from 1.
Is there any way to sort this out in Progress?
Since you are using a character field, it's treating the numbers as strings. The ASCII values for the strings "1", "2" and "3" are 49, 50 and 51. Progress treats a blank ("") as ASCII -1. That's why the blank comes first.
Your best bet would be to use two FOR EACH statements. First do the non-blank records:
FOR EACH mytable NO-LOCK WHERE mytable.priority <> "" BY priority:
Then do the blank records:
FOR EACH mytable NO-LOCK WHERE mytable.priority = "":
If you have your business logic in procedures/functions, you can run those from within the FOR EACH loops to prevent any code duplication.
If (only if) theres not that many records in the table perhaps you can copy the records to a temp-table with a new priority and sort the temp-table instead?
If you have million of records this might not be it! Then I would consider simply adding a new field.
DEFINE TEMP-TABLE MyTable NO-UNDO
FIELD priority AS CHARACTER
FIELD txt AS CHARACTER.
CREATE MyTable.
ASSIGN MyTable.priority = "1"
MyTable.txt = "First?".
CREATE MyTable.
ASSIGN MyTable.priority = ""
MyTable.txt = "Last?".
DEFINE TEMP-TABLE ttMyTable NO-UNDO LIKE MyTable
FIELD newPriority AS INTEGER
INDEX sortOrder newPriority.
FOR EACH MyTable NO-LOCK:
CREATE ttMyTable.
BUFFER-COPY MyTable TO ttMyTable
ASSIGN
ttMyTable.newPriority = IF MyTable.priority = "" THEN 99999 ELSE INTEGER(MyTable.priority).
END.
FOR EACH ttMyTable NO-LOCK BY ttMyTable.newPriority:
DISPLAY ttMyTable.
END.
Since you are scanning /all/ records anyway, you could sort in the BY:
define temp-table tt no-undo
field priority as character
.
create tt. tt.priority = "".
create tt. tt.priority = "1".
create tt. tt.priority = "2".
create tt. tt.priority = "3".
create tt. tt.priority = "".
for each tt by ( if tt.priority = "" then "4" else tt.priority ):
display string( rowid( tt ) ) tt.priority.
end.

Select list oracle apex second value

When I create a Select list based on a SQL query it asks for 2 columns. For example I did something like: select itemcode, itemname from items in a select list called LST_ITEMS. I need to retrieve or get both of the values when I call it with :LST_ITEMS.
You can write query as:
select itemname display_value,
itemcode || ':' || itemname return_value
from items
After that you will get combined value in :LST_ITEMS variable. You can parse it in PL/SQL code further. For example:
declare
code number;
name varchar2(100);
begin
code = substr(:LST_ITEMS, 1, instr(:LST_ITEMS, ':') - 1);
name = substr(:LST_ITEMS, instr(:LST_ITEMS, ':') + 1);
end;
You Can Get That Using Javascript Dynamic Action Like so
$s('P1_Display_Val',apex.item("LST_ITEMS").displayValueFor("1"));
This copy the display value of item "LST_ITEMS" (with return value = 1) to item "P1_Display_Val". either 1 was the selected value or not.

Automate bulk of update queries in pl\sql

For frequent period of time, i'm doing same process of updating few tables with consecutive values. Hope to make this simple an example below,
UPDATE Table_1 SET vchar_val = REPLACE (vchar_val, '.360/', '.370/'),
WHERE vchar_val LIKE 'http://services%.360/%'
AND c_version IN ('ALL', 'N/A', '37.0');
For 37th version, i'm replacing the places where '36' with '37'. The same i'll do for '38' and it continues...This is making me bore and time consuming process as i've 50 plus records like this for different tables for which i'm manually editing all update queries.
So i planned to write a scheduler which i can trigger for each version by giving input as previous version and current version, in which i'll put all this update queries.
Here comes the place where i struck, if i go by giving version values as input, i'm supposed to introduce local parameter to store. HOW CAN I ASSIGN THAT LOCAL VARIABLE TO MY UPDATE SCRIPT.??????
I go with concatenate the texts like
REPLACE (vchar_val, '.'+ #PrevVersion +'/', '.'+ #CurrentVersion +'/')
PrevVer** & CurrentVer** is my local variable with values .360 & .370 resp.
I think i miss quiet piece of code in this snippet as i'm getting error when running this.
Please help me guys to rearrange this code to automate the query or ur comments to do this job in any alternative way...
Thanks
-VIno
begin
for i in 36 .. 50 loop
UPDATE Table_1
SET vchar_val = REPLACE (vchar_val, '.'|| i ||'0/', '.'|| i+1 ||'0/')
WHERE vchar_val LIKE 'http://services%.'|| i ||'0/%'
AND c_version IN ('ALL', 'N/A', i+1 ||'.0');
end loop;
end;
Of course you could do that in one single update with some fancy reg_exp, but I leave that exercice to another fellow stackoverflower :)
Local variable:
declare
my_local_valiable number;
begin
update my_table ... ;
commit;
end;
Autoincrement: sequence
update table_1 set my_field = '.' || my_sequence.nextval where ...;
UPD
Number always in the same position (for example, 2 digits, 10th and 11th symbols in the string):
update table_1 set my_field = substr(my_field, 1, 9) || to_char(to_number(substr(my_field, 10, 2)) + 1) || substr(my_field, 12);
This converts string 'abracadab29ra' to 'abracadab30ra'.
The same with replace:
update table_1 set my_field = replace(my_field, substr(my_field, 10, 2), to_char(to_number(substr(my_field, 10, 2)) + 1));
Number always follows after a string 'value = ' and has two digits:
update table_1 set my_field = replace(my_field, substr(my_field, instr(my_field, 'value = ', 1) + 8, 2), to_char(to_number(substr(my_field, instr(my_field, 'value = ', 1) + 8, 2)) + 1))
This converts string 'my value = 33' to 'my value = 34'.

Changing a 0 or 1 value to "Yes" and "No" in APEX report

I have a report region on my page and it's getting data from a students table. Within that table, there's a column called cv_lodged which is either 1 or 0 representing Yes or No. In the report it shows this columns data as 0 or 1, I want to change it to show Yes or No.
How can I do this?
You can put a CASE statement in your query
SELECT (CASE WHEN cv_lodged = 1
THEN 'Yes'
ELSE 'No'
END) cv_lodged,
other_columns
FROM students
If this is something that is likely to be common, you're probably better served creating a function that converts your pseudo-boolean data to a string. Something like
CREATE FUNCTION my_bool_to_str( p_num IN NUMBER )
RETURN VARCHAR2
IS
BEGIN
IF( p_num = 1 )
THEN
RETURN 'Yes';
ELSE
RETURN 'No';
END IF;
END;
that you would call in your query
SELECT my_bool_to_str( cv_lodged ) cv_lodged,
other_columns
FROM students
I've usually just created a static LOV in Shared Components called YES1_NO0, with 2 entries: 'Yes' -> 1, 'No' -> 0.
In Interactive Reports you can then change these columns. To do this, edit the column of the IR. Change 'Display Type' to 'Display as Text (based on LOV, escape special characters)'. Then under 'List of Values' set 'Column Filter Type' to 'Use Named List of Values to Filter Exact Match' and select the named LOV.
But sure, you can totally do this in SQL.
Currently, there is a simpler way to do this.
First open the APEX page with the "Yes/No" item as developer and click on the item to open the page item settings.
Change the Settings value from Use component settings to Custom.
Afterwards change the Yes Value to 1 and the No Value to 0.
This solution has some advantages:
No need to decode the value 1 or 0 to Y or N (select decode(mycolumn, 1, 'Y', 'N') from mytable where id = 123;) or select case when ...
No need to decode the submitted value back to 1 or 0 from Y or N

Resources