Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newline? 3

Status
Not open for further replies.

A1METALHEAD

Programmer
May 21, 2004
76
US
is there anyway to add a new line and a tab in a lable like in c++?(i have already tryed this)

label1.text="1stLine \n 2ndLine \n \t 3rdLine
 
You can't do it in the same way as escaped control characters are not a feature of VB string literals.

You can concantenate strings and constants:
Code:
label1.text="1stLine" & vbcrlf & "2ndLine" & vbcrlf & vbtab & "3rdLine"

Or use String.Format:
Code:
label1.text = string.format("1stLine{0}2ndLine{0}{1}3rdLine", vbcrlf, vbtab)

The second example may seem a bit silly but if you're using String.Format already for other reasons it's a neat trick you can use to eliminate concatenation.

Think how often printf and its variants are used in C/C++.
 
Instead of vbCrLf (which is old-school VB), you might want to use Environment.NewLine, which is from the .NET framework itself.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
also, how do you get a part of a int? im trying to...

'thextbox1.text is inshured to have a 3-digit number
dim guessText as integer = textbox1.text
dim guessOnes as integer 'i want this to be the first digit int guestext
dim guessTens 'second digit
dim guessHundreds 'third digit
 
Try
Code:
guessOnes = cint(textbox1.text.substring(0,1))
guessTens = cint(textbox1.text.substring(1,1))
guessHundreds = cint(textbox1.text.substring(2,1))
 
Or..
Code:
Dim i As Integer
Dim Ones, Tens, Hundreds As Integer

i = int.Parse(textbox1.text)
Ones = i mod 10
Tens = (i / 10) mod 10
Hundreds = (i / 100) mod 10
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Tsk. Tsk.

Never ever trust user input, regardless of what you put in place to prevent non numeric input

Dim i As Integer
Dim Ones, Tens, Hundreds As Integer
Dim isError as Boolean
Try
i = int.Parse(textbox1.text)
if I < 0 then
isError = True
else
Ones = i mod 10
Tens = (i / 10) mod 10
Hundreds = (i / 100) mod 10
End if
Catch ex as Exception
isError = True
End Try

if isError then
''''....
End If


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top