473,473 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can I write this shorter?

Hello

I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));

Thanks
// Smyken
Jul 20 '05 #1
3 1231
You can pass the parameter inside an string with a string separator like ";"
and split into an array inside the function. Then make a For Loop and make
the operation for each element in the array...this allows you to pass any
number of elements to the function.

Raul Carrillo

"Smyke" <me*****@ing.umu.se> escribió en el mensaje
news:6c**************************@posting.google.c om...
Hello

I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));

Thanks
// Smyken

Jul 20 '05 #2
me*****@ing.umu.se (Smyke) writes:
I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));


Not unless the function changeout is build to understand it. There is
a big difference between calling a function once and calling it three
times.

Unless you have *many* calls, I doubt you save anything by making an
easier way to call the function. The extra code required for that will
take more work than just calling three times.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
"Smyke" <me*****@ing.umu.se> wrote in message
news:6c**************************@posting.google.c om...
I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));


Perhaps:

for (var i=1;i<=3;i++){
changeout("sub"+i);
}

or

function chgout(){
for (var i=0;i<arguments.length;i++)
changeout(arguments[i]);
}

and then

chgout('sub1','sub2','sub3');

HTH,

Vjekoslav
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
4
by: Aki | last post by:
Hi, I have a problem with writing cookies in IE. The code works fine in Netscape 7.2, Opera 8 and Firefox 1.04. In IE 6 the cookie isn't written. I run WinXP SP2. I'm trying to show a...
8
by: Servé Lau | last post by:
Sometimes I code like this: char *p = strchr(buf,'\n'); if (p) *p = 0; But I've also seen the shorter expression: buf = 0;
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
4
by: darrel | last post by:
I'm backtracking to a problem I had a month or so ago. I need to write XML files quite a bit. I'm finding that the way I'm doing it doesn't write a new, clean XML file each time, but just dumps...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
4
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through...
3
by: skanemupp | last post by:
is there anyway to make this shorter? i hate having these big blocks of similar-looking code, very unaesthetic. maybe doesnt matter good-code-wise? anyway can i make some function that makes this...
4
by: raylopez99 | last post by:
Please consider the below and how to make name references shorter-- there has to be a way. RL using System; namespace MyNamesSpace1 { class ManagerClass
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.