Set button label from external

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Set button label from external

Post by bidgeeman » Sat Jun 20, 2009 10:17 am

Hi.
I'v been stuck on this one for a while.
I'm trying to set button labels from text lines of an external text file.

Code: Select all

on mouseUp
   answer folder "choose folder"
   if it is empty then exit mouseUp
   put it into tTitles
   open url tTitles , "/Test.txt"
    set the label of button "Button2" to line 1 of url tTitles , "/Test.txt"
end mouseUp
If anyone could offer a tip as to where I'm falling over it would be much appreciated. :) :oops:

Thanks
Bidge

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Sat Jun 20, 2009 11:05 am

Hi Bidge

your first line is incorrect: instead of

Code: Select all

answer folder "choose folder"
try:

Code: Select all

answer file "choose folder"
(or with a bit of refinement):

Code: Select all

answer file "choose file:"
Also here's your revised code for what you want to achieve:

Code: Select all

on mouseUp
    answer file "choose file:" 
   if it is empty then exit mouseUp 
  put url ("file:"&it) into tData
    
    set the label of button "Button2" to line 1 of tData
end mouseUp
It seems to work...

:)

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sat Jun 20, 2009 11:16 am

Hi Gyro.

Thanks for the response. I'm loading other files from that folder, hence the line

" open url tTitles , "/Test.txt".

The file is Test.txt located in the same folder and want to put the first few lines of that txt file into the label of some buttons.
Even with that script change you suggested it did'nt work so I must be doing something else wrong in the script???

Cheers
Bidge

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sat Jun 20, 2009 3:31 pm

you are mixing file-access methods. "open file" can't be used with the url keyword (and is too complex to be used in 99% of all cases).

what you want is probably something like this:

Code: Select all

on mouseUp
  answer folder ""
  if it = "" or the result = "cancel" then
    exit mouseUp
  end if
  put url ("file:" & it & "/test.txt") into contentOfFile
  set the label of button 1 to lie 1 of contentOfFile
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 21, 2009 12:10 am

Thanks for pointing that out BvG.

Code: Select all

put url ("file:" & it & "/test.txt") into contentOfFile 
This file access method is new to me (I'm just learning). Many thanks for the help. :)

Cheers
Bidge
[/quote]

Post Reply