返回列表 上一主題 發帖

[發問] 請問,Function中,由固定儲存格改為變數儲存格問題?

回復 1# yoya
但是當我把它改為變數之後,系統就讀不到我的下單字串。

可以啊,
  1. Option Explicit
  2. Sub Ex()
  3.     Dim A As String, B As Boolean
  4.     '程式中使用函數 有參數給參數,沒參數不用給
  5.      Sheet1.Cells(1, 2) = "S"
  6.     A = GetOrderText("第一個參數OrderStock的字串", "第二個參數OrderPrice的字串")
  7.     B = Test_Function
  8.     MsgBox A
  9.     MsgBox B
  10.     Sheet1.Cells(1, 2) = "s"
  11.     MsgBox GetOrderText("第一個參數OrderStock的字串", "第二個參數OrderPrice的字串")
  12.     MsgBox Test_Function
  13. End Sub
  14. Function Test_Function() As Boolean
  15.     If Sheet1.Cells(1, 2) = "S" Then Test_Function = True
  16. End Function

  17. Public Function GetOrderText(OrderStock As String, OrderPrice As String)
  18.     GetOrderText = "GetOrderText ???"
  19.     If Sheet1.Cells(1, 2) = "S" Then
  20.         GetOrderText = "Account=" & Sheet1.Cells(3, 2) & ",ProductID=" & OrderStock & ",TradeType=" & Sheet1.Cells(6, 2) & ", TradeKind=" & Sheet1.Cells(7, 2) & ", OrderType=" & Sheet1.Cells(8, 2) & ", BuySell=" & Sheet1.Cells(9, 2) & ", Qty=" & Sheet1.Cells(10, 2) & ", Price=" & OrderPrice & ", OrderNo=" & Sheet1.Cells(12, 2) & ", TradeDate=" & Sheet1.Cells(13, 2) & ", BasketNo=" & Sheet1.Cells(14, 2)
  21.     End If
  22. End Function
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 要批評別人時,先想想自己是否完美無缺。
返回列表 上一主題