• 0

[VB.NET] How to change test on a label?


Question

11 answers to this question

Recommended Posts

  • 0

Of course it doesnt work, what's the text in your label right now? it has to correspond to whatever text you specify to replace, and as weenur said, just assign the text property a new value.

Link to comment
Share on other sites

  • 0
Hey,

I am trying to get this code to work, but it doesn't want to work.

label.Text.Replace("Loading...", "Ready to Go!!")

Thanks :D

That command performs a find and replace operation on the string 'label.Text' and returns the result. You are discarding the return value, and even if you used the result, it would be very inefficient.

Instead, to change the text of a label, set label.Text to the string literal "Ready to Go!!".

label.Text = "Ready to Go!!"

If you want to perform a find and replace operation, you would use your current code. But for god's sake, use the return value!

For example, this code...

Dim s As String = "tonsOfText-tonsOfText-tonsOfText"
s = s.Replace("Text", "Stuff")
MsgBox(s)

...would cause a messagebox to appear saying "tonsOfStuff-tonsOfStuff-tonsOfStuff".

BTW: A string is a series of text and a variable type. A string literal is a string defined in code without using a variable.

Link to comment
Share on other sites

  • 0
BTW: A string is a series of text and a variable type. A string literal is a string defined in code without using a variable.

Isn't it an array of chars?

Link to comment
Share on other sites

  • 0
Isn't it an array of chars?

Nope.

Dim s As String <-- string

s = "string literal" <-- string literal

Dim s As String() <-- string array

Dim s As String() = {"string", "literal", "array"} <-- string array instantiated with an array of string literals

Dim c As Char <-- character

c = "c"c <-- character

Dim c As Char() <-- character array

Dim c As Char() = {"c"c, "h"c, "a"c, "r"c, " "c, "a"c, "r"c, "r"c, "a"c, "y"c} <-- character array instantiated with an array of characters

c is the type character for the Char type. That is required under Option Strict.

http://www.python.org/doc/current/ref/strings.html <-- never mind that it is Python, it defines a string literal as a string defined in code using double quotes (or single quotes in Python)

Link to comment
Share on other sites

  • 0
Oh i was saying isn't a String made up of an array of chars, that's what i mean...

In C/C++, yes. But not in .NET ;) At least try not to think of it that way, because the String object doesn't really behave like a character array, even though internally, it very well could be an array of characters...

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.