Source language: Translate to:

Coding Help

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Coding Help

Postby HackinHoodLogicsTm » Wed Nov 18, 2015 8:16 am

Hello Neobookers... I run into a coding situation... I checked through the all posted info's but cant find sample of what i need.

I have a text file "Letters.txt"

The letters.txt contains the following

Apple
Pineapple
Mango
Orange

I want a code that after a user inputs for example "App" in the search box it's able to search for all words having "App" in them
such as

Apple
Pineapple

and then randomly break the words into Two Letters and add to the ListBox

Example Break Pineapple to Pi, Ne, Pl, Le and separately add it to the ListBox with Time Delay

I have the code below which is able to randomly select the word from the Letters.txt
But it's left with the function break the words and add to the list box

Code: Select all
.Declaring Variables
SetVar "[2Letters]" "[PubDir]Letters.txt"

.Loop through text file and randomly select a word
Loop "1" "[Lbk]" "[Loop1]"
Delay "500"
FileLen "[2Letters]" "[LetterSize]"
Random "[LetterSize]-1" "[Pos]"
FileRead "[2Letters]" "[Pos]+1" "[Word]"

..Here is where i now want to randomly break the words and add to the list box

EndIf

EndLoop


Please any help will be appreciated
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby virger » Wed Nov 18, 2015 9:43 am

He aqui el ejemplo completo, Disfrutalo

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=8
Name=Text1
X=21
Y=3
W=116
H=24
Anchor=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\qr\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 Busca Data}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
TabOrder=2
ObjectType=9
Name=EnBs
X=4
Y=27
W=150
H=31
Anchor=0
VarName=[Bs]
Align=1
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16316648
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=BtBusca
X=33
Y=66
W=93
H=28
Anchor=0
Text=Busca
Align=2
Key=13
ImageStyle=0
XPTheme=Yes
ObjAction=filelen "[PubDir]Data.txt" "[Len]"¶ListBoxDeleteItem "LsPl" "All"¶loop "1" "[Len]" "[L]"¶    fileRead "[PubDir]Data.txt" "[L]" "[Dt]"¶    SearchStr "[Bs]" "[Dt]" "[ps]" ""¶    if "[ps]" ">" "0"¶        strlen "[Dt]" "[Ld]"¶        loop "1" "[Ld]" "[c]"¶            substr "[Dt]" "[c]" "2" "[Pl]"¶            ListBoxAddItem "LsPl" "0" "[Pl]"¶            delay "500"¶            math "[c]+1" "" "[c]"¶        endloop¶        ListBoxAddItem "LsPl" "0" "-----"¶    endif¶endloop
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=10
Name=LsPl
X=39
Y=100
W=80
H=330
Anchor=0
VarName=[vPl]
VarType=0
XPTheme=Yes
LineColor=0
LineWidth=1
LineStyle=0
FillColor=15263992
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 518
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Coding Help

Postby dpayer » Wed Nov 18, 2015 11:08 am

I think what you are trying to do is have the 'ajax' style listing for your listbox. You want to find all words that have 'at least' the phrase you have typed in.

I looked at Virgir's sample but I think the following example may also help you see how to do this.

1) I made a slightly larger text file with similar words that will clarify functionality. Copy this list into notepad and save as the txt file data.txt into your [pubdir]
Code: Select all
aptitude
applaud
zap
clap
Apple
Pineapple
Mango
Orange


