[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Can't Use Chr(10) in CodeBehind

Posted on 2004-11-12
5
Medium Priority
?
326 Views
Last Modified: 2008-03-06
Why can't I seem to use Chr 's in codebehind using VB?

Example:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim CRLF As String
    CRLF = Chr(10)
    blah
    blah
    blah
End Sub

vbCRLF doesn't seem to be recognized either.

Nor does: Const CRLF As Char = Chr(10)

I get an error message that says that Chr is undeclared.

0
Comment
Question by:gbmcneil
5 Comments
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 12567526
Dim myChar = vbCrLf

works for me!

When do u get the error? When you compile?

0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 12567697
You may have to put this at the top

Imports Microsoft.VisualBasic
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12567823
hi
another solution if you simply want a new line is to use vbNewLine and you dont need any additional imports. you simply treat it as a string

regards
0
 

Author Comment

by:gbmcneil
ID: 12568249
Gentlemen: Thank you for your help.

raterus seemed to have the solution that worked for me. I added the Import declaration before the Class, as so:

Imports Microsoft.VisualBasic
Public Class MyForm
    blah
    blah
    blah

This allowed every possible way to define a carriage return/linefeed to work and not cause the error I encountered above.

Dim myNewLine = vbNewLine
Dim myChar = vbCrLf
Dim MyCrLf As String = Chr(10)
Const CRLF As Char = Chr(10)

all work now!

Where did you come across that one raterus?

0
 
LVL 33

Expert Comment

by:raterus
ID: 12576674
it's the namespace that constant is defined in, not some big secret or anything.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question