View Full Version : String problem, I'm confused...
robmaggs
08-20-2008, 05:01 PM
Hi,
I want to take a text file of urls and then assign them to several button objects which in turn open an embedded web object
http://www.something.com
http://somethingelse.com
and so on...
I've done this so far by:
button1 = TextFile.ReadToString("C:\\url.txt");
url = String.Mid(button1, 0, -1);
Web.LoadURL("Web1", url);
This is great because it will load line 1 for button 1 but how do I move on to line 2 and load that url for button 2
I'm confused, any assistance will be greatly appreciated.
Many thanks
Rob
RizlaUK
08-20-2008, 05:49 PM
name your buttons 1,2,3,4,5 etc and use the below code in each button
tbUrl = TextFile.ReadToTable("C:\\url.txt");
if tbURL then
strURL=tbUrl[String.ToNumber(this)];
Web.LoadURL("Web1", strURL);
end
simple and basic but it should work
robmaggs
08-21-2008, 07:01 AM
Thanks Rizla, I reall appreciate your help.
tbUrl = TextFile.ReadToTable("C:\\url.txt");
if tbURL then
strURL=tbUrl[String.ToNumber(this)];
Web.LoadURL("Web1", strURL);
end
Sorry for being such a dumbass but where am I naming buttons 1,2,3,4,5?
Am I doing this under the properties for each button object ie Attributes/object name or is this being assigned somewhere else?
I understand (I think) what is going on but I struggle with the code syntax somewhat.
Thanks in advance
Rob :)
ShadowUK
08-21-2008, 07:41 AM
Yep, Call it Button1, Button2, Button3, ... and then run the code.
robmaggs
08-21-2008, 01:33 PM
Hiya,
not quite sure what I'm doing wrong, but for some reason nothing happens when I click the buttons. :huh
Did I need to put any code anywhere else?
Thanks
Rob :)
RizlaUK
08-21-2008, 01:51 PM
now try it
tbUrl = TextFile.ReadToTable("C:\\url.txt");
if tbURL then
strURL=tbUrl[String.ToNumber(String.Remove(this,"Button")];
Web.LoadURL("Web1", strURL);
end
Derek
08-21-2008, 02:24 PM
Try this:
strURL=tbURL[String.ToNumber(Button.GetProperties(this).ObjectN ame)];
robmaggs: Watch tbURL and tbUrl case mixing. It's likely to cause headaches! Variable names are case sensitive.
Ulrich
08-21-2008, 03:31 PM
Here is an example. You may have 1 to 5 buttons, according the number of URLs in the text file.
Ulrich
robmaggs
08-23-2008, 09:08 AM
Thanks for your help, I think upeters solution might be more suitable for my project, but I'm struggling to work out how I could open URLs from a listbox.
I see from upeters example that a table is created from a texfile and populated with two values. In my case the first one would be a website name and the second a url. When the user clicks on a selection in the list box it would open a link in a web object (Web1)
-- read the text file
file_table = TextFile.ReadToTable("AutoPlay\\Docs\\url_1.txt");
for i, entry in file_table do
-- split the line
separator = String.Find(entry, "|");
option = String.Mid(entry, 1, separator-1);
action = String.Mid(entry, separator+1, -1);
ListBox.AddItem("ListBox1", option, action);
end
What would I have to do to get be able to call the url value from the table and open the url in the web object.
Sorry to be a pain, I just can't get my head around it.
Thanks Rob
Ulrich
08-23-2008, 09:53 AM
Here is an updated example. I dropped the buttons of the former project and replaced them with a ListBox. Clicking on a single entry of the ListBox will load the corresponding page in the web object.
Ulrich
robmaggs
08-23-2008, 10:11 AM
That's totally awesome, Thanks so much Ulrich and everyone who helped me.
Rob :)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.