Source language: Translate to:

Using Variables to Make a Table Field Name

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Re: Using Variables to Make a Table Field Name

Postby Gaev » Fri Jan 24, 2014 7:55 pm

Enigman:

I have ...

NeoBook
Version 5.8.4
17 April 2013

NeoBookDBPro
v1.3a


I setup a test as follows ...


1) PageEnter code ...
Code: Select all
SetVar "[myTable]" "Patients"


2) Setup Simple Text, CheckBox, Radio Button and Push Button objects with Caption set to [Learn.[myTable].LastName]

3) Then ran the pub (F8) ... and clicked on buttons that ...

a) Opened the Database (dbpOpenAccessDatabase "Learn" "[DatabaseFileName]" "") ... all captions were null

b) Opened Table called Patients (dbpOpenTable "Learn" "Patients" "") ... all captions were null

c) Displayed contents in Grid View (dbpShowGrid "Learn" "Patients" "RectangleForGrid") ... all captions were null

Then, I navigated (in the Grid) from one record to another ... you guessed it ... all captions were null !!!


Assuming you do not have a later version of NeoBook or NeoBookDBpro ... I wonder how you got different results.


Note: While setting this test, I discovered an anomaly ... i.e. if I set the captions to ...

[Learn.Patients.LastName]
[Learn.[myTable].LastName]

... then "all objects EXCEPT the Simple Text object" displayed the value of the field LastName in the current record ... for both lines !!! ... not sure why the exception with the Simple Text object ... but an explanation for the others might be that the first line triggers NeoBook to refresh the content of the object ... while there, it also extracts and refreshes the second line.


Anyway, this is my last response on this post.

Also, given the way this interaction turned out, I have made a mental note to self to refrain from responding to any future posts originating from you ... probably best for both of us.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Using Variables to Make a Table Field Name

Postby Enigman » Fri Jan 24, 2014 9:00 pm

Gaev,

2) Setup Simple Text, CheckBox, Radio Button and Push Button objects with Caption set to [Learn.[myTable].LastName]

3) Then ran the pub (F8) ... and clicked on buttons that ...

a) Opened the Database (dbpOpenAccessDatabase "Learn" "[DatabaseFileName]" "") ... all captions were null

b) Opened Table called Patients (dbpOpenTable "Learn" "Patients" "") ... all captions were null

c) Displayed contents in Grid View (dbpShowGrid "Learn" "Patients" "RectangleForGrid") ... all captions were null


Well, ... don't know ... but those are inconsistent assignments. That may be the problem. First you used [myTable], then opened the table and did other stuff with the literal "Patients". I can't see the code so I can't speculate further.

I have the same NB version which is the highest available, but my DBPro is v1.6a, which is higher.

Anywho ... thanks for your help.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: Using Variables to Make a Table Field Name

Postby Gaev » Sat Jan 25, 2014 7:54 am

Enigman:
Well, ... don't know ... but those are inconsistent assignments. That may be the problem. First you used [myTable], then opened the table and did other stuff with the literal "Patients".

Changed to ...
Code: Select all
dbpOpenTable "Learn" "[myTable]" ""
and
dbpShowGrid "Learn" "[myTable]" "RectangleForGrid"
Same results as before.

I have the same NB version which is the highest available, but my DBPro is v1.6a, which is higher.
I checked the release notes for ...

v1.4 (viewtopic.php?f=21&t=17842)
v1.4a (viewtopic.php?f=21&t=17847)
v1.5 (viewtopic.php?f=21&t=18152)
v1.6 (viewtopic.php?f=21&t=18723)
v1.6a (viewtopic.php?t=18737)

... no mention of the type of issues being discussed (unless it was considered one of the "several other minor fixes")
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Using Variables to Make a Table Field Name

Postby Enigman » Sat Jan 25, 2014 8:37 am

Gaev,

I checked the release notes for ...

v1.4 (viewtopic.php?f=21&t=17842)
v1.4a (viewtopic.php?f=21&t=17847)
v1.5 (viewtopic.php?f=21&t=18152)
v1.6 (viewtopic.php?f=21&t=18723)
v1.6a (viewtopic.php?t=18737)

... no mention of the type of issues being discussed (unless it was considered one of the "several other minor fixes")

Okay, thanks. Good to know.

Changed to ...

Code: Select all
dbpOpenTable "Learn" "[myTable]" ""
and
dbpShowGrid "Learn" "[myTable]" "RectangleForGrid"

Same results as before.

Okay. I can't speculate further without seeing more code, but thanks for trying to replicate.

I have since converted to using table views where I define a sales year table called "Sales_2014" as a virtual view called "Sales".

Code: Select all
SetVar "[SalesTablePrefix]" "Sales_"
SetVar "[SalesYear]" "![Year]"
SetVar "[SalesTable]" "![SalesTablePrefix][SalesYear]"
. Sales Table
dbpCreateView "db" "[SalesTable]" "Sales"
dbpOpenTable "db" "Sales" "salOnTableChange"

