forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Tab-character within a Table-column

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Fri Oct 01, 2010 7:36 pm    Post subject: Tab-character within a Table-column Reply with quote

Hi,

does anyone know if it's possible and how it's done to have tab-characters within a table column?

For different reasons i use a table element as a list. If i now assign a memory-list to this table, only the part until the first tab-character appears.
logical - the tab-character is used to split items into colums.

I thought of a kind of masking the tab-character with @strrepl() and then replace it back, but if i assign that, it's the same thing as before.

Any suggestions?
.
Back to top
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Oct 02, 2010 11:26 am    Post subject: Reply with quote

Can you submit a small example of what you are trying to do?
Back to top
View user's profile Send private message Send e-mail
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Sat Oct 02, 2010 1:27 pm    Post subject: Reply with quote

Hi,

i need to do something like this:

Code:

  DIALOG CREATE,New Dialog,-1,0,240,160
  DIALOG ADD,TABLE,TABLE1,10,7,223,144,Column 1
  DIALOG SHOW

  list create,1
  list add,1,Record 1@tab()0001@tab()ok
  list add,1,Record 2@tab()0002@tab()ok
  list add,1,Record 3@tab()0003@tab()ok
  list add,1,Record 4@tab()0004@tab()ok

  list assign,Table1,@text(1)

:EvLoop
  wait event
  goto @Event()

:Close
  list close,1
  exit



The tab-characters from list 1 should appear in column 1 of table1.
.
Back to top
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Mon Oct 04, 2010 2:35 am    Post subject: Reply with quote

I see your point...hmmmm

Interestingly, if you placed an actual tab (using the tab key) in the VDS IDE and put quotes around it it works but if you use @chr(34)@tab()@chr(34) it doesn't work. Consider the weirdness below when viewing the generated test.txt file.

Code:
  DIALOG CREATE,New Dialog,-1,0,240,160
  DIALOG ADD,TABLE,TABLE1,10,7,223,144,Column 1
  DIALOG SHOW

  list create,1
  # using tabs in notepad
  list add,1,"Record 1    0001    ok"
  # using tabs in MS Word
  list add,1,"Record 2    0002    ok"
  #using tabs the VDS IDE
  list add,1,"Record 3                        0003  ok"
  #programmically adding tabs
  list add,1,"Record 4"@tab()"0004"@tab()"ok"
  list savefile,1,test.txt

  list assign,Table1,1

:EvLoop
  wait event
  goto @Event()

:Close
  list close,1
  exit


Result
Code:
Record 1    0001    ok
Record 2    0002    ok
Record 3                        0003  ok
Record 4    0004    ok

The length of Record 3 is 40 characters where the rest is only 16. So a tab in the IDE is not a really tab.

Still playing with it....
Back to top
View user's profile Send private message Send e-mail
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Mon Oct 04, 2010 4:02 am    Post subject: Reply with quote

After further research it seems that using the tab key in the IDE does not insert a tab character but a series of spaces instead.

Edit: Weird... I just played with this for about an hour and now my IDE is inserting tabs when I used the tab key but then later it inserted a series of spaces again... I think my PC is on PCPBig Smile

It looks like you might not be able to do what you want.

To bad CR didn't allow the table element to use a definable field separator instead of the tab character only. No clue
Back to top
View user's profile Send private message Send e-mail
mmatica
Newbie


Joined: 03 Dec 2004
Posts: 12

PostPosted: Mon Oct 04, 2010 9:40 am    Post subject: Reply with quote

You have reserved only one column for the table.
If you replace
Code:

DIALOG ADD,TABLE,TABLE1,10,7,223,144,Column 1|Column 2|Column 3

everything will be OK.

M.
Back to top
View user's profile Send private message
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Mon Oct 04, 2010 10:02 am    Post subject: Reply with quote

@mmatica: Please read the topic again, then you'll understand what's the problem.

@Aslan: The tab-behaviour of the IDE in my opinion is a useful feature called smart-tab. you can turn it off in editor options.

