Forums › Forums › SIMPOL Programming › Using SelectKey
- This topic has 5 replies, 2 voices, and was last updated 14 years, 8 months ago by JD Kromkowski.
- AuthorPosts
- August 4, 2009 at 8:46 am #298JD KromkowskiParticipant
I am having trouble understanding how to use formvar.selectkey(). Consider the following: function DailyDetails() integer iErrnum; iErrnum = 0 wxwindow w2 w2 =@ wxwindow.new(100,100,400,600,captiontext=”Details”,error=iErrnum) string filename filename = “C:SIMPOLFormsDetails.sxf” integer error; error = 0 string errtext; errtext = “” dataform1 f2 f2 =@ opendataform1(filename, error=error, errortext=errtext) f2.setcontainer(w1) //f2.selectfirst() // instead I’d like to use f2.selectkey in Superbase, we could do this: OPEN FORM “C:PROGRA~1SBCLASDESAMPLESCLASSICBUGBASEEMPLOYEE.SBV” SET INDEX “Lastname” INDEX Lastname SELECT FORM KEY “Holden” SELECT FORM CURRENT FORM So let’s say that just like this Superbase example, my “Details.sfx” form uses a table called “employee”. It has a number of indexes. The first index which will be the default one used in Simpol is “SSN”. But I want to use an index called “Fullname”. (In the SB example, the first index is “EmployeeNumber” which is why I change it to “Lastname”) anyvalue value; value = “Holden” boolean lock; lock = .true boolean found; found = .true integer thisError; thisError = 0 // here is where I am not sure how to // “Set” the index to Fullname or // otherwise declare and pass the index “Fullname” // in fooling around I tried this which will work // but only because I knew to go to the next // index after the current one f2.selectkey(value,f2.mastertable.currindex.next,lock,found,thisError) // surely there must be a better way f2.selectcurrent() wxprocess(1000000) end function f2 By the way, the debugger really doesn’t work correctly. I can’t seem to look at variables in function outside of main.
August 5, 2009 at 11:02 am #1494MichaelKeymasterJDK wrote:
> I am having trouble understanding how to use formvar.selectkey().
>
> Consider the following:
>
> function DailyDetails()
> integer iErrnum; iErrnum = 0
> wxwindow w2
> w2 =@ wxwindow.new(100,100,400,600,captiontext="Details",error=iErrnum)
> string filename
> filename = "C:SIMPOLFormsDetails.sxf"
> integer error; error = 0
> string errtext; errtext = ""
> dataform1 f2
> f2 =@ opendataform1(filename, error=error, errortext=errtext)
> f2.setcontainer(w1)
> //f2.selectfirst()
> // instead I'd like to use f2.selectkeyOK
>
> in Superbase, we could do this:
>
> OPEN FORM "C:PROGRA~1SBCLASDESAMPLESCLASSICBUGBASEEMPLOYEE.SBV"
> SET INDEX "Lastname"
> INDEX Lastname
> SELECT FORM KEY "Holden"
> SELECT FORM CURRENT FORM
> So let's say that just like this Superbase example, my "Details.sfx" form
> uses a table called "employee". It has a number of indexes. The first
> index which will be the default one used in Simpol is "SSN".
> But I want to use an index called "Fullname".
>
>
> (In the SB example, the first index is "EmployeeNumber" which is why
> I change it to "Lastname")
>
> anyvalue value; value = "Holden"
> boolean lock; lock = .true
> boolean found; found = .true
> integer thisError; thisError = 0
> // here is where I am not sure how to // "Set" the index to Fullname or
> // otherwise declare and pass the index "Fullname"
> // in fooling around I tried this which will work
> // but only because I knew to go to the next
> // index after the current one
> f2.selectkey(value,f2.mastertable.currindex.next,lock,found,thisError) // surely there must be a better way
> f2.selectcurrent()
> wxprocess(1000000)
> end function f2There is:
f2.selectkey(value,f2.mastertable.table!Lastname,lock,found,thisError)
Also, it is probably a bad idea to lock the record unless you intend to
change it. Especially since you are passing a found parameter, which
means that you will get a record object back even if it doesn't match,
and even if it is wrong, you will still be locking it.>
> By the way, the debugger really doesn't work correctly. I can't seem
> to look at variables in function outside of main.If you mean the Watch window, that has been seen at times, but we
thought we had fixed most of the cases. Normally you should still be
able to hover your mouse over a variable in the code to see its value.
Also, if you place the cursor in the variable and press Shift+F9, it
should pop up the Watch window where you can do fairly extensive
analysis of the variables.Ciao, Neil
September 1, 2009 at 7:17 am #1751JD KromkowskiParticipantFiguring out the value of a field on the current record has always
been pretty straightforward in SBREQUEST YourField
or
REQUEST YourField.YourFileSo how do I do it in SIMPOL
function Details(type(*) me, dataform1 f)
// f is the current form and obviously works
// with various select statements
// e.g. f.selectfirst(error=e)if me.type == wxmenuitem
string test
test = "TESTING TESTING"
wxmessagedialog(message = me.name,captiontext = test)//Here I want to determine the value of a
//field FULLNAME on the current record and
//then pass it as string to variable test
//for sake of ease this field is a string so
//I don't need to manipulate/transform it
//with .tostr()
//I thought something like thistest = f.mastertable.record!FULLNAME
//I've tried other variation using f.masterrecord.etc
//without successtest = f.whatdoIuse!FULLNAME
// this is check to see if I've done it correctly
wxmessagedialog(message = me.name,captiontext = test)//ETC.
end functionSeptember 2, 2009 at 12:49 pm #1711MichaelKeymasterJDK wrote:
> Figuring out the value of a field on the current record has always
> been pretty straightforward in SB
>
> REQUEST YourField or REQUEST YourField.YourFile
>
> So how do I do it in SIMPOL
>
> function Details(type(*) me, dataform1 f) // f is the current form
> and obviously works // with various select statements // e.g.
> f.selectfirst(error=e)
>
> if me.type == wxmenuitem string test test = "TESTING TESTING"
> wxmessagedialog(message = me.name,captiontext = test)
>
> //Here I want to determine the value of a //field FULLNAME on the
> current record and //then pass it as string to variable test //for
> sake of ease this field is a string so //I don't need to
> manipulate/transform it //with .tostr() //I thought something like
> this
>
> test = f.mastertable.record!FULLNAME
>
> //I've tried other variation using f.masterrecord.etc //without
> success
>
> test = f.whatdoIuse!FULLNAME
>
> // this is check to see if I've done it correctly
> wxmessagedialog(message = me.name,captiontext = test)
>
> //ETC. end function
>The easy way would be to add db1util to your project, and then use
fieldval2string().Ciao, Neil
September 3, 2009 at 2:21 am #1752JD KromkowskiParticipantJDK >> test = f.whatdoIuse!FULLNAME
>>
>> // this is check to see if I've done it correctly
>> wxmessagedialog(message = me.name,captiontext = test)
>>
>> //ETC. end function
>>NR> The easy way would be to add db1util to your project, and then use
> fieldval2string().Well, yes I saw this function as part of formlib and had intended to
eventually use it. But I am still going to need to be able to
determine/get/establish the current record.I want to do this in terms of the dataform1 f.
But something like this doesn't work.r =@ f.selectcurrent()
I suppose what I really need to do is Tablevar.selectcurrent()
test = r!FULLNAME
September 4, 2009 at 5:38 am #1594JD KromkowskiParticipantOK. Here is a better example of what I was trying to do, and my path of
confusion.function main()
integer error; error = 0
string filename; filename = "C:SIMPOLFormsMyForm.sxf"
string errtext; errtext = ""dataform1 f
f =@ opendataform1(filename, error=error, errortext=errtext)// select a record here
// f.selectlast()
sbme1table table
sbme1record r
sbme1field field
table =@ f.mastertable.table
r =@ table.select()
field =@ table!TheField
string test
test = r.get(field)
end function testI thought this sort of worked, until I realized that this is not giving me
the current record (i.e. the "current" record in terms of what the form is
showing).It seems to only be giving me the field value I am after for the first
record.So, if at // select a record here//, I have
f.selectlast()test still give me TheField value for the first record.
Why is that? I am guessed it has something to do with the line
r =@ table.select()
In other words, I am setting r to "point" at the first record even though
the f is "pointing" to the last record by virtue of f.selectlast().Then, I asked myself what is that masterrecord thing all about? So my new
working example is as follows:function main()
integer error; error = 0
string filename; filename = "C:SIMPOLFormspayroll1c.sxf"
string errtext; errtext = ""
dataform1 f
f =@ opendataform1(filename, error=error, errortext=errtext)//
//f.selectfirst()
//f.selectlast()
//f.selectnext()
// etc.
//
sbme1table table
sbme1record r
sbme1field field
table =@ f.mastertable.table
r =@ f.masterrecord.record
field =@ table!TheField
string test
test = r.get(field)
end function testSo having figured this all out (which works), it is now clear, all I
actually needed to do is this.string test
test = f.masterrecord.record.get(f.mastertable.table!TheField)Of course, this example presumes that TheField is a string.
- AuthorPosts
- You must be logged in to reply to this topic.