2) Create a new app in NB. Size 320x200 is OK. Paste the following into it:
Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=3
Name=PushButton2
X=8
Y=8
W=144
H=48
Anchor=0
Text=Begin
Hint=you would put this action in the enter page section of code
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[ListboxContents]" ""¶FileToVar "[pubdir]data.txt" "[thisdata]"StrParse "[thisdata]" "[#13][#10]" "[thisdata]" "[thisdatalen]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=9
Name=TextEntry2
X=8
Y=80
W=144
H=32
Anchor=0
VarName=[TextEntry2]
Align=1
EditLen=0
ObjAction=.test if starting or restarting¶SetVar "[ListBoxContents]" ""¶¶.search text file for text found¶StrLen "[TextEntry2]" "[EntryLen]"¶.set minimum length you want to search for - suggest not using 1If "[EntryLen]" ">" "1"¶.for each new character added to input, you have to start over, clearing out the listbox¶¶    Loop "1" "[thisdatalen]" "[CNTR]"¶.grab the whole word¶    SearchStr "[TextEntry2]" "[thisdata[CNTR]]" "[FoundItHere]" ""¶    If "[FoundItHere]" ">" "0"¶    ListBoxAddItem "ListBox2" "0" "[thisdata[CNTR]]"¶    Endif¶¶    EndloopEndif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=10
Name=ListBox2
X=160
Y=0
W=152
H=192
Anchor=0
Text=[ListboxContents]
VarName=[ListBox2]
VarType=0
Sorted=Yes
XPTheme=Yes
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4


 
Parsed in 0.010 seconds, using GeSHi 1.0.8.10

Run the app and test it out! The Begin button reads the file in as a variable. You can do this other ways programatically. You must click the button in this demo.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Coding Help

Postby HackinHoodLogicsTm » Wed Nov 18, 2015 2:38 pm

Thanks guyz for the reply... But where do i paste the code in my software...

When i paste anywhere in the software such an page enter or startup... The App fails to run.... :oops:
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby HackinHoodLogicsTm » Wed Nov 18, 2015 3:10 pm

I guess you did not understand my situation...

I am able to randomly select a word from a Text file in the [PubDir]

And this time, after the word has been selected i want it to be broken into

Two letter words and then add the seperated words to a Listbox.

For example
It randomly selected "BEAUTIFUL" from the textfile

instead of Add Beautiful to the Listbox i want it instead this way

BE
AU
TI
FU
UL

But it should be randomly separated and added to the listbox.. I don't know if this is possible with Neobook...?
Please i need help.
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby dpayer » Wed Nov 18, 2015 3:19 pm

OK, I did misunderstand you. Virger's app did something more than that.

But before I offer any more, I need to know:

1) Will you have many words that will match?
2) if many words do you want them all broken up randomly and put in the list box.
3) do you want to display all partial matches or do you want to wait for the final word selections to be finalized?
(example, if your list has dozens of entries, with a dozen or more partial matches, should they all be broken up, even if you will only choose the final words that fully match)
4) do you want to start searching after only 2 letters being typed in? or more?

You will not be able to simply copy my code into your app. You will need to adapt it. Read the actions and see how it works. Then use the parts that are useful.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Coding Help

Postby HackinHoodLogicsTm » Wed Nov 18, 2015 4:44 pm

Thanks dplayer for the reply...
1) Will you have many words that will match?
2) if many words do you want them all broken up randomly and put in the list box.
3) do you want to display all partial matches or do you want to wait for the final word selections to be finalized?
(example, if your list has dozens of entries, with a dozen or more partial matches, should they all be broken up, even if you will only choose the final words that fully match)
4) do you want to start searching after only 2 letters being typed in? or more?


Ok dplayer I hope you will understand it this way

I am trying to build a software that randomly flicks out word from a .txt
file and then displays the result in the Texbox. So this result will be called the THE MAIN WORD

Then a user will have a button when clicked will randomly generate two letter words THE MAIN WORD

Which means there will be unlimited loop of the two letters from the main word and as of each instance it add the two letters into the Listbox with delay interval.

I hope you understand now...
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby Gaev » Wed Nov 18, 2015 5:21 pm

HackinHoodLogicsTm:

1) Say you have the randomly selected word in a variable called [mainWord].

2) The way to extract the first two letters from [mainWord] is ...
Code: Select all
SubStr "[mainWord]" "1" "2" "[twoLetters]"


