Jump to content

Fill a string with zeros and value. (005)


Guest deBruineBeren

Recommended Posts

Guest deBruineBeren

I would like to place the value of "FileLongGR" in to a textbox "txtLongGR".

And fill the empty spaces in front of the value with zeros (00).

In eMbedded Visual Basic I used this code:

Dim FileLongGr

Dim strLongGR As String


strLongGR = String(3 - Len(FileLongGr), "0") & FileLongGr

txtLongGr.Text = strLongGR

Is there something like this for VB.NETCF ?

Thanks in advance.

Link to comment
Share on other sites

sorry, just to clarify

you want to fill a textbox with 0's after a specific word has been set to the textbox text property?

you can use the PadLeft or PadRight property to do this i believe

for example:

string tempString = "Some String";

this.textBox1.Text = tempString;

this.textBox1.Text = this.textBox1.Text.PadRight(this.textBox1.MaxLength - tempString.Length, '0');

this is C# but should be no different than vb.net

Edited by Tech
Link to comment
Share on other sites

Guest deBruineBeren

@ Tech, thanks for the hint.

What I want to do is place a value in a textbox and fill the empty spaces in front of the value with zeros.

This is the code i'm using now thanks to your hint:

Dim LongGraden As String = MathClass.Graden(Longitude)

            txtLongGraden.Text = LongGraden.PadLeft(txtLongGraden.MaxLength, "0")

The Matclass.Graden calculates the Longitude in degrees.

The Maxlenght of textbox txtLongGraden = 2

So if the Longitude in degrees is for example 4 the textbox wil show 04.

If the Longitude is 52 (here in the Netherlands) the textbox wil just show 52.

Thanks again.

Alex.

;)

Link to comment
Share on other sites

  • 3 weeks later...
Guest lspatricio
@ Tech, thanks for the hint.

What I want to do is place a value in a textbox and fill the empty spaces in front of the value with zeros.

This is the code i'm using now thanks to your hint:

Dim LongGraden As String = MathClass.Graden(Longitude)

            txtLongGraden.Text = LongGraden.PadLeft(txtLongGraden.MaxLength, "0")

The Matclass.Graden calculates the Longitude in degrees.

The Maxlenght of textbox txtLongGraden = 2

So if the Longitude in degrees is for example 4 the textbox wil show 04.

If the Longitude is 52 (here in the Netherlands) the textbox wil just show 52.

Thanks again.

Alex.

:D

<{POST_SNAPBACK}>

you may also want to use the Format string function. It's more flexible. ;)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.