[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

12/13/2011 4:40:00 AM

Is there a fast and easy way to put Tab() into a string?

e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"

ultimately I would want this to be possible

sStr = "ABC"; Tab(10); "DEF"; Tab(20); "GHI"

The only way (too slow) I can think to do this is to open a file and do
a print to the file then read it back.

What other way to do this?
OK, I could write a sub to parse it all but isn't there a better way?


11 Answers

BeeJ

12/13/2011 4:58:00 AM

0

This is kinda hokey...

Private Sub Form_Load()

Dim sStr As String

Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"

Debug.Print StrTab("ABC", "Tab(10)", "DEF", "Tab(20)", "GHI")

End Sub

Public Function StrTab(ParamArray vArgs() As Variant) As String

Dim lX As Long
Dim lPtr As Long
Dim lTabCol As Long

For lX = 0 To UBound(vArgs)
If vArgs(lX) Like "Tab(*)" Then
lTabCol = Val(Split(vArgs(lX), "(")(1))
If lTabCol > lPtr Then
StrTab = StrTab & Space$(lTabCol - lPtr - 1)
lPtr = Len(StrTab)
Else
' error Will Robinson
' just tack the next,if any, on the end of the concat
End If

Else
StrTab = StrTab & vArgs(lX)
lPtr = Len(StrTab)

End If

Next lX

End Function 'StrTab


Dee Earley

12/13/2011 10:46:00 AM

0

On 13/12/2011 04:40, BeeJ wrote:
> Is there a fast and easy way to put Tab() into a string?
>
> e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
>
> ultimately I would want this to be possible
>
> sStr = "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
>
> The only way (too slow) I can think to do this is to open a file and do
> a print to the file then read it back.

A comma between values in the .print output adds a tab:
Debug.Print "ABC", , , , , , , , , , "DEF", , , , , , , , , , "GHI"
If, as per your subject, you actually want it in a string, use simple
string concatenation:
Blah = "ABC" & Tab(10) & "DEF" & Tab(20) & "GHI"
Or even:
Blah = "ABC" & vbTab & vbTab & vbTab etc...

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Dee Earley

12/13/2011 10:50:00 AM

0

On 13/12/2011 10:46, Deanna Earley wrote:
> On 13/12/2011 04:40, BeeJ wrote:
>> Is there a fast and easy way to put Tab() into a string?
>>
>> e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
>>
>> ultimately I would want this to be possible
>>
>> sStr = "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
>>
>> The only way (too slow) I can think to do this is to open a file and do
>> a print to the file then read it back.
>
> A comma between values in the .print output adds a tab:
> Debug.Print "ABC", , , , , , , , , , "DEF", , , , , , , , , , "GHI"
> If, as per your subject, you actually want it in a string, use simple
> string concatenation:
> Blah = "ABC" & Tab(10) & "DEF" & Tab(20) & "GHI"

Sorry, I didn't realise that Tab() wasn't a real function and only meant
something to .Print.
If you want to emulate the exact behaviour, then I think you'll need
your own parser.

Either that or just use simple string concatenation :)

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Larry Serflaten

12/13/2011 12:48:00 PM

0

BeeJ <nos...@spamnot.com> wrote:
> Is there a fast and easy way to put Tab() into a string?
>
> e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
<...>
> What other way to do this?

One way would be to assign the groups using Mid$:

sStr = Space$(30)
Mid$(sStr, 1) = "ABC"
Mid$(sStr, 10) = "DEF"
Mid$(sStr, 20) = "GHI"
Debug.Print Trim$(sStr)

LFS

Mike Williams

12/13/2011 4:20:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jc6m02$q5d$1@dont-email.me...
> This is kinda hokey...
> Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI" Debug.Print
> StrTab("ABC", "Tab(10)", "DEF", "Tab(20)", "GHI")
> [StrTab function snipped]

As far as the VB Tab(n) function is concerned, a single tab "column" is the
average width of all characters in whatever font you happen to be using.
Because of this you can simulate tab columns using Space characters /only/
if all characters in that specific font are the same width (in other words,
only for a fixed width font). The reason it appears to work in your own
specific test case is that you are printing to the VB6 Debug windows which
by default uses a fixed width font (Courier New). It will not work for the
far more widely used proportionally spaced fonts, such as Arial or Times New
Roman. To see what I mean, try the following code using your own existing
StrTab function:

Private Sub Command1_Click()
Me.Font.Name = "Courier New"
Call testPrint
Me.Font.Name = "Arial"
Call testPrint
End Sub

