Smalltalk: Setting value of a variable to object - smalltalk

I have a (probably) very simple question regarding SmallTalk that I am not able to solve for few hours.
So, I am trying to create a simple app for managing students and exams - therefore I have classes Student (attributes: name, surname) and Exam (attributes: date, student, mark). Moreover, I have 2 datasets in GUI to show students (DatasetStudents) and exams (DatasetExams).
What I'm trying to do with following method is create a new exam when there is a student selected in the dataset. Then I try to set the selected student object as a value of exam's attribute student. However, the problem occurs on the ex student: selected. line. When I try ex student: selected name. to set value to selected student's name, which is string, it works like charm.
Is there any way how to assign whole object to variable?
newExam
| selected ex |
selected := DatasetStudents selection.
selected isNil
ifTrue: [^Dialog warn: ‘Select student before adding exam!’]
ifFalse : [ nil ].
ex := Exam new.
ex student: selected.
DatasetExams list add: ex.
What I'm trying to achieve overall is to automatically show relevant exams in second dataset for a student selected in first dataset, but I'm currently stuck at assigning students to exams...
Thank you in advance!

Related

Next Record within a group

I have these records grouped by Animal ID since many of the same animals come and go from the facility, so an animal will have multiple records. I want to create a function that gets the length an animal stayed here. However, I want to ignore the animals that have an outcome_type = 'RTO' followed by an intake_type = 'OWNER SUR' within the same. Does anyone know how I can ignore these values. I attached an image for reference. enter image description here

Inputting Data into Database and reading it

I have an SQL database and 2 VB applications, teacher and student application.
In the teacher application, the SQL database is connected with datagridview. In the form there are 10-15 checkboxes. those checkboxes are a set of weak points the teacher can select for a student in their class. for eg- "weak in calculations" etc. I want, when the teacher select the checkboxes, they should be shown in the teacher application in a string form. I think assigning each check box an ID would be a lot better than inputting long strings into the database. when the teacher selects a checkbox, the ID for that checkbox goes into the datagridview selected cell. I am not sure how to seperate each ID in the same cell because the teacher can select multiple checkboxes.
I need help with seperating the IDs and then reading them.
http://www.filedropper.com/sample_18 here is a sample program i made, it shows entering the checkbox id into the datagridview.
Let's keep it simple. Let's say we have 3 check boxes.
So for saving to db:
dim totalValue as integer = 0
if (chkBox1.checked) then totalValue +=1
if (chkBox1.checked) then totalValue +=2
if (chkBox1.checked) then totalValue +=4
save to db the totalValue
For reading from db:
totalValue = get this value from db
chkBox1.checked = ((totalValue and 1)=1)
chkBox1.checked = ((totalValue and 2)=2)
chkBox1.checked = ((totalValue and 4)=4)

QlikView: Counting With Set Analysis

I have following expression which counts saved persons:
=Count({1<Saved={'Yes'}>} Surname & Forenames)
I also have follwing expression which counts died persons:
=Count({1<Saved={'No'}>} Surname & Forenames)
However, for some persons there is no data, but I want to count that persons as well:
=Count({1<Saved -= {'No', 'Yes'}>} Surname)
However, this last expression gives me 0 as a result, although there are null values in the Saved field. How can I count every surname which has any value in the Saved field other than YES and NO (count should include everything except YES and NO, even Null values)?
In a table object you can uncheck "supress when value is null" and it should show when using count(Surname).
If you want it to show in a text object you can probably use something like:
=Count({1} if(IsNull(Saved), Surname))

Compare array to database and change matching elements

I am working on a hospital database and I am loading hospital beds to combobox. What I want to do is, if bed is already taken, I want to add (Occupied) after id of bed.
There is a room and bed list table. Room 101 has Three beds. 1001, 1002 and 1003. I have loaded Bed_No to an array. bed_ids_array()
There is a Patient-Bed Occupied table. As you can see 1002 and 1003 are occupied by patients. I read this data through while loop dr(1)
I am adding data to combobox in vb.net and it should look like this:
But it looks like this:
(when rechecking with different values same data comes when data is being read from access database)
The code I have used is this:
'Check if beds in array have patients
Call connect()
con.Open()
cmd = New OleDbCommand("Select * from Bed_to_Patient_Relation", con)
dr = cmd.ExecuteReader
While dr.Read
'Add all occupied stuff to combobox first
For i = 0 To room_bed_count - 1
'take first bed id and check all database
If bed_ids_array(i) = dr(1) Then
Cmbbx_Beds.Items.Add(bed_ids_array(i) & "Occupied")
Else
Cmbbx_Beds.Items.Add(bed_ids_array(i))
End If
Next
End While
What I want to do is to add "Occupied" to text if match is found, else, just enter normally
I suggest making a few changes. Ditch the combobox for a datagridview. You can still select the row you want, but have better visibility of the data. Join your two tables in the query to identify which beds are available or occupied. Include the bed and room id in the patient to bed relationship table, or better yet, assign a unique id for each bed. An occupied table may allow for a more effective join.
The issue I think you have with existing code is that you're adding the list twice, or not clearing it after each reload of the box. I find it much more efficient to populate a grid based on data from a query, such as the join mentioned above.
probably not the answer you were looking for.

Oracle APEX_ITEM API usage and issues

I have the following select statement that I am using as a standard report:
select id,
name,
telephone,
apex_item.checkbox2(10,id) as "Tick when Contacted",
apex_item.text(20,:P2_DATE) as "Date Contacted",
apex_item.textarea(30,:P2_COMMENT,5,80) as "Comment"
from my_table
My question is and the area that I am not sure if I am doing this correctly is that if this statement returns 10 rows and out of those 10 rows, I only select/check 5 records and then press the submit button, why is it that my PL/SQL page process that inserts the selected records into another table is not picking up :P2_DATE and :P2_COMMENT which are hidden items on the page and purely just used as placeholders and not actual columns within my_table?
Am I doing this correctly or do I need to use an apex collection?
Here is what my page process looks like; is this correct?
DECLARE
v_row BINARY_INTEGER;
BEGIN
FOR i IN 1..APEX_APPLICATION.G_F10.COUNT LOOP
v_row := APEX_APPLICATION.G_F10(i);
INSERT INTO MY_OTHER_TABLE
( DATE_CONTACTED,
COMMENTS
)
VALUES ( APEX_APPLICATION.G_F20(v_row),
APEX_APPLICATION.G_F30(v_row)
);
END LOOP;
COMMIT;
END;
Example of report with user input is as follows:
ID/CHECKBOX DATE CONTACTED COMMENTS
=====================================================
1 21/08/2012 Comment 1
2 21/08/2012 Comment 2
3 21/08/2012 Comment 3
4 21/08/2012 Comment 4
5 21/08/2012 Comment 5
Based on this report where user has manually entered these 5 comments, I expect these 5 records get inserted into MY_OTHER_TABLE, as they have been checked.
Unfortunately MY_OTHER_TABLE never gets populated for the 5 records that I have checked.
I am unsure what I have missed out on something, or if I have completely got my original select wrong with regards to using these two placeholder items?
In your comment you say
can I user apex_item.text api where the source is not coming from an underlying oracle table?
Now i read that as:
can i generate this report and have the default value for my apex_item fields set to that of my 2 page items.
Yes. You can. That is what i thought you meant originallyn and it makes sense since the items are hidden anyway. Just make sure of the below:
if you meant that the value is not put in the report items at page load:
if the region with the hidden items is BELOW the region with your report, move your region with the items or create a new region ABOVE the region with your report.
With above and below i'm talking about their position in the form structure. Switch over to tree view if you use component view to easily see this.
My guess is that the item (and its source) is processed before, and thus has a valid session state before the rendering of the report starts.