3) The way to add an entry to a ListBox is ...
Code: Select all
ListBoxAddItem "ListBox1" "0" "[twoLetters]"


4) So, the whole code would be ...
Code: Select all
... clear any previous items in ListBox
ListBoxDeleteItem "ListBox1" "All"
... loop until all done
While
   ... xtract first two letters
   SubStr "[mainWord]" "1" "2" "[twoLetters]"
   ... add [twoLetters] to the ListBox
   ListBoxAddItem "ListBox1" "0" "[twoLetters]"
   ... remove the first two letters
   StrDel "[mainWord]" "1" "2" "[mainWord]"
   ... get new size of [mainWord]
   StrLen "[mainWord]" "[mainWordLen]"
   ... all done ?
   If "[mainWordLen]" "=" "0"
      ExitWhile
   End
   ... delay 2 seconds
   Delay "2000"
EndWhile


I have not tested this myself ... if you run into unexpected results, post details of your tests here.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Coding Help

Postby HackinHoodLogicsTm » Wed Nov 18, 2015 11:08 pm

Thanks Gaev will try and let you know... You are Genius
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby HackinHoodLogicsTm » Thu Nov 19, 2015 12:59 am

Thanks Gaev :D The above code works perfectly

But i wanted to Two letters to loop unlimitedly... With the code you gave me it ends afters breaking all the words into two letters.

:arrow: Could there be a way the Two letters from the [MainWord] break randomly with loop format that does not End :?:

Thanks...
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby HackinHoodLogicsTm » Thu Nov 19, 2015 2:50 am

Ok i did figured out somehow to Randomly select the two letters words into the ListBox by

1. Created another .txt file
2. Then sent the Two letter words into it
3. Then randomly fetch the two letters words from .Txt file
4. And displays the results in the TextBox

Here is the code

Code: Select all
... clear any previous items in ListBox
ListBoxDeleteItem "ListBox1" "All"

... Declare Variable for Two Letters.txt
    SetVar "[2L]" "[PubDir]TwoLetters.txt"

... loop until all done
While "" "=" ""
   ... xtract first two letters
   StrLen "[mainWord]" "[WordLen]"

   ...Check to see if Letter is not a Two letter word
   If "[WordLen]" ">" "2"
      SubStr "[mainWord]" "1" "2" "[twoLetters]"
      FileWrite "[PubDir]TwoLetters.txt" "Append" "[twoLetters]"

      ... remove the first two letters
       StrDel "[mainWord]" "1" "2" "[mainWord]"
       gotoline "9"
      Else
     
   ...Random Selection of the Two Letters
   FileLen "[2L]" "[LetterSize]"
   Random "[LetterSize]-1" "[Pos]"
   FileRead "[2L]" "[Pos]+1" "[Word]"
   ListBoxAddItem "ListBox1" "1" "[Word]"
   
   ... get new size of [mainWord]
   .StrLen "[mainWord]" "[mainWordLen]"
   ... all done ?
   If "[mainWordLen]" "=" "0"
            ExitWhile
   EndIf
   EndIf
   ... delay 2 seconds
   Delay "2000"
EndWhile


But when dividing the words it follows a pattern

1. Say "BEAUTIFUL" will be devided into this "BE, AU, TI, FU, L" without quotes

I was wondering if it could randomly mix the breaking of the words to something like this

"EB, BE, AU, UA, TI, IT, IF , LU, LA and more

Then in this case it randomly create a two letter from the main word...

Please could this be possible
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby dpayer » Thu Nov 19, 2015 6:31 am

When you create your two letter combinations, store them in an array using a variable array (see help docs). This basically puts the data in this format

[myword1]
[myword2]
[myword3]
[myword4]
[myword5]
[myword6]
[myword7]
[myword8]
[myword9]
etc.
Then you create a subroutine to randomly pic from that list (and then exclude the picked number in the loop]. Place the randomly picked ones in your list box.

Try building that and show us what you have done. We'll help from there.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Coding Help