Isn't there any API way to change the fieldseparator of a ListView control?
.
Back to top
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Mon Oct 04, 2010 1:01 pm    Post subject: Reply with quote

I haven't found any API that will do this. I even tried directly editing a subitem (via API) with text that included a tab and the table parsed it out also, probably since the Table refreshes any time it's touched. I think VDS is just parsing the input then setting the subitems accordingly.

If you find an API solution, please let me know Wink
Back to top
View user's profile Send private message Send e-mail
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Tue Oct 05, 2010 1:47 am    Post subject: Reply with quote

For the moment i ended up with a tab-simulation-function. It calculates needed spaces to fill the distances between items.

Here it is. (feel free to play around with it, maybe someone finds a better way.)

Code:

#                                                                                         
#    Function bsTabulator  / bornSoft                                                     
#    --------------------------------                                                     
#                                                                                         
#    Example how to simulate Tab-Characters within a table column.                       
#                                                                                         
#        Usage :    %T = @bsTabulator(<tab-width>,<text>)                                 
#                                                                                         
#                                                                                         
                                                                             
#DEFINE Function,bsTabulator

  list create,1
  list create,2

  #    Here is some text we want to assign to a table column
  list add,1,This is a key@tab()@tab()Value1@tab()@tab()Value2
  list add,1,Stupid text@tab()@tab()10000@tab()@tab()50
  list add,1,13 characters@tab()@tab()100000@tab()@tab()333
  list add,1,Some more chars@tab()@tab()50@tab()@tab()1

  DIALOG CREATE,Tabulator Test,-1,0,675,251
  DIALOG ADD,STYLE,STYLE1,Courier New,10,,,
  DIALOG ADD,TABLE,Table1,6,6,664,184,Column1[644],,STYLE1
  DIALOG ADD,EDIT,AddEDIT,200,6,414,21,Another line with@tab()3 Tabs@tab()@tab()in it.,,MULTI,TABS,STYLE1
  DIALOG ADD,BUTTON,Add,200,424,46,22,Add
  DIALOG ADD,BUTTON,Exit,200,620,50,22,Exit,,default
  DIALOG ADD,STATUS,STAT,STAT
  DIALOG ADD,EDIT,TW,200,546,18,22,8
  DIALOG ADD,TEXT,TEXT1,206,488,,,Tab-width:
  DIALOG ADD,BUTTON,OK,200,569,30,22,OK
  DIALOG SHOW

:Load
  #    First we replace all Tab-Characters ( ascii 9 ) by a Tab-Tag. 
  list assign,2,@strrep(@text(1),@tab(),<TAB>,all)

  #    The TabWidth is an integer value, which specifies the distance in characters. 
  %%TabWidth = @dlgtext(TW)

  #    Here we load our processed text to the table-column. 
  %i = @next(2)
  repeat
      list add,Table1,@bsTabulator(%%Tabwidth,%i)
      %i = @next(2)
  until @not(@ok())

:EvLoop
  wait event
  goto @event()

:AddButton
  #    Of course we we can add additional lines in the same way. 
  %%Text = @dlgtext(AddEdit)
  list add,1,%%Text
  %%Text = @strrep(%%Text,@tab(),<TAB>,all)
  list add,Table1,@bsTabulator(%%TabWidth,%%Text)
  goto EvLoop

:OKButton
  list clear,Table1
  list seek,1,0
  goto Load

:Close
:ExitButton
  list close,1
  list close,2
  EXIT

#    Here starts the function that processes our lines.       
#    Variable %1 is the TabWith and variable %2 is our text. 
:bsTabulator
  if @greater(@pos(<tab>,%2),0)
      %A = @new(list)
      %B = @new(list)
      list assign,%A,@strrep(%2,<tab>,@cr()@lf(),all)
      %i = @next(%A)
      repeat
          %L = @len(%i)
          %M = @mod(%L,%1)
          if @greater(%M,0)
              %F = @diff(%1,%M)
            else
              %F = %1
          end
          list add,%B,@fill(@sum(%L,%F),%i)
          %i = @next(%A)
      until @not(@ok())
      %R = @strrep(@text(%B),@cr()@lf(),,all)
      list close,%A
      list close,%B
    else
      %R = %2
  end
  exit %R



