返回列表 上一主題 發帖

困惑的變數

困惑的變數

本帖最後由 GBKEE 於 2011-7-7 08:39 編輯

煩請各位指導一下,為何第3個答案會是no?
以及要如何做才得到正解yes?

homeFD1 = "D:\aaa\"

i = 1

If homeFD1 = "D:\aaa\" Then        '當然是yes....
  MsgBox ("yes")
Else
  MsgBox ("no")
End If

If "homeFD" & i = "homeFD1" Then        '答案是yes
  MsgBox ("yes")
Else
  MsgBox ("no")
End If

If "homeFD" & i = "D:\aaa\" Then          '答案是no  MsgBox ("yes")
Else
  MsgBox ("no")
End If
請多指教

homeFD1 = "D:\aaa\"
這個homeFD1是變數
"homeFD"用雙引號括起來是字符
不能混為一談!

TOP

Sheets(i) 這類用法...用慣了 所以熊熊卡住...

另 "homeFD"用雙引號括起來是字符
但曾試用
mySER = "homeFD" & i
MsgBox (mySER)                    '答案..... homeFD1 依然不會是  "D:\aaa\"
請多指教

TOP

Dim homeFD(1 To 10)
homeFD(1) = "D:\aaa\"
i = 1
If homeFD(i) = "D:\aaa\" Then
  MsgBox ("yes")
Else
  MsgBox ("no")
End If
My Blog
http://blog.xuite.net/a8350070

TOP

回復 3# stephen
homeFD ="D:\aaa\"
mySER =homeFD & i
MsgBox  mySER                   請問答案.是....

TOP

本帖最後由 GBKEE 於 2011-7-7 10:26 編輯

回復 5# GBKEE
答案是  homeFD1
另,a8350070 謝謝啦~ 正解~Dim homeFD(1 To 10)



再試試看GBKEE上
  1. Sub Ex()
  2. Dim homeFD, I, mySER
  3. homeFD = "D:\aaa\"
  4. mySER = homeFD & I
  5. MsgBox mySER        
  6.   '          請問答案.是....
  7. End Sub
複製代碼
請多指教

TOP

        靜思自在 : 為自己找藉口的人永遠不會進步。
返回列表 上一主題