I have this:
....
dim myVar as string
myVar "00014"
....
i need to replace only the left zero with space
in my case
" 14"
REPLACE 0 with space
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: REPLACE 0 with space
Code: Select all
Dim MyLen As Long
MyLen = Len(MyVar)
MyVar = CStr(Val(MyVar))
MyVar = Space(MyLen - Len(MyVar)) & MyVar
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4374
- Joined: 26 Apr 2010, 17:36
Re: REPLACE 0 with space
sorry Hans,HansV wrote:Code: Select all
Dim MyLen As Long MyLen = Len(MyVar) MyVar = CStr(Val(MyVar)) MyVar = Space(MyLen - Len(MyVar)) & MyVar
but my really prob is to align item correct in combobox,
I have arranged a code in old your reply here:
http://www.eileenslounge.com/viewtopic. ... lit=+align
... my actual code:
Code: Select all
With Me.SOSP
.Clear
For I = 1 To Y
MIASTRINGA = Val(Left(ARR_SOSP(I), 5))
strLine = Space(5 - Len(MIASTRINGA)) & MIASTRINGA
Debug.Print strLine & Mid(ARR_SOSP(I), 6, 48)
.AddItem strLine & Mid(ARR_SOSP(I), 6, 48)
DoEvents
Next I
End With
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: REPLACE 0 with space
You have to set the font for the combo box to a fixed-width font such as Courier New.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4374
- Joined: 26 Apr 2010, 17:36
Re: REPLACE 0 with space
now work....HansV wrote:You have to set the font for the combo box to a fixed-width font such as Courier New.
But i dont like Courier New, i use in my all project Arial
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: REPLACE 0 with space
Arial, like Times New Roman, is a variable-width font. It will be virtually impossible to align the text correctly if you use a variable-width font.
Instead of Courier New, you could use Consolas, a newer fixed-width font from Microsoft:
Instead of Courier New, you could use Consolas, a newer fixed-width font from Microsoft:
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: REPLACE 0 with space
Another fixed-width font that might be suitable is Lucida Sans Typewriter.
-
- 4StarLounger
- Posts: 495
- Joined: 13 Sep 2013, 07:56
Re: REPLACE 0 with space
Hi,
Using the Replace function can substitute 1 or more characters with 1 or more others.
eg:-
As for lining up correctly, see Hans' suggestions.
NB. This function will replace all 0's not just the leading ones.
Using the Replace function can substitute 1 or more characters with 1 or more others.
eg:-
Code: Select all
MyVar = Replace(MyVar,"0"," ") ' replace 0 with single space
NB. This function will replace all 0's not just the leading ones.
Regards, Ben
"Science is the belief in the ignorance of the experts."
- Richard Feynman
"Science is the belief in the ignorance of the experts."
- Richard Feynman