Cheers. bornSoft
.
Back to top
View user's profile Send private message Visit poster's website
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Fri Oct 29, 2010 2:06 am    Post subject: Reply with quote

Hi,

based on the example above i've made a proper workaround for this problem.

I needed a solution for my special case. For this the above solution did measure but today i had to spend hours in an uncomfortable bus and there was time for me to go over this item. So I ended up with the following script.

Maybe on the first look it seems a bit complicated , but the function itself stuffed into a dsu should be useful and easy to use for everyone who stumbles over the same problem.

Contrary to the above solution this one is not a one-way-tab-faking. You can easily restore the original string and it also works best with multi-column tables.

Greetings. bornSoft

Code:

#                                                                                         
#    Function bsTableTab  / bornSoft                                                     
#    -------------------------------                                                     
#                                                                                         
#    This Function simulates Tab-Characters within a string by the correct number of     
#    no-break-spaces and restores the original string including all Tab-Characters.       
#                                                                                         
#    This is nessesary if Tab-Characters are needed within table columns.                 
#                                                                                         
#        Usage :    %T = @bsTableTab( <text> [ ,<tab-width> ,RESTORE ] )                 
#                                                                                         
#    <Tab-width> is optional and specifies the number of characters a tab-character       
#    is covering. This must be an integer. If this is omitted, the default value is 8.   
#                                                                                         
#    If the argument RESTORE is set, a previously manipulteted string is turned into     
#    its primary form.                                                                   
#                                                                                         
#                                                                                         

#DEFINE Function,bsTableTab

  DIALOG CREATE,bsTableTab Test - bornSoft,-1,0,676,274
  DIALOG ADD,STYLE,STYLE1,Courier New,10,,,
  DIALOG ADD,TABLE,Table1,6,6,664,184,Column1[464]|Column2[180],,STYLE1,DBLCLICK
  DIALOG ADD,EDIT,AddEDIT,200,6,490,21,Another line with@tab()4 Tabs@tab()@tab()in it.|x@tab()@tab()(y),,MULTI,TABS,STYLE1
  DIALOG ADD,BUTTON,Add,200,500,46,22,Add
  DIALOG ADD,EDIT,TW,200,616,18,22,8
  DIALOG ADD,TEXT,TEXT1,204,558,,,Tab-width:
  DIALOG ADD,BUTTON,OK,200,640,30,22,OK
  DIALOG ADD,TEXT,TEXT2,228,7,,,Restored line ( doubleclick a table-item to rebuild its original tab-characters )
  DIALOG ADD,EDIT,RestoreEdit,246,6,600,21,,,TABS,STYLE1,MULTI
  DIALOG ADD,BUTTON,Exit,246,620,50,22,Exit,,DEFAULT
  DIALOG SHOW

  #    Some text to assign to a table column   
  list create,1
  list add,1,This is a key@tab()@tab()Value1@tab()@tab()Value2
  list add,1,Stupid text@tab()@tab()10000@tab()@tab()50@tab()
  list add,1,13 characters@tab()@tab()100000@tab()@tab()333|Item2@tab()2
  list add,1,Some more chars@tab()@tab()50@tab()@tab()1

:Load
  #    Load the processed text to the table   
  #    TabWidth is an integer value, that     
  #    specifies the distance in characters   
  %%TabWidth = @dlgtext(TW)
  list clear,Table1
  list seek,1,0
  %i = @next(1)
  repeat
      parse "%%item1;%%item2",%i
      list add,Table1,@bsTableTab(%%item1,%%Tabwidth)@tab()@bsTableTab(%%item2,%%Tabwidth)
      %i = @next(1)
  until @not(@ok())

