NetTalk Central

Author Topic: Form Drop field - setting a memory variable from another field  (Read 4515 times)

Devan

  • Full Member
  • ***
  • Posts: 230
    • View Profile
    • Email
Form Drop field - setting a memory variable from another field
« on: October 27, 2011, 06:11:05 AM »
Powering along with some NT development lately...You can tell by the number of questions I am suddenly posting!  ;D

Ok, a frustrating problem at the moment: 

I have a file with two fields, FIL:Field1 and FIL:Field2.

I also have a WebForm with a couple of local variables LOC:MyVar1 and LOC:MyVar2

In the form, I have a drop down which pulls the value of FIL:Field1 and populates LOC:MyVar1 with it - works a treat.

Now, I whenever the user changes the drop down, I also want it to pull down the value of FIL:Field2 and populate LOC:MyVar2 with it.  Cannot make it work.

I have gone to the ValidateValue::LOC:MyVar1 and entered the following code:

Code: [Select]
LOC:MyVar2 = p_web.GSV('FIL:Field2')
p_web.SSV('LOC:MyVar2') = p_web.GSV('FIL:Field2')

I have tried setting FIL:Field2 as a Hot Field, removed it.  Tried p_web.GV() and SV() instead of GSV() and SSV() and nothing.

LOC:MyVar1 always works, LOC:MyVar2 is always blank...

Johan de Klerk

  • Full Member
  • ***
  • Posts: 217
  • Johan de Klerk
    • View Profile
    • Designer Software
Re: Form Drop field - setting a memory variable from another field
« Reply #1 on: October 27, 2011, 07:02:28 AM »
Hi Devan,

I think it should be:
LOC:MyVar2 = p_web.GSV('FIL:Field2')
p_web.SSV('LOC:MyVar2',p_web.GSV('FIL:Field2'))

I might be wrong.

Regards

Johan de Klerk
Clarion 10, NT 11.57

Devan

  • Full Member
  • ***
  • Posts: 230
    • View Profile
    • Email
Re: Form Drop field - setting a memory variable from another field
« Reply #2 on: October 27, 2011, 02:08:58 PM »
Haa! You are correct Johan... I typed in the code snippet wrong in my tiredness very late last night...

The second line indeed should be:

p_web.SSV('LOC:MyVar2',p_web.GSV('FIL:Field2'))

Notwithstanding the introduced bug in my code, FIL:Field2 and LOC:MyVar2 are always blank at this point in the code when I inspect them in DebugView and I cannot understand why it is so...  ???

Devan

  • Full Member
  • ***
  • Posts: 230
    • View Profile
    • Email
Re: Form Drop field - setting a memory variable from another field
« Reply #3 on: October 27, 2011, 06:11:20 PM »
Ok - I sorted it out... Basically an ID-10-T error on my part...

Decades of programming with Clarion Win32 has lulled be into a false sense of security that the record buffer will always be there and waiting, and that including 'Hot Fields' in a Browse or Drop will usually make those fields readily available in memory.

In the web environment - NO!

I ended up making the Drop list give me the ID of the record and place that in LOC:MyID, then going to the 'Client-Side' tab of the field and checking the 'Send new value to server' checkbox and clicking the 'Server Code' button to embed a short code snippet which would get the record for me:

Code: [Select]
! Fetch other related report data
p_web._OpenFile(mytable)
lsreportlist{PROP:SQL} = 'SELECT * FROM mytable WHERE ID=' & LOC:MyID
Next(mytable)
If ~Error()
    p_web.SetSessionValue('LOC:MyVar1', FIL:Field1)
    p_web.SetSessionValue('LOC:MyVar2', FIL:Field2)
Else
    p_web.DeleteSessionValue('LOC:MyVar1')
    p_web.DeleteSessionValue('LOC:MyVar2')
End
p_web._CloseFile(mytable)

Oh yeah - I had to remember that the files are not Open() at this point either, so had to manually Open() and Close() them as above...

Hope this helps another wandering soul on the NetTalk road...  ;)


Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: Form Drop field - setting a memory variable from another field
« Reply #4 on: October 27, 2011, 07:54:56 PM »
Devan,

Reading your last post reminded me about _Open and _Close file from p_web. My brain has tracked in Access:<filename>.UseFile() .. Need to standardise to use proper Nettalk etiquette.

Thanks!
Cheers,

Stu Andrews

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Form Drop field - setting a memory variable from another field
« Reply #5 on: October 27, 2011, 10:53:41 PM »
Hi Stu,

Access:FileName.Open is just fine. It's what I use in my code.
The other is really just there so the "same code" works in Legacy and ABC - ie it's there for the benefit of Legacy programmers.

cheers
Bruce


Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: Form Drop field - setting a memory variable from another field
« Reply #6 on: October 28, 2011, 01:22:56 AM »
Oh, okay. Awesome. Good to know.

Actually, I heard your voice saying your reply .. So you have probably already told me that before.

Memory is my strong point.
Cheers,

Stu Andrews