|
Joined: Feb 2004
Posts: 119
Vogon poet
|
OP
Vogon poet
Joined: Feb 2004
Posts: 119 |
tab1 {
if (!$1-) return $chr(9)
else {
var %tablist,%p = 1
while (%p <= $numtok($1-,59)) {
%tablist = $instok(%tablist,$gettok($1-,%p,59),0,9)
inc %p
}
return %tablist
}
}
tab2 {
if (!$1-) return $chr(9)
var %wpm = 1,%tablist
while ($ [ $+ [ %wpm ] ]) {
%tablist = $instok(%tablist, $ [ $+ [ %wpm ] ] ,0,9)
inc %wpm
}
return %tablist
}
Why won't $tab1 work like $tab2?? what am i doing wrong???
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
The parameters that are sent with the identifier are delimited by commas, meaning in the following example:
$identifier(this is a test, and so is this)
$1 = this is a test $2 = and so is this $0 = 2
This means that in your tab2 alias, there will only be 1 iteration, since it says while $N.
An easy fix is to tokenize the incoming parameters: tokenize 59 $1
Btw why are you using $instok with 0 as destination position? You know that appends it to the end, right?
Also why are you looping?
alias tab return $replace($1,;,$chr(9))
Greets
Last edited by FiberOPtics; 18/01/05 11:58 AM.
Gone.
|
|
|
|
Joined: Feb 2004
Posts: 119
Vogon poet
|
OP
Vogon poet
Joined: Feb 2004
Posts: 119 |
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
alias tab return $iif($1,$replace($1,;,$chr(9)),$chr(9))
Replacing 0 with %p doesn't make any difference, since it will also add it to the end, because you are doing an incremental loop.
Last edited by FiberOPtics; 18/01/05 12:11 PM.
|
|
|
|
Joined: Feb 2004
Posts: 119
Vogon poet
|
OP
Vogon poet
Joined: Feb 2004
Posts: 119 |
[quote] alias tab return $replace($$1,;,$chr(9)) some how it don't work like i want it too..
tab2 { if (!$1-) return $chr(9) var %wpm = 1,%tablist while ($ [ $+ [ %wpm ] ]) { %tablist = $instok(%tablist, $ [ $+ [ %wpm ] ] ,0,9) inc %wpm } return %tablist}
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Ok let's go over this.
Your original code samples showed this:
$tab --> returns a tab $tab(params;params;params) --> returns a tab delimited list instead of ; delimited list, meaning $tab(a;b;c) turns into a<tab>b<tab>c
Isn't that what you want?
That's what my above alias does anyways, be more specific please.
Greets
Gone.
|
|
|
|
Joined: Feb 2004
Posts: 119
Vogon poet
|
OP
Vogon poet
Joined: Feb 2004
Posts: 119 |
on a mdx listview
did -i $dname 3 1 headertext $tab(a,b,c)
$tab2 works.. but not $tab1. basically i want it to seperate the title's for the listview. even when i change $tab1 to work with $chr(44) and not $chr(59) it still won't work.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
EDIT: Wait a min, tab2 works but not tab1? Eh?
It should be the other way round, tab 2 is the one working incorrectly for me.
*confused*
Nevertheless, regarding the changing from 59 to 44:
I take it you didn't read my first reply carefully.
The whole point is: the parameters you specify in an alias are delimited by commas.
Meaning $tab(a,b,c) sends to the tab alias 3 parameters:
$1 = a $2 = b $3 = c
and $0 = 3 and $1- = a b c (see how there are no more commas? that's because a comma is a delimiter)
Meaning $tab(a;b;c) sends to the tab alias 1 parameter:
$1 = a;b;c
with $0 = 1 and $1- = a;b;c
Do you see what I mean? Looping with "while $N" is futile, since there is only 1 parameter, so you have to tokenize 59 $1 to make it work like you want to.
//tokenize 59 a;b;c --> will give as tokens: $1 = a, $2 = b, $3 = c
Greets
Last edited by FiberOPtics; 18/01/05 12:35 PM.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Look, I took both your aliases and tested them: $tab1(a;b;c) gives a<tab>b<tab>c $tab2(a;b;c) gives a;b;c This is all normal behaviour like I tried to point out to you. I cannot understand that you say tab1 isn't working, since tab1 is the only alias out of the two that changes the ; to a tab. Btw you still havent said what exactly you want. Yea you told me that it's for a listview, but that has no meaning for me since I don't use mdx, although I can imagine that you simply want tabs between your text so that they are put in the right column. From what I see, you want to replace tokens delimited by a ; to tokens delimited by tabs, so that they are added to your list correctly. Meaning $tab(column1;column2;column3) changes to column1<tab>column2<tab>column3 and that column1 is added to the first, column2 added to the second, and column3 added to the third column. Your tab1 alias does this, not tab2. I can't help you further, sorry. Edit: Further testing: Made a window @@, and did //aline @@ $tab1(1;2;3) which added respectively 1 2 3 in 3 seperate columns to the window. So 1 number in 1 column. With //aline @@ $tab2(1;2;3) it just put the whole string 1;2;3 to the first column. 
Last edited by FiberOPtics; 18/01/05 01:16 PM.
Gone.
|
|
|
|
Joined: Feb 2004
Posts: 119
Vogon poet
|
OP
Vogon poet
Joined: Feb 2004
Posts: 119 |
tab1 {
if (!$1-) return $chr(9)
else {
var %tablist,%p = 1
while (%p <= $numtok($1-,44)) {
%tablist = $instok(%tablist,$gettok($1-,%p,44),0,9)
inc %p
}
return %tablist
}
}
tab2 {
if (!$1-) return $chr(9)
else {
var %wpm = 1,%tablist
while ($ [ $+ [ %wpm ] ]) {
%tablist = $instok(%tablist, $ [ $+ [ %wpm ] ] ,0,9)
inc %wpm
}
return %tablist
}
}
ok let me do this again.. i changed the code so both works for $chr(44) now. $tab1 still doesn't work like $tab2 does.. what am i doing wrong?
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
alias tab1 {
if (!$0) { return $chr(9) }
scon -r var % $+ tablist = $!+(%tablist,$chr(9), $* )
return $mid(%tablist,2)
} $tab1 -> <tab> $tab1(hello,world) -> hello<tab>world
New username: hixxy
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
*sigh* you still don't understand it, because you put $gettok($1-,%p,44), while I already explained that the comma's are delimiters, and not there when doing $1-
For your code with tokens delimited by ;:
alias tab return $iif($1,$replace($1,;,$chr(9)),$chr(9))
Example: $tab(a;b;c) or $tab
Anyway, tidy posted a solution that lets you use the regular comma as delimiter, so use that.
Greets
Last edited by FiberOPtics; 18/01/05 05:07 PM.
Gone.
|
|
|
|
|