Source language: Translate to:

Prob

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Postby Gaev » Tue Oct 31, 2006 7:58 am

Alex:

I am responding to your recent PM here because more people can learn from discussions here than in Private Messages ... and others can contribute as well.
I have a big problem and I can't solve it.

I have a Lexicon.dbf, with all my information about me (my
favourite restaurant, hotel, my name, adress...) but in the
lexicon I have my friends too with her informations.

I will have a fonction who knows who use the program, it
means, when in the TextEntry1 I write : "It's : Alexandre",
the lexicon search FirstName and Alexandre, when it has found
Alexandre, it knows all about Alexandre. So, when I write in
the TextEntry : "What is my favourite restaurant", it searchs
the information in Favourite Restaurant and past it the the
result variable.

This fonction is look as the Microsoft Windows Session.

And still a question, my cousin is schoolboy, and in the
lexicon I have a case with his shoolresult, when he says in
the TextEntry1 "Schoolresult" "I had a : 16/20" the lexicon
save the 16 with other result and do a Math founction :
16+13+20+05=54 54/4=13,5
And in [result] it's writing, "Your average is 13,5".

I test with this, but it's not working :

If "[TextEntry1]" "=" "It's : [lexicon.firstname]"
StrParse "[TextEntry1]" ":" "[Item]" "[Cnt]"
StrReplace "[Item2]" "[#32]" "" "[Item2]"
dbfCreate "[PubDir]Lexicon.dbf"
"LastName,String,25|FirstName,String,25|FavouriteRestaurant,String,25|
FavouristeHotel,String,25|ShoolResult,String,25"
""
setvar "[Result]" "Hi [lexicon.firstname]"
If "[TextEntry1]" "=" "Today I have a : [lexicon.schoolresult]"
Math
Endif
Endif

Code: Select all
If "[TextEntry1]" "=" "It's : [lexicon.firstname]"
StrParse "[TextEntry1]" ":" "[Item]" "[Cnt]"
StrReplace "[Item2]" "[#32]" "" "[Item2]"
dbfCreate "[PubDir]Lexicon.dbf"
"LastName,String,25|FirstName,String,25|FavouriteRestaurant,String,25|
FavouristeHotel,String,25|ShoolResult,String,25" ""
a) This will not work ... as [lexicon.schoolresult] is null (nothing) before the database file is opened.

b) Field names (like FavouriteRestaurant) are limited to 10 characters ... most of yours are too long.

c) you should dbfCreate/dbfOpen the database somewhere else (e.g. Book StartUp section) ... otherwise, you are trying to create/open it EVERY TIME the user invokes this function ... normally, database files are opened at the begining of the pub and closed at Exit time (NeoBook will close for you if you do not do a dbfClose).
Code: Select all
setvar "[Result]" "Hi [lexicon.firstname]"
This will cause [result] to contain the text "hi " plus the contents of the firstname field of the FIRST record in the database just created/opened ... what are you trying to do here ? ... if you want to navigate to the record in the database that contains the firstname field that is entered in [TextEntry1], then you need to issue the dbfQuery command first ... and check that a matching record exists.
Code: Select all
If "[TextEntry1]" "=" "Today I have a : [lexicon.schoolresult]"
This will never be true ... the (outer) If/EndIf block is only invoked if [TextEntry1] is equal to "It's : [lexicon.firstname]" (your first line of code) ... so how can it also be equal to "Today I have a : [lexicon.schoolresult]" ? ... no matter what the value of [lexicon.schoolresult] ?
Code: Select all
Math
I am assuming you need help with the Math here ... but first you will have to learn how to store multiple values for a single person ... this is not a simple process that newcomers should attempt in their first database project ... you either need to have multiple Result fields ... and store each result in the "next available field" or have another (relational) database with one record for each result ... and the firstname field being the relating field in the two databases.

I would suggest that you learn about the complexities of working with databases (which is different from plain text files) by studying the example pubs that come with the plugin ... and ask questions here if you do not understand any of them.

Also, as I pointed out in an earlier post, you are making your coding unnecessarily complex by using a single TextEntry Box as a kind of (console) command line input (like in MS DOS) ... NeoBook offers a lot of graphical controls ... so you do not have to worry about such "parsing" of user input ... e.g. You can have a TextEntry Box for user to enter just the "firstname" ... have a Text Box in front to assist user (e.g. Enter First Name Here:) ... and a button after it which user clicks after entering his/her first name ... then, the Click section of the button does NOT have to StrParse anything !!! ... repeat similarly for the SchoolResult entry.

Again as stated previously, study the capabilities of the dbfShowTable command ... will save you a lot of scripting related to invalid user input because a Table display will allow user to select his record with just one click of the mouse.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Alex » Tue Oct 31, 2006 11:42 am

Thanks

It's my idee possible or not ?
Alex
 
Posts: 745
Joined: Sat Mar 04, 2006 4:53 am

Previous

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron