Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 7:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Listbox entries from text file
PostPosted: October 18th, 2009, 11:35 pm 
Offline

Joined: November 3rd, 2004, 6:44 pm
Posts: 59
Location: Ipswich, UK
I am using the script below to read a series of names held in a text file into a listbox.
This all works very well but there is always an extra blank line at the bottom of the listbox - Is there a way to remove this, or not generate it in the first place?

Regards

Clive Cartmel


********************************************************
var Names = ""

NamesList = OpenFile("StaffSubjects.txt")

while (NamesList.EndOfFile() == false) {
currentfile = NamesList.ReadLine()
Names = Names + currentfile + "\n"
wait()
}

Listbox.SetSelection(0,-1)
Listbox.ReplaceSelection(Names)

********************************************************

_________________
Opus Headstart Pro 6
Opus Pro 6


For this message Clive Cartmel has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: October 19th, 2009, 12:50 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Clive,

Somewhere... there was a basic example of reading text file LINES. Much like you have... but it starts out with the go to First Line and reads that into a variable..
From then on, all the reads populate the displayed text by putting the line return ( \n ) in front of the expression.

maybe:
Names = "\n" + Names + currentfile

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: October 19th, 2009, 12:52 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Lar_123 wrote:
Clive,

Somewhere... there was a basic example of reading text file LINES. Much like you have... but it starts out with the go to First Line and reads that into a variable..
From then on, all the reads populate the displayed text by putting the line return ( \n ) in front of the expression.

maybe:
Names = "\n" + Names + currentfile


I'm pretty sure I used that construct in this sample pub:
viewtopic.php?t=3632&highlight=listbox+tickbox

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: October 19th, 2009, 9:02 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
NamesList.EndOfFile() ? Names = Names + currentfile : Names = Names + currentfile + "\n"

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Listbox entries from text file
PostPosted: October 19th, 2009, 10:23 pm 
Offline

Joined: November 3rd, 2004, 6:44 pm
Posts: 59
Location: Ipswich, UK
Thanks for both of your suggestions.

Mack, yours looks very interesting, but could I push you to a little more clarity as to how I implement it with my script?

What does the ? do?

Thanks in anticipation.

Regards

Clive Cartmel

_________________
Opus Headstart Pro 6
Opus Pro 6


For this message Clive Cartmel has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: October 19th, 2009, 10:31 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Clive,

It's a conditional operator - basically a smart if-then-else.

Use it in place of your current concatenation:

Names = Names + currentfile + "\n"

It will check the condition of the end-of-file and select the appropriate response - IE concat with new line or concat without new line.

Regards,

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Thanks
PostPosted: October 20th, 2009, 5:42 pm 
Offline

Joined: November 3rd, 2004, 6:44 pm
Posts: 59
Location: Ipswich, UK
Mack,

Many thanks for the explanation - it works perfectly.
I assume that this is another of those undocumented features that could save us a great deal of time if we knew about them?
I can now go and tidy up a number of publications that had this annoying little feature in the past.

Thanks once again.

Clive

_________________
Opus Headstart Pro 6
Opus Pro 6


For this message Clive Cartmel has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Thanks
PostPosted: October 20th, 2009, 6:43 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Clive Cartmel wrote:
I assume that this is another of those undocumented features that could save us a great deal of time if we knew about them?


No, not really. The Conditional Operation is merely a useful way of writing this. It could just as easily have been written with the if-else which has been around since day dot and is well documented. :-)

The undocumented would be to use an array and join which is oddly missing despite its sister the split turning up from strings.

Opus Script is basically JavaScript (<=1.2) and there are many books out there that give useful examples. But credit where credit is due - DW have covered a phenomenal amount of fundamental programming through their examples and help guide.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group