PDA

View Full Version : Object name with onpush indicator


ABC123

gschepp
12-19-2014, 09:23 PM
I have a form with multiple fields (50) one for each year and corresponding buttons that are labeled with years. The fields will have 3 options: "S", "C", or blank. I would like to create a script that retrieves the object name of the button pushed. I should be able to write the xbasic that would determine which operation to complete.

I would like to identify (Object Name) Btn_S2000 as triggered with onpush. Find the routine that matches Btn_S2000. Within that routine determine which specs are met and then put the data in Senate->2000.


table name -- legis_senate
alias -- Senate

Button -- Btn_S2000
Field -- Senate->S2000

Al Buchholz
12-19-2014, 09:45 PM
Gary

This looks like a question.

This forum is for code contribution.

Let me know what version you are using and I'll move this post.

gschepp
12-19-2014, 10:22 PM
Sorry.

I'm using Alpha Anywhere.

Ray in Capetown
12-20-2014, 03:25 AM
put the code that determines the operation to complete into a udf

Have each button call the same function with

yourudf(parentform.Active())
The paramenter received by the function will be a string with the button name.

Stan Mathews
12-20-2014, 11:03 PM
You can get the button object name with

this.name

If the field corresponding to Btn_S2000 has the object name S2000 you know that the object name of the field is

right(this.name(),5)

and the value in the field is eval(right(this.name(),5)+".value")

if the field contains text you would use

eval(right(this.name(),5)+".text")

gschepp
12-21-2014, 05:22 PM
Is there any Xbasic documentation that is helpful? I've searched Alpha 5 but it appears to be very minimal. It may be that I need to obtain Xbasic background from another source.

Stan Mathews
12-21-2014, 06:44 PM
I don't think you're going to find a sample code snippet in any documentation that will do what you want. It's more a question of putting the pieces together.

For any button the object name is this.name()

Since you have fields named similarly to the buttons you have to parse the button name to get the associated field name.
You use that field name and its properties to obtain the field value.
You obtain "routine that matches" by combining the field name and the field value, I'm guessing.

Ronald Anusiewicz
12-21-2014, 09:20 PM
I'm not sure but maybe this could help you.

gschepp
12-21-2014, 11:38 PM
Right now that won't help with determining the right routines to provide the right data. But part of it should help when I turn it into a function. The this.name() and parentform.Active() appear to prove useful. I am stuck with it not providing the right data each time.


39426


Buttons have a year for each election. Push to automatically put right status in box to right of year. Since this is for Senate elections they mostly run for election once every six years. The years they run it should have "S". The 2 election years after should have a "C". It should blank it out if there is a "S" or "C".

If election year box is blank and previous election is blank -- put S in.
If election year box is blank and previous election has "C" and election before that has "C" -- put S in.
If election year box is blank and previous election has "C" and election before that has "S" -- put C in.
If election year box has "C" or "S" -- blank it out.

The following is where I am with this.


Dim Senate_Status as C
Dim Senate_E1 as C
Dim Senate_E2 as C
Dim Senate_E3 as C
Dim Tbl_Senate as C

Tbl_Senate ="Senate->S"

select
'Senate 1964
case parentform.Active() ="Btn_S1964"
Senate_Year = val(right(this.Name(),4))
DELETE Senate_Status
Senate_E1 =Tbl_Senate +str(Senate_Year,4)
Senate_E2 =Tbl_Senate +str(Senate_Year-2,4)
Senate_E3 =Tbl_Senate +str(Senate_Year-4,4)
select
case isblank(Senate_E1)
select
case isblank(Senate_E2)
Senate_Status = "S"
case isnotblank(Senate_E2)
select
case Senate_E2 + "='S'"
Senate_Status = "C"
case Senate_E2 + "='C' .and. " +Senate_E3 + "='C'"
Senate_Status = "S"
case else
Senate_Status =""
end select
case else
Senate_Status =""
end select
case isnotblank(Senate_E1)
Senate_Status =""
case else
Senate_Status =""
end select
parentform:Senate_1964.value=Senate_Status

Stan Mathews
12-22-2014, 08:38 AM
Is this

Senate_E1 = Tbl_Senate +str(Senate_Year,4)

supposed to be getting a field value into the Senate_E1 variable?

Al Buchholz
12-22-2014, 09:27 AM
Is this

Senate_E1 = Tbl_Senate +str(Senate_Year,4)

supposed to be getting a field value into the Senate_E1 variable?

Looks like Gary is building the fieldname.

Time to use debug (1) and or the trace window.

gschepp
12-22-2014, 10:16 AM
Yes, Senate_E1 is the field that corresponds to the button push that will hold either "S", "C", or will be blank.
Senate_E2 will be the field to the last election and Senate_E3 is for 2 elections previous.

I"m getting a snag with it reporting Variable "Senate_Status" not found when there is an "S" in the last election (Senate_E2).

Stan Mathews
12-22-2014, 12:03 PM
This would all be easier to diagnose with a sample database. I've never used the construction you're using.

I think your isnotblank() test needs modification



Dim Senate_Status as C
Dim Senate_E1 as C
Dim Senate_E2 as C
Dim Senate_E3 as C
Dim Tbl_Senate as C

Tbl_Senate ="Senate->S"