:EvLoop
  wait event
  goto @event()

:AddButton
  #    Add additional lines in the same way   
  %%Text = @dlgtext(AddEdit)
  list add,1,%%Text
  goto load
  goto EvLoop

:OKButton
  #    EM_SETTABSTOPS                         
  %x = @sendmsg(@winexists(~AddEdit),$0CB,1,@chr(@prod(@dlgtext(TW),4)))
  %x = @sendmsg(@winexists(~RestoreEdit),$0CB,1,@chr(@prod(@dlgtext(TW),4)))
  goto Load

:Table1DBLCLICK
  #    Rebuild the original string             
  %i = @strrep(@item(Table1),@tab(),@fsep(),all)
  %%TabWidth = @dlgtext(TW)
  if @not(@null(%i))
      dialog set,RestoreEdit,@bsTableTab(%i,Restore,%%TabWidth)
      dialog focus,RestoreEdit
  end
  goto EvLoop

:Close
:ExitButton
  list close,1
  exit

#    Function bsTableTab                       
:bsTableTab
  #    Default TabWidth: 8 characters         
  if @numeric(%2)
      %W = %2
    elsif @numeric(%3)
      %W = %3
    else
      %W = 8
  end
  if @equal(%2,RESTORE) @equal(%3,RESTORE)
      goto bsTableTab_Restore
  end

  #    Replace all @tab() characters with the 
  #    correct number of no-break-spaces       
  if @greater(@pos(@chr(160),%1),0)
      %1 = @strrep(%1,@chr(160),@chr(32),all)
  end
  if @greater(@pos(@tab(),%1),0)
      %A = @new(list)
      %B = @new(list)
      if @equal(@strdel(%1,1,-1),@tab())
          %E = 1
      end
      list assign,%A,@strrep(%1,@tab(),@cr()@lf(),all)
      %i = @next(%A)
      repeat
          %L = @len(%i)
          %M = @mod(%L,%W)
          if @greater(%M,0)
              %F = @fill(@diff(%W,%M))
            else
              %F = @fill(%W)
          end
          %F = @strrep(%F,@chr(32),@chr(160),all)
          list add,%B,%i%F
          %i = @next(%A)
      until @not(@ok())
      %R = @strrep(@text(%B),@cr()@lf(),,all)
      list close,%B
      list close,%A
      if @not(%E)
          %H = @asc(@strdel(%R,1,-1))
          %G = @strdel(%R,1,-1)
          while @equal(@strdel(%R,1,-1),@chr(160))
              %H = @asc(@strdel(%R,1,-1))
              %R = @substr(%R,1,-1)
          wend
      end
    else
      %R = %1
  end
  exit %R

:bsTableTab_Restore
  #    Rebuild the original string             
  %P = @pos(@chr(160),%1)
  if @greater(%P,0)
      %x = 1
      %C = @substr(%1,%x)
      while @not(@null(%C))
          if @equal(%C,@chr(160))
              %T = 1
              %x = @succ(%x)
              %C = @substr(%1,%x)
              while @equal(%C,@chr(160))
                   %T = @succ(%T)
                   %x = @succ(%x)
                   %C = @substr(%1,%x)
              wend
              %R = %R<TAB>%T</TAB>%C
            else
              %R = %R%C
          end
          %x = @succ(%x)
          %C = @substr(%1,%x)
      wend
      while @greater(@pos(<TAB>,%R),0)
          %x = @strslice(%R,<TAB>,</TAB>)
          %y = @div(%x,%W)
          if @greater(@mod(%x,%W),0)
              %y = @succ(%y)
          end
          %c = 1
          %T = @tab()
          while @less(%c,%y)
              %T = %T@tab()
              %c = @succ(%c)
          wend
          %R = @strrep(%R,<TAB>%x</TAB>,%T)
      wend
  end
  exit %R



.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group