Shoutbox

how do i do this... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: how do i do this... (/showthread.php?tid=69312)

how do i do this... by roflmao456 on 12-09-2006 at 10:50 PM

if i want to like say write something to an external file ( viewer.html )

its first preset text in the file is "Hello"

but in the script i want to open it and set that text to "Hi"

can anyone give out a code for this


RE: how do i do this... by Baggins on 12-09-2006 at 11:09 PM

You would need to read in the file, parse it, and replace the text.  I am not very good at parsing stuff though.

Or did you mean that the file just consists of the one word "hello" and nothing else?

EDIT: could you give an example of what exactly the file would look like?

I am assuming because you say html it would need parsing


RE: how do i do this... by roflmao456 on 12-11-2006 at 12:03 AM

this is my viewer.html file i need to replace the bold ones below..

code:
<HTML>
<TITLE>YouTube Viewer</TITLE>
<Script>
var v;

function viewVid(video){
v = video;
document.getElementById("vid").innerHTML = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/12345678901\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/12345678901\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>";
}
</Script>
<BODY onload=''>
<div id='vid' align='center'>
</div>
</BODY>
</HTML>


the 12345678901 is what i am going to replace
RE: how do i do this... by Baggins on 12-11-2006 at 12:12 AM

ok, one solution popped into my head, first create three variables

in the first store:

code:
<HTML>
<TITLE>YouTube Viewer</TITLE>
<Script>
var v;

function viewVid(video){
v = video;
document.getElementById("vid").innerHTML = "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/

second:
code:
\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/

third:
code:
\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>";
}
</Script>
<BODY onload=''>
<div id='vid' align='center'>
</div>
</BODY>
</HTML>


now when you find out the id for whichever video you want to veiw, store it in a variable.

finally write the variables in this order to your file

var1, id, var2, id, var3

that is write NOT append

then you have a .html that you can open

that is the easiest way i can think of

RE: how do i do this... by Spunky on 12-11-2006 at 12:16 AM

code:
var myVar = <variable with source code in it>.split("http://www.youtube.com/v/");
myVar = myVar[1].substr(0,11)//Change 11 to another number if needed
<variable with source code in it>.replace(/myVar/g);

Remember to write back to the file for changes to take affect
Not tested, but it should work

EDIT: Beaten :o
RE: how do i do this... by CookieRevised on 12-11-2006 at 02:49 AM

quote:
Originally posted by SpunkyLoveMuff
code:
var myVar = <variable with source code in it>.split("http://www.youtube.com/v/");
myVar = myVar[1].substr(0,11)//Change 11 to another number if needed
<variable with source code in it>.replace(/myVar/g);

Remember to write back to the file for changes to take affect
Not tested, but it should work

EDIT: Beaten :o

that will not work...

The split function is not needed and will actually make that this wont work. Delimeters ("http://www.youtube.com/v/" in your case) will obviously be deleted from the final array the split function has created.

-------

The proper way to do this:

1) read the entire file into a variable

now you have the entire contents of the file in 1 string. All it takes now is just replacing parts of the string like you replace text in strings...

2) replace the number with your own number in that variable (use the string.replace() function for this with a regular expression so you replace all occurances and not simply the first one).

3) overwrite the file with the new text in that variable

But as stated several times by now, look things up yourself roflmao456. You clearly don't learn a thing by asking copy/paste solutions as you keep comming asking for basic programming stuff. Study the JScript 5.6 documentation (available from the official Plus! scripting database, category "others").

Hence I'm not going to give the code, you need to look this up and find out by yourself using the documentation. Start by reading about files and how to open, read and write them. It is clearly explained with examples in the documentation.