select
'Senate 1964
case parentform.Active() ="Btn_S1964"
Senate_Year = val(right(this.Name(),4))
DELETE Senate_Status
Senate_E1 =Tbl_Senate +str(Senate_Year,4)
Senate_E2 =Tbl_Senate +str(Senate_Year-2,4)
Senate_E3 =Tbl_Senate +str(Senate_Year-4,4)
select
case isblank(Senate_E1)
select
case isblank(Senate_E2)
Senate_Status = "S"
case isnotblank(Senate_E2)
select
case Senate_E2 = "S"
Senate_Status = "C"
case Senate_E2 ="C" .and. Senate_E3 ="C"
Senate_Status = "S"
case else
Senate_Status =""
end select
case else
Senate_Status =""
end select
case isnotblank(Senate_E1)
Senate_Status =""
case else
Senate_Status =""
end select
parentform:Senate_1964.value=Senate_Status

or


case isnotblank(Senate_E2)
select
case eval(Senate_E2) = "S"
Senate_Status = "C"
case eval(Senate_E2) ="C" .and. eval(Senate_E3) ="C"
Senate_Status = "S"
case else
Senate_Status =""
end select

gschepp
12-22-2014, 07:16 PM
Here is the file. I was still testing different options. Trying to figure out how to determine the name for the field name, etc.

39431

The form that is in need is Terms_Senate.

gschepp
12-22-2014, 07:32 PM
Here is the file. I was still testing different options. Trying to figure out how to determine the name for the field name, etc.

39431

Stan Mathews
12-22-2014, 09:21 PM
Seems to me to work for 1970. Not all of the years are handled in the script.

What do you see not working?

gschepp
12-22-2014, 10:36 PM
I was focusing on trying to make it work with a range of elections before expanding the remaining years. The focus was on getting the conditional object labeled Senate Terms 1976 - 2026 work first. If you were checking the range from 1904 to 1974 then click on the button between the group of years and "Serve First". Right below the button with the down green arrow.

U.S. Senators run for election once every 6 years unless there is a special election. If a Senator is elected in 1976 there won't be an election in 1978 or 1980. Next election would be 1982.

I am trying to have "S" enter for years that a Senator is elected. For years that they are not elected but serving enter a "C".


1976 -- S
1978 -- C
1980 -- C
1982 -- S

When the button is pushed for 1976 it should check to see if the Senator was elected in 1974 or serving. If elected a "C" would be enter. If serving in 1974 it would check to see if was serving in 1972 (Enter "S") if elected in 1972 (Enter "C"). Pattern is 2 election (even) years between years Senators are elected.

The range you reviewed has a problem with this issue. It will not enter any data for the year after an election with "S" entered.


1970 -- S
1972 --
1974 -- S
1976 --
1978 -- S

It needs to be

1970 -- S
1972 -- C
1974 -- C
1976 -- S
1978 -- C

It does not seem to correctly interpret the expression after the variable Senate_E1. Or I have it written wrong.

I also attempted writing it different starting with Senate 1978.

Stan Mathews
12-23-2014, 03:24 AM
I think I see now.

Define a global variable for the form pushed_btn. Set it to any year you want. I used
pushed_btn = "1904"

Add an inline xbasic element to each button as the first action,

dim global pushed_btn as C
pushed_btn = right(this.Name(),4)

The elect_senate script is then


dim global pushed_btn as C
Dim Senate_Status as C
Dim Senate_E1 as C
Dim Senate_E2 as C
Dim Senate_E3 as C
Dim Tbl_Senate as C
Tbl_Senate ="Senate->S"
Senate_Status =""
Senate_Year = val(pushed_btn)
Senate_E1 =Tbl_Senate +str(Senate_Year,4)
Senate_E2 =Tbl_Senate +str(Senate_Year-2,4)
Senate_E3 =Tbl_Senate +str(Senate_Year-4,4)
select
case isblank(Senate_E1)
select
case isblank(Senate_E2)
Senate_Status = "S"
case isnotblank(Senate_E2)
select
case Senate_E3 ="S"
Senate_Status = "C"
case Senate_E3 ="C"
Senate_Status = "S"
end select
case else
Senate_Status =""
end select
case isnotblank(Senate_E1)
Senate_Status =""
case else
Senate_Status =""
end select
eval("parentform:Senate_"+pushed_btn+".value") = Senate_Status

Stan Mathews
12-23-2014, 09:00 AM
I probably don't have the logic right but there's a problem in your script with the isblank() and isnotblank() statements. You're inadvertently testing whether the variables Senate_E1, etc are blank, not the table fields you intend.

I changed from the global variable scenario I suggested and created a udf. The udf is the onpush code for each button (I changed 1976 to present). The udf has one parameter, the year portion of the button name. I change the "blank" tests to alltrim(eval(variable_name)). Eval() returns the field value. Also changed the logic a bit as well.

Give it a try.

39432

gschepp
12-23-2014, 11:43 AM
Thanks Stan, :grin: I tweaked the case part when Senate_E2 >"". It was nearly making it work except it would leave the election year blank after 2 non elected years showing with a "C". The result was S - C - C - Blank - S - C - C - Blank.:thinking: After tweaking it is now S - C - C - S - C - C. :grin:

Replaced that section with:



case alltrim(eval(Senate_E2))= "S" (Section starting with -- case alltrim(eval(Senate_E2))> "")
Senate_Status = "C"
case alltrim(eval(Senate_E2))= "C"
select
case alltrim(eval(Senate_E3)) ="S"
Senate_Status = "C"
case alltrim(eval(Senate_E3)) ="C"
Senate_Status = "S"
end select