Private Sub testPrint()
Me.Print Me.Font.Name & " using Tabs:"
Me.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
Me.Print "ABCDE"; Tab(10); "FGHIJ"; Tab(20); "KLM"
Me.Print Me.Font.Name & " using BeeJ Function:"
Me.Print StrTab("ABC", "Tab(10)", "DEF", "Tab(20)", "GHI")
Me.Print StrTab("ABCDE", "Tab(10)", "FGHIJ", "Tab(20)", "KLM")
Me.Print
End Sub

If you want something which you can actually embed into a string (as it
appears you do) and which works with proportionally spaced fonts then you
need to use proper Tab positions. If evenly spaced Tab positions are okay
for you then you can simply include one or more vbTab characters at the
appropriate points in your string. As far as the VB Print statement is
concerned the Tab positions are spaced 8 columns apart, where a column is
the average width of all characters in the font you are using (note that
this is not the same as the VB Print statement "Tab Print Zones" which are
spaced 14 columns apart). Each vbTab character in the string causes the
print position to move to the next fixed "8 columns apart" Tab position. For
example:

Dim s1 As String, s2 As String
Me.Font.Name = "Arial"
s1 = "ABC" & vbTab & "DEF" & vbTab & "GHI"
s2 = "ABCD" & vbTab & "EFGHIJ" & vbTab & "KLM"
Me.Print s1
Me.Print s2

If you want evenly spaced Tab positions which are spaced more (or less) than
8 columns apart then you can instead print exactly the same strings using
the GDI DrawText function, which allows you to specify the "number of
columns per Tab position".

Otherwise, if evenly spaced Tab positions are not suitable for your needs
and if you want to set irregularly spaced Tab positions (and if you are not
dumping your strings into a control which allows you to easily do that, such
as ListBox for example or a RichTextBox) then one way to do so would be to
embed control characters into your String at appropriate points and to write
a function which will print that string to a Form or PictureBox or Printer
or whatever, digging out the control characters as it does so and spacing
things out accordingly. For example, you could include a backslash character
followed by two hex digits at each point you need a Tab and your function
could use that information to calculate the desired tab positon and use a
simple CurrentX to achieve it. Your function would also need to perform the
standard "two backslashes signify a literal" thing otherwise you would not
be able to include literal backslashes in your string. There are of course
all sorts of other ways of doing these things, depending on exactly what it
is you want to do.

Mike


BeeJ

12/14/2011 11:20:00 PM

0

Larry Serflaten submitted this idea :
> BeeJ <nos...@spamnot.com> wrote:
>> Is there a fast and easy way to put Tab() into a string?
>>
>> e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI" <...>
>> What other way to do this?
>
> One way would be to assign the groups using Mid$:
>
> sStr = Space$(30)
> Mid$(sStr, 1) = "ABC"
> Mid$(sStr, 10) = "DEF"
> Mid$(sStr, 20) = "GHI"
> Debug.Print Trim$(sStr)
>
> LFS

In my case this would be more difficult since I do not know how long
the line is. But as usual, you offer some inersting advice.


BeeJ

12/14/2011 11:23:00 PM

0

>
> Either that or just use simple string concatenation :)

Almost. Tab(col) accounts for the current position in the string and
applies spaces in the amount needed to get to that column col and only
if necessary; i.e. none if already or past col.


BeeJ

12/14/2011 11:49:00 PM

0

I typically use Lucida Console. Do they allow you to use that font
over there? lol

I do use GDI DrawText in special cases (graphical formatting) but for
some reason (old age) never remember it unless I have switched my brain
to graphics mode.


Mike Williams

12/15/2011 9:29:00 AM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jcbckt$2vc$1@speranza.aioe.org...
>I typically use Lucida Console. Do they allow you to use
> that font over there? lol

No, we don't have fonts over here. We just draw random scribbles in the mud
with a bent stick!


Jeff Johnson [MVP: VB]

12/15/2011 3:54:00 PM

0

"Larry Serflaten" <serflaten@gmail.com> wrote in message
news:081dcb0d-11a0-4240-97b7-d815fbcad1ee@b32g2000yqn.googlegroups.com...

>> Is there a fast and easy way to put Tab() into a string?
>>
>> e.g. like Debug.Print "ABC"; Tab(10); "DEF"; Tab(20); "GHI"
> <...>
>> What other way to do this?
>
> One way would be to assign the groups using Mid$:
>
> sStr = Space$(30)
> Mid$(sStr, 1) = "ABC"
> Mid$(sStr, 10) = "DEF"
> Mid$(sStr, 20) = "GHI"
> Debug.Print Trim$(sStr)
>
> LFS

....Larry???