I am having a situation in which I need to clear
the variable lastWord
so that msgbox
show nothing in next loop
.
Following code is just an Example.
Sub clear_lastWord_Variable()
Dim wordArr() As String
Dim lastword As String
Do
selection.Find.ClearFormatting
selection.Find.Font.Bold = True
With selection.Find
.Forward = True
.Wrap = wdFindStop
End With
selection.Find.Execute
If selection.Find.Found Then
wordArr = Split(selection, " ")
For i = LBound(wordArr) To UBound(wordArr) Step 1
lastword = wordArr(i)
Next i
MsgBox lastword
' here should be something to clear lastword
Else
Exit Do
End If
Loop
End Sub
To delete a variable, along with its value, use Remove-Variable or Remove-Item . This cmdlet does not delete the values of variables that are set as constants or owned by the system, even if you use the Force parameter. If the variable that you are clearing does not exist, the cmdlet has no effect.
Remarks. When executed, the End statement resets all module-level variables and all static local variables in all modules. To preserve the value of these variables, use the Stop statement instead. You can then resume execution while preserving the value of those variables.
You can't "clear" a non-object variable, you can only set it to a defined value. For a string variable, that's usually the empty string "" . For object variables, there is Set myObj = Nothing . Please look below, VARIANT type variable can be set to EMPTY and then checked by IsEmpty() function.
C++ String clear() This function removes the elements, becomes an empty string.
You can't "clear" a non-object variable, you can only set it to a defined value. For a string variable, that's usually the empty string ""
.
lastword = ""
or (identical)
lastword = vbNullString
For object variables, there is Set myObj = Nothing
.
If your variable is not an object you can also do:
lastword = Empty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With