使用 VB 时出现错误 "Object variable not set"
Getting an error "Object variable not set" using VB
我正在尝试编写一个程序,它将删除 MsgBox 中单词的每个首字母。这是我的代码:
Sub Test
dim k as String
dim f as String
dim bd as String
k = inputbox("input text")
f = "inputed text:" & chr(9) & k & chr(13)
bd = bd + Split(mid(k,1,1))
for i = 2 to len(k)
if mid(k,i-1,1) = "" then bd = bd + Ucase(mid(k,i,1)) else bd = bd + mid(k,i,1)
next i
f = f & "result of work:" & chr(9) & bd
MsgBox f
End Sub
我在这里遇到错误:bd = bd + Split(mid(k,1,1))
如果要去除字符串中任何病房的首字母,请测试下一个代码:
Sub deleteFirstWdLett()
Dim x As String, i As Long, arr
x = "My dog has three houses" 'consider it the InputBox string
arr = Split(x)
For i = 0 To UBound(arr)
arr(i) = Mid(arr(i), 2)
Next
Debug.Print Join(arr, " ")
End Sub
如果单词只包含一个字母会怎样?是否应该将其删除,从而导致额外的空 space (如上所示)?代码应该跳过这种情况吗?我不明白这样做的原因,所以我无法想象你真正需要什么,从这个角度来看...
我正在尝试编写一个程序,它将删除 MsgBox 中单词的每个首字母。这是我的代码:
Sub Test
dim k as String
dim f as String
dim bd as String
k = inputbox("input text")
f = "inputed text:" & chr(9) & k & chr(13)
bd = bd + Split(mid(k,1,1))
for i = 2 to len(k)
if mid(k,i-1,1) = "" then bd = bd + Ucase(mid(k,i,1)) else bd = bd + mid(k,i,1)
next i
f = f & "result of work:" & chr(9) & bd
MsgBox f
End Sub
我在这里遇到错误:bd = bd + Split(mid(k,1,1))
如果要去除字符串中任何病房的首字母,请测试下一个代码:
Sub deleteFirstWdLett()
Dim x As String, i As Long, arr
x = "My dog has three houses" 'consider it the InputBox string
arr = Split(x)
For i = 0 To UBound(arr)
arr(i) = Mid(arr(i), 2)
Next
Debug.Print Join(arr, " ")
End Sub
如果单词只包含一个字母会怎样?是否应该将其删除,从而导致额外的空 space (如上所示)?代码应该跳过这种情况吗?我不明白这样做的原因,所以我无法想象你真正需要什么,从这个角度来看...