M
marc hankin
In my macro (below) named "RemovSpcsAftInitCapng", I
created a long variable "j", and I included the following
statements:
Do While i <= lStrMain
i = i + 1
If i = 1 Then j = i
If i = 2 Then j = j - 1
If i > 2 Then j = j - 1
For some reason which eludes me, after the first
iteration, j = 0 despite the coding above. What am I
doing wrong?
Thank you in advance for any help,
Marc
Function MsgboxFn()
Dim strMain As String, strNuMain As String, strChoice
As String
Dim strLeft As String, strTrim As String, strRt As
String
Dim strMsg As String, StrMsg1 As String,
strBlankSpace As String
Dim blnEmptySpc As Boolean
Dim lStrMain As Long, lstrNuMain As Long, lstrLeft As
Long, lstrRt As Long
Dim i As Long, j As Long
Dim lStrRtInverter As Long, lStrMainCntr As Long
StrMsg1 = "||strMain =" & strMain & "||strNuMain
=" & strNuMain & "||strChoice =" & strChoice & "||strLeft
=" & strLeft & vbCr
StrMsg1 = StrMsg1 & "||strTrim =" & strTrim
& "||strRt As String =" & strRt & "||strMsg =" & strMsg
& "||StrMsg1 =" & StrMsg1 & vbCr
StrMsg1 = StrMsg1 & "||strBlankSpace =" &
strBlankSpace & "||blnEmptySpc =" & blnEmptySpc
& "||lStrMain =" & lStrMain & "||lstrNuMain =" &
lstrNuMain & vbCr
StrMsg1 = StrMsg1 & "||lstrLeft =" & lstrLeft
& "||lstrRt =" & lstrRt & "||i =" & i & "||j =" & j
& "||lStrRtInverter =" & lStrRtInverter & "||lStrMainCntr
=" & lStrMainCntr
MsgBox "StrMsg1 =" & StrMsg1
MsgBox "strMsg =" & strMsg
End Function
Private Sub RemovSpcsAftInitCapng()
'
' Macro recorded 8/29/2004 by Marc B. Hankin
'
Dim strMain As String, strNuMain As String, strChoice
As String
Dim strLeft As String, strTrim As String, strRt As
String
Dim strMsg As String, StrMsg1 As String,
strBlankSpace As String
Dim blnEmptySpc As Boolean
Dim lStrMain As Long, lstrNuMain As Long, lstrLeft As
Long, lstrRt As Long
Dim i As Long, j As Long
Dim lStrRtInverter As Long, lStrMainCntr As Long
Beegin:
Selection.Range.Case = wdTitleWord
strMain = Selection.Text
strNuMain = strMain
'MsgBox strMain
'MsgBox strNuMain
lStrMain = Len(strMain) '# of chars in
strMain
lstrNuMain = Len(strNuMain) '# of
chars in strMain
'MsgBox lStrMain
'
'
MsgboxFn
Do While i <= lStrMain
i = i + 1
If i = 1 Then j = i
If i = 2 Then j = j - 1
If i > 2 Then j = j - 1
MsgBox "Iteration No." & i & " AND j=" & j
& " AND strNuMain=" & strNuMain
strBlankSpace = ""
strBlankSpace = Mid(strNuMain, j, 1)
blnEmptySpc = False
If strBlankSpace = Chr(32) Then blnEmptySpc = True
If blnEmptySpc = False Then If strBlankSpace = Chr
(160) Then blnEmptySpc = True
If blnEmptySpc = True Then
MsgBox ("There is a space located in Space
No. " & j)
If j > 1 Then
strLeft = Left(strNuMain, i - 1)
Else
strLeft = ""
End If
'
MsgBox "Now leaving ..strLeft = null.. End
If ..."
'
'MsgBox strLeft
'
lStrRtInverter = lstrNuMain - i
j = i - 1
strRt = Right(strNuMain, lStrRtInverter)
'MsgBox strRt
strNuMain = strLeft & strRt
'Length of each string
lstrNuMain = Len(strNuMain)
lstrLeft = Len(strLeft)
lstrRt = Len(strRt)
End If
MsgBox "Now leaving ..Bottom of loop..."
MsgboxFn
Loop
End Sub
created a long variable "j", and I included the following
statements:
Do While i <= lStrMain
i = i + 1
If i = 1 Then j = i
If i = 2 Then j = j - 1
If i > 2 Then j = j - 1
For some reason which eludes me, after the first
iteration, j = 0 despite the coding above. What am I
doing wrong?
Thank you in advance for any help,
Marc
Function MsgboxFn()
Dim strMain As String, strNuMain As String, strChoice
As String
Dim strLeft As String, strTrim As String, strRt As
String
Dim strMsg As String, StrMsg1 As String,
strBlankSpace As String
Dim blnEmptySpc As Boolean
Dim lStrMain As Long, lstrNuMain As Long, lstrLeft As
Long, lstrRt As Long
Dim i As Long, j As Long
Dim lStrRtInverter As Long, lStrMainCntr As Long
StrMsg1 = "||strMain =" & strMain & "||strNuMain
=" & strNuMain & "||strChoice =" & strChoice & "||strLeft
=" & strLeft & vbCr
StrMsg1 = StrMsg1 & "||strTrim =" & strTrim
& "||strRt As String =" & strRt & "||strMsg =" & strMsg
& "||StrMsg1 =" & StrMsg1 & vbCr
StrMsg1 = StrMsg1 & "||strBlankSpace =" &
strBlankSpace & "||blnEmptySpc =" & blnEmptySpc
& "||lStrMain =" & lStrMain & "||lstrNuMain =" &
lstrNuMain & vbCr
StrMsg1 = StrMsg1 & "||lstrLeft =" & lstrLeft
& "||lstrRt =" & lstrRt & "||i =" & i & "||j =" & j
& "||lStrRtInverter =" & lStrRtInverter & "||lStrMainCntr
=" & lStrMainCntr
MsgBox "StrMsg1 =" & StrMsg1
MsgBox "strMsg =" & strMsg
End Function
Private Sub RemovSpcsAftInitCapng()
'
' Macro recorded 8/29/2004 by Marc B. Hankin
'
Dim strMain As String, strNuMain As String, strChoice
As String
Dim strLeft As String, strTrim As String, strRt As
String
Dim strMsg As String, StrMsg1 As String,
strBlankSpace As String
Dim blnEmptySpc As Boolean
Dim lStrMain As Long, lstrNuMain As Long, lstrLeft As
Long, lstrRt As Long
Dim i As Long, j As Long
Dim lStrRtInverter As Long, lStrMainCntr As Long
Beegin:
Selection.Range.Case = wdTitleWord
strMain = Selection.Text
strNuMain = strMain
'MsgBox strMain
'MsgBox strNuMain
lStrMain = Len(strMain) '# of chars in
strMain
lstrNuMain = Len(strNuMain) '# of
chars in strMain
'MsgBox lStrMain
'
'
MsgboxFn
Do While i <= lStrMain
i = i + 1
If i = 1 Then j = i
If i = 2 Then j = j - 1
If i > 2 Then j = j - 1
MsgBox "Iteration No." & i & " AND j=" & j
& " AND strNuMain=" & strNuMain
strBlankSpace = ""
strBlankSpace = Mid(strNuMain, j, 1)
blnEmptySpc = False
If strBlankSpace = Chr(32) Then blnEmptySpc = True
If blnEmptySpc = False Then If strBlankSpace = Chr
(160) Then blnEmptySpc = True
If blnEmptySpc = True Then
MsgBox ("There is a space located in Space
No. " & j)
If j > 1 Then
strLeft = Left(strNuMain, i - 1)
Else
strLeft = ""
End If
'
MsgBox "Now leaving ..strLeft = null.. End
If ..."
'
'MsgBox strLeft
'
lStrRtInverter = lstrNuMain - i
j = i - 1
strRt = Right(strNuMain, lStrRtInverter)
'MsgBox strRt
strNuMain = strLeft & strRt
'Length of each string
lstrNuMain = Len(strNuMain)
lstrLeft = Len(strLeft)
lstrRt = Len(strRt)
End If
MsgBox "Now leaving ..Bottom of loop..."
MsgboxFn
Loop
End Sub