(公司里不能装VB,所以只能用VBA来表示)
Private Sub CommandButton1_Click()
Dim PostionX(12), PostionY(12) As Byte
Dim i As Integer
Dim V, H As Long
V = Val(TextBox6.Text)
H = Val(TextBox7.Text)'定义点坐标
'1
PostionX(0) = 10
PostionY(0) = 10
'2
PostionX(1) = V / 2
PostionY(1) = 10
'3
PostionX(2) = V - 10
PostionY(2) = 10
'4
PostionX(3) = V / 4
PostionY(3) = H / 4
'5
PostionX(4) = V * 3 / 4
PostionY(4) = H / 4
'6
PostionX(5) = 10
PostionY(5) = H / 2
'7
PostionX(6) = V / 2
PostionY(6) = H / 2
'8
PostionX(7) = V - 10
PostionY(7) = H / 2
'9
PostionX(8) = V / 4
PostionY(8) = H * 3 / 4
'10
PostionX(9) = V * 3 / 4
PostionY(9) = H * 3 / 4
'11
PostionX(10) = 10
PostionY(10) = H - 10
'12
PostionX(11) = V / 2
PostionY(11) = H - 10
'13
PostionX(12) = V - 10
PostionY(12) = H - 10
Open "D:\hua.ts" For Append As #1
For i = 0 To 12Write #1, PostionX(i), PostionY(i)
Next iClose #1
End SubPrivate Sub CommandButton2_Click()
Unload Me
End Sub
如何使输出的PostionX,PostionY的值小数点后有4位?

解决方案 »

  1.   

    使用format()函数进行格式化例如pi=3.14,则format(pi,"00.000")得到3.1400format具体用法请参看msdn
      

  2.   


    同意楼上。
    如果楼主需要Format()函数的详细介绍,我可以提供。
      

  3.   

    Private Sub CommandButton1_Click()
    Dim PostionX(12) As Byte
    Dim PostionY(12) As ByteDim i As Integer
    Dim V As Long
    Dim H As Long
    Dim X1 As Long
    Dim Y2 As LongV = Format(TextBox6.Text, "0.000")
    H = Format(TextBox7.Text, "0.000")
    TextBox3.Text = Format(V * 3 / 4, "0.000")'定义点坐标
    '1
    PostionX(0) = Format(10, "0.000")
    PostionY(0) = Format(10, "0.000")
    '2
    PostionX(1) = V / 2
    PostionY(1) = Format(10, "0.000")
    '3
    PostionX(2) = V - 10
    PostionY(2) = Format(10, "0.000")
    '4
    PostionX(3) = V / 4
    PostionY(3) = H / 4
    '5
    PostionX(4) = Format(V * 3 / 4, "0.000")
    PostionY(4) = Format(H / 4, "0.000")
    '6
    PostionX(5) = Format(10, "0.000")
    PostionY(5) = H / 2
    '7
    PostionX(6) = V / 2
    PostionY(6) = H / 2
    '8
    PostionX(7) = V - 10
    PostionY(7) = H / 2
    '9
    PostionX(8) = V / 4
    PostionY(8) = H * 3 / 4
    '10
    PostionX(9) = V * 3 / 4
    PostionY(9) = H * 3 / 4
    '11
    PostionX(10) = Format(10, "0.000")
    PostionY(10) = H - 10
    '12
    PostionX(11) = V / 2
    PostionY(11) = H - 10
    '13
    PostionX(12) = V - 10
    PostionY(12) = H - 10
    Open "D:\hua.ts" For Append As #1
    For i = 0 To 12Write #1, PostionX(i), PostionY(i)
    Next iClose #1
    "hua.ts"  中的结果为:
    10,10
    56,10
    101,10
    28,53
    83,53
    10,106
    56,106
    101,106
    28,158
    83,158
    10,201
    56,201
    101,201
    并不是: 0.000格式?不知道哪里出了问题.....
      

  4.   

    Dim PostionX(12) As Single
    Dim PostionY(12) As Single 
    Private Sub Command1_Click()
        PostionX(12) = 1234354 * 3 / 666
        MsgBox Format(PostionX(12), "#,0.0000")
    End Sub
      

  5.   

    看来错误是在  PostionX,PostionY定义上
    应该为Single.而不是Byte
      

  6.   


    没注意到这个变量的类型 ^_^只有用Single或Double类型的,才能保留小数部分。