Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
Complete
Gerbil In Training
Topic Author
Posts: 4
Joined: Mon Jan 09, 2006 4:29 am

Visual Basic Special Characters

Mon Jan 09, 2006 5:14 am

Does anyone know how to write out special characters in Visual Basic? The special charcters are things like end-of-line. How would I put that in string data?
 
dragmor
Grand Gerbil Poohbah
Posts: 3644
Joined: Mon Sep 23, 2002 7:24 pm
Location: Oz

Mon Jan 09, 2006 6:06 am

Use the Chr(nn) function

Chr(13) & Chr(10) is carriage return and line feed in windows.
SZ87R6/i5 4560 stock/24GB 2333mhz/840 Evo 250GB/Seagate 2TB/ASUS 760GTX/Dell 2711
Rainbows lie in corded knots
While thunder wakes the sleeping crocs.
 
thegleek
Darth Gerbil
Posts: 7460
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI
Contact:

Mon Jan 09, 2006 11:33 am

yeah.. and if you need an ascii chart to reference, i archived these on my site:

http://www.thegleek.com/quickies/ascii.html

-and-

http://www.thegleek.com/quickies/asciiall.html
––•–√\/––√\/––•–– nostalgia is an emotion for people with no future ––•–√\/––√\/––•–-
 
Complete
Gerbil In Training
Topic Author
Posts: 4
Joined: Mon Jan 09, 2006 4:29 am

Mon Jan 09, 2006 2:37 pm

For readability purposes in the source code, is there some way to continue lines to a next line? In cpp you can just do this:

sprintf(buff,
"one line"
"another line"
):

Can you do the same sort of thing, continue a command to the next line, in Visual Basic?
 
Flying Fox
Gerbil God
Posts: 25690
Joined: Mon May 24, 2004 2:19 am
Contact:

Mon Jan 09, 2006 3:00 pm

Use the _ character.

    s = "This is line #1.  " + _
        "This is line #2."
 
UberGerbil
Grand Admiral Gerbil
Posts: 10368
Joined: Thu Jun 19, 2003 3:11 pm

Mon Jan 09, 2006 3:20 pm

Note that if you're talking about VB/VBA proper (rather than VBScript) there are predefined constants for those common control characters:
vbCr
vbCrLf
vbLf

Msgbox "This is" & vbCrLf & "on two lines"
 
Craig P.
Gerbil Team Leader
Posts: 285
Joined: Tue Dec 31, 2002 3:12 am
Location: South Bend, IN

Mon Jan 09, 2006 4:25 pm

For the named constants, for anything that might double as a key name, make sure you check the documentation. It could also be a constant for one of the events (KeyPress, I think).

Line continuation is properly " _" (note the leading space).
 
UberGerbil
Grand Admiral Gerbil
Posts: 10368
Joined: Thu Jun 19, 2003 3:11 pm

Mon Jan 09, 2006 11:05 pm

The key event constants all begin vbKey... eg vbKeyTab, as opposed to vbTab for chr(9)

You can see the lists of predefined constants in the object browser (hit F2 or find it on the menus) -- I think they're listed under "Constants" in the Classes list (I don't have pre-.Net VB installed on this machine, but looking at the VBA environment in Excel it looks like there's a separate set for KeyCodeConstants).

Who is online

Users browsing this forum: No registered users and 12 guests
GZIP: On