无法将值从单元格分配给变量

时间:2019-04-04 18:46:26

标签: excel vba types decimal

由于某种原因,我的变量被分配了看似错误的结果。

to generaRed

  set numpoints number
  set onlist (list points)
  set xlist [xcor] of points
  set ylist [ycor] of points
  set vallist [value] of points

  set onlist fput false onlist
  set xlist fput 0 xlist
  set ylist fput 0 ylist
  set vallist fput 0 vallist
  clear-drawing

  if max xlist > max-pxcor - 1 or max ylist > max-pycor - 1 or min xlist < min-pxcor + 1 or min ylist < min-pycor + 1
     [user-message "One or more coordinate values are outside the screen range.  Please check your inputs and setup again"
      stop]

  ask points [ die ]

  ( foreach xlist ylist vallist [
    [ x y v ] ->
    create-points 1 [
      setxy x y
      set value v
      set super? false
      set hidden? false
      face patch 0 0
      set size 10
    ]
    ]
    )
  ask points with [not hidden?] [if distance min-one-of other points with [not hidden?] [distance myself] = 0
    [user-message "Two or more active points have identical coordinates.  Please halt, revise your inputs and setup again" stop]]
  create-points 1 [set hidden? true set super? true setxy (min-pxcor + 1) (min-pycor + 1)] ; who numpoints + 1
  create-points 1 [set hidden? true set super? true setxy (min-pxcor + 1) (max-pycor - 1)] ; who numpoints + 2
  create-points 1 [set hidden? true set super? true setxy (max-pxcor - 1) (max-pycor - 1)] ; who numpoints + 3
  create-points 1 [set hidden? true set super? true setxy (max-pxcor - 1) (min-pycor + 1)] ; who numpoints + 4
end
  • 预期结果:public E0m1 as long Set DD = Workbooks("correct path") DD.Activate E0m1 = DD.Range("B36").Value '(cell value is 0.5)
  • 我得到的是:E0m1 = 0.5

1 个答案:

答案 0 :(得分:2)

Long 数据类型不支持浮点运算 (十进制数字)

如果您想存储十进制数字(例如,将0.5存储到变量中),请将其存储到一个

Double可以包含更大,更精确的数字,但是从您提供的数据的外观来看,Single就足够了。另外,作为补充说明:

如果要声明变量,除非出于某种原因要使它们成为全局变量,否则最好使用Dim关键字声明它们。

例如

Dim e0m1 as Single
Dim ws as Worksheet: Set ws = Sheets("correct path")
e0m1 = ws.Range("B36")
相关问题