That allows me to set all form objects to using direct field assignments like "[db.Sales.fieldname]". That works fine for all objects, including the text input boxes.

I am still using other variable field assignments in subroutine scripts and button scripts and that works fine too. For example, there is a photo box in the upper right where the image filename is set like this:

Code: Select all
[PhotoDir]\[db.[thisTable].SKUPrefix]\[db.[thisTable].SKUPrefix][db.[thisTable].SKUNumber]-[iter].jpg

The above syntax can be used as the target of a photo object as well as a parameter in any NB script command and it works fine. As a photo object definition, the displayed photo will change automatically as I navigate through the data. I also use the "[thisTable]" variable in custom dialog boxes so that I can use one dialog box for all tables including Inventory, Sales and Archive. The tables all have the same format so that works great. When I open the custom dialog I first set [thisTable] to the current table name, then open the box, and everything works as expected against the current table.

So the way everything is working it would still point to an assumption that the only "problem child" is the Text Input box and the way it resolves its variable name assignment. Interestingly, you can make script commands in the events of a text input box, such as in "Lose Focus" that use nested variable field assignments and they work too. It's just that one spot, the Text Input variable name definition, that has a problem resolving embedded nested variables. That fact that it is just the one place where nested variables don't work is why I think maybe it is a bug in NB or maybe only when DBPro is installed.

Thanks again for your support.

Dave? You out there? How about a comment on that?
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: Using Variables to Make a Table Field Name

Postby mishem » Sat Jan 25, 2014 10:55 am

That fact that it is just the one place where nested variables don't work is why I think maybe it is a bug in NB or maybe only when DBPro is installed.


I think this is not a mistake.

It is impossible to foresee all the text options.

For example, you insert a variable [Temp] in which the text "hello[it's just the text in brackets]"

In my version 5.8.4 there is a command
PopulateStr

But few people use it.

Incidentally can try.

Maybe then, and will not need a virtual table.
mishem
 
Posts: 575
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using Variables to Make a Table Field Name

Postby Enigman » Sat Jan 25, 2014 1:28 pm

Mishem,

In my version 5.8.4 there is a command
PopulateStr

But few people use it.

Incidentally can try.

Maybe then, and will not need a virtual table.

Interesting. I have never seen that command. But, though useful elsewhere, one cannot use it to alter the Text Input Box variable specification. The original problem remains.

Not a problem, though. Using virtual tables has some advantages. For instance I just discovered that I really need two inventory tables instead of one. With virtual tables I can open either inventory table without any changes to the program code I have already written. If I had to do it with nested field names, I would have to completely rewrite what I have already done to accomodate alternate inventory tables.

Your original suggestion is still the best.

Thanks.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Re: Using Variables to Make a Table Field Name

Postby Neosoft Support » Mon Jan 27, 2014 11:59 am

Here's why this doesn't work:

When something causes the contents of a variable to change, NeoBook sends out a pub-wide message to all objects that basically says "hey a variable named [whatever] has changed." Each object compares this variable against a list of variables it uses. If it's able to determine that one of its variables has changed it updates itself or takes whatever action is appropriate.

So if you have the following nested variable:

[db.[SalesTable].Description]

If [SalesTable] changes, each object receives a change message from NeoBook. No problem identifying [SalesTable] since it's clearly present within the variable. However, what happens if the greater compound variable changes? For example, assume that [SalesTable] has been set to "2014". This will create a variable called [db.2014.Description]. When that variable changes, each object will be looking for a variable called [db.2014.Description] which they won't find because it doesn't match "[db.[SalesTable].Description]". The object won't realize that it needs to update itself so it won't take any action.

Nested variables always work in code, because the entire variable is populated each time the code is executed. Nested variables don't work reliably on-screen because objects are not always able to recognize that they need to be updated. This is not just limited to Text Entry Fields, but they are affected by this limitation more acutely than other types of objects.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5602
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Using Variables to Make a Table Field Name

Postby Enigman » Mon Jan 27, 2014 12:24 pm

Okay, good explanation. I knew it had to be something particular (or more acutely related) to the Text Input box.

I did manage to work around that using virtual tables (views) which worked nicely. So I have three main forms for dealing with the three main table types, Inventory, Sales, and Archive. Each of those three categories has multiple tables that are swapped in and out of the virtual table view. Each Inventory table has a coordinated set of Sales tables by year, and a coordinated Archive table. Works great so far.

I did run into one little quirk with the dbpOpenTable command when opening virtual tables wherein after any table has been closed and a new table reopened, all subsequent dbpOpenTable commands immediately generate two "Table tablename is not open" errors back to back, even though the table was in fact opened at the time and data is showing. I'll post details in another thread.

Thanks.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Previous

Return to NeoBookDBPro

Who is online

Users browsing this forum: No registered users and 2 guests

cron