Using TAB as CSV delimiter

C

Charlotte E.

Hi guys,

What's the difference between to two vbConstants:

- vbTab - Chr(9) and
- vbKeyTab - Chr(57)

Which one will be the most corrent to use as delimiter in a .CSV file?

Thanks,

CE
 
G

GS

Hi guys,
What's the difference between to two vbConstants:

- vbTab - Chr(9) and
- vbKeyTab - Chr(57)

Which one will be the most corrent to use as delimiter in a .CSV
file?

Thanks,

CE

Hi Charlotte,
I've always used vbTab and so can vouch that it works reliably. I'm not
familiar with vbKeyTab and so can't speak to its usage in place of
vbTab.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
A

Auric__

GS said:
Hi Charlotte,
I've always used vbTab and so can vouch that it works reliably. I'm not
familiar with vbKeyTab and so can't speak to its usage in place of
vbTab.

vbTab is correct, because that's the ASCII code for the tab character.
(Chr(57) = "9".)

vbKeyTab is the scan code for pressing the Tab key on the keyboard (a
completely unrelated task), largely used in forms, like this:

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If vbKeyTab = KeyAscii Then MsgBox "Tab"
End Sub
 
G

GS

GS said:
vbTab is correct, because that's the ASCII code for the tab
character. (Chr(57) = "9".)

vbKeyTab is the scan code for pressing the Tab key on the keyboard (a
completely unrelated task), largely used in forms, like this:

Private Sub UserForm_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger) If vbKeyTab = KeyAscii Then MsgBox "Tab"
End Sub

Thanks! That makes sense since KeyAscii would be the right place for
using vbKey<whateve> because we would be testing a keyboard action! I'm
not familiar with vbKeyTab because the only keyboard action I test for
is when the ESC key is pressed, and I always use the numeric value
rather than the VB constant.

Also, vbTab is a printable string character and so makes sense that it
would be used for delimiting a string!<g>

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
A

Auric__

GS said:
Thanks! That makes sense since KeyAscii would be the right place for
using vbKey<whateve> because we would be testing a keyboard action! I'm
not familiar with vbKeyTab because the only keyboard action I test for
is when the ESC key is pressed, and I always use the numeric value
rather than the VB constant.

vbKey<X> is useful for avoiding magic numbers. Writing your code now, you
know that 27 is Escape (or whatever), but a month from now? A year? Unless
you normally carry those values in your head, it's best IMO to use the
constants.
Also, vbTab is a printable string character and so makes sense that it
would be used for delimiting a string!<g>

Yeah, precisely. Upon reviewing the docs, it looks like vbKeyTab = 9, not 57
as Charlotte posted. Not entirely sure where that number came from. Maybe
the scan codes are different for non-US keyboards, I dunno.
 
G

GS

vbKey said:
you
know that 27 is Escape (or whatever), but a month from now? A year?
Unless
you normally carry those values in your head, it's best IMO to use
the
constants.

Yeah, you make a valid point! Yes, the ESC key # is 27 and since it's
the only one I use it's easy to remember. However, I do feel that using
the constant makes code more self-documenting and so I should change my
habits to that end.

And yes, you're correct that vbKeyTab = KeyAscii(9)!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
A

Auric__

GS said:
Yeah, you make a valid point! Yes, the ESC key # is 27 and since it's
the only one I use it's easy to remember. However, I do feel that using
the constant makes code more self-documenting and so I should change my
habits to that end.

I strongly recommend it -- but OTOH, in some of my old VB6 projects, I used
various keys in such a way that it was common to see something like this:

Select Case KeyCode
Case vbKeyTab
Case vbKeyLeft
Case Asc("W")
End Select
 
G

GS

GS said:
I strongly recommend it -- but OTOH, in some of my old VB6 projects,
I used various keys in such a way that it was common to see
something like this:

Select Case KeyCode
Case vbKeyTab
Case vbKeyLeft
Case Asc("W")
End Select

I started using this line in the _Keypress event on forms...

If KeyAscii = 27 Then Unload Me 'Esc

...as the default in my form template, which was formatted for font and
had the basic Ok/Cancel buttons placed. I just did copy/paste to insert
the line in other _Keypress events.

As of now the form template has been modified as follows.

If KeyAscii = vbKeyEscape Then Unload Me

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
C

Charlotte E.

Hi Guys,


Sorry for a late reply, but I've been away for a few days :)

But, thank you for your replys - everything makes sense now :)


CE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top