Dim intPosition as integer
Dim strNewBinary as string
intPosition = len(strBinary)
If len(strBinary) mod 4 <> 0 then
strNewBinary = left(strBinary, len(strBinary) mod 4) & "-"
End if
For intPosition = len(strBinary) mod 4 to len(strBinary)
strNewBinary = strNewBinary & mid(strBinary, intPosition,4) & "-"
Next
strBinary = left(strBinary,len(strBinary)-1)
Dim intPosition as integer
Dim strNewBinary as string
intPosition = len(strBinary)
If len(strBinary) mod 4 <> 0 then
strNewBinary = left(strBinary, len(strBinary) mod 4) & "-"
End if
For intPosition = (len(strBinary) mod 4)+1 to len(strBinary)
strNewBinary = strNewBinary & mid(strBinary, intPosition,4) & "-"
Next
strBinary = left(strBinary,len(strBinary)-1)
0
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.
Z B..........
Your routine returns the original string...
that is no "-" inserted in string. Believe you have
some conflict with strBinary and strNewBinary.
I was going to suggest using a masked edit box with the mask = "####-####-####-####" but I can't figure out how to right-justify without putting in a lot of code, in which case, just do it by hand:
Dim binstring As String
Dim z As Integer
binstring = "11010101111001"
For z = Len(binstring) - 3 To 1 Step -4
binstring = Left$(binstring, z - 1) & "-" & Mid$(binstring, z)
Next z
MsgBox binstring
I guess this is similar to the Z_Beeblebrox comment, but by working backwords, you don't have to worry about the expanding size of the result and can therefore keep it in the same variable, if that's what you want.
Dim intPosition As Integer
Dim strNewBinary As String
intPosition = Len(strBinary)
If Len(strBinary) Mod 4 <> 0 Then
strNewBinary = Left(strBinary, Len(strBinary) Mod 4) & "-"
End If
For intPosition = (Len(strBinary) Mod 4) + 1 To Len(strBinary) Step 4
strNewBinary = strNewBinary & Mid(strBinary, intPosition, 4) & "-"
Next
strNewBinary = Left(strNewBinary, Len(strNewBinary) - 1)
I made a couple mistakes, I guess this just isn't my day. Anyways, that should do it, I actually tested it this time.
s = "11010101111001"
sBin = Format(s, "&&&&-&&&&-&&&&-&&&&")
and then use Split function.
or another solution
Private Type FullString
str As String * 16
End Type
Private Type PartString
First As String * 4
Second As String * 4
Third As String * 4
Fourth As String * 4
End Type
Private Sub Command1_Click()
Dim fs As FullString
Dim ps As PartString
RSet fs.str = "11010101111001"
LSet ps = fs
Debug.Print ps.First, ps.Second, ps.Third, ps.Fourth
End Sub
0
et1dknAuthor Commented:
Z B
Thanks much for the prompt reply.........
Dan
0
Featured Post
We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Zaphod.
Dim intPosition as integer
Dim strNewBinary as string
intPosition = len(strBinary)
If len(strBinary) mod 4 <> 0 then
strNewBinary = left(strBinary, len(strBinary) mod 4) & "-"
End if
For intPosition = len(strBinary) mod 4 to len(strBinary)
strNewBinary = strNewBinary & mid(strBinary, intPosition,4) & "-"
Next
strBinary = left(strBinary,len(strBina