Postby Gaev » Thu Nov 19, 2015 6:53 am

:

Could there be a way the Two letters from the [MainWord] break randomly with loop format that does not End

Define "does not End" ... do you want the ListBox to contain thousands of entries ? ... what eventually stops this endless addition of entries ?

I was wondering if it could randomly mix the breaking of the words to something like this

"EB, BE, AU, UA, TI, IT, IF , LU, LA and more

Then in this case it randomly create a two letter from the main word...

I am confused about your definition/example of "random" ...

a) EB, BE, AU, UA, TI, IT appear to be two adjacent letters (and their reverse orders) ... do you want the order of the entries to be as stated too ?

b) but then what happened to FU and UF ?

c) and IF, LA are not adjacent letters

d) and the last single letter L is paired with the second last letter ?


Or do you just want to show two any letters from the word that are completely randomly extracted ?
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Coding Help

Postby HackinHoodLogicsTm » Thu Nov 19, 2015 8:48 am

Gaev:
Or do you just want to show two any letters from the word that are completely randomly extracted ?


Yes that is exactly what i want.

I want it to show any two letters from the word that are completely randomly extracted then add it to the ListBox

This way the two letters will have an endless show because some words may repeat itself.

Define "does not End" ... do you want the ListBox to contain thousands of entries ?


Yes the listbox can contain Thousands of entries...

what eventually stops this endless addition of entries ?

Will have a push button that will stop the endless addition of entries

This function will serve as "PAUSE" / "RESUME"

So that when you click on "PAUSE" it pauses the loop format
Then "RESUME" to resume the entries..
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana

Re: Coding Help

Postby HackinHoodLogicsTm » Thu Nov 19, 2015 9:41 am

Thanks to all of you FOR helping me out

I finally got i working :D with the code below

I did it such that

1. Fetch the first two letters from the main word
2. Then append the main word with the first two middle letters
3. Then save them to an external .txt
4. Randomly flick the text from the .txt file

Works as i need. But if you have any other method you can let me know... APRECHAYDIT :)

[syntax=neobook]
Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
... clear any previous items in ListBox
ListBoxDeleteItem "ListBox1" "All"

... Declare Variable for Two Letters.txt
    SetVar "[2L]" "[PubDir]TwoLetters.txt"

... loop until all done
While "" "=" ""
   ... xtract first two letters
   StrLen "[mainWord]" "[WordLen]"
   ShowErrors "False"
   FileLen "[2L]" "[FinalLen]"

   ...Check to see if Letter is not a Two letter word
   If "[FinalLen]" "<" "26"
      SubStr "[mainWord]" "1" "2" "[twoLetters]"
      FileWrite "[PubDir]TwoLetters.txt" "Append" "[twoLetters]"

      SubStr "[mainWord]" "2" "2" "[AddWord]"
      SetVar "[mainWord]" "[mainWord][AddWord]"
     
      ... remove the first two letters
       StrDel "[mainWord]" "1" "2" "[mainWord]"
       gotoline "10"
      Else
     
   ...Random Selection of the Two Letters
   FileLen "[2L]" "[LetterSize]"
   Random "[LetterSize]-1" "[Pos]"
   FileRead "[2L]" "[Pos]+1" "[Word]"
   ListBoxAddItem "ListBox1" "1" "[Word]"
   
   ... get new size of [mainWord]
   .StrLen "[mainWord]" "[mainWordLen]"
   ... all done ?
   If "[mainWordLen]" "=" "0"
            ExitWhile
   EndIf
   EndIf
   ... delay 2 seconds
   Delay "2000"
EndWhile
Parsed in 0.008 seconds, using GeSHi 1.0.8.10
I am proud to be a Neobooker!!!
www.neosoftware.com
Special Thanks To
Mr. David Riley
User avatar
HackinHoodLogicsTm
 
Posts: 120
Joined: Wed Aug 28, 2013 7:03 am
Location: Ghana


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron