重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'自定义一个函数:功能是给小数直接进一位
从事多线服务器托管,服务器租用,云主机,虚拟主机,主机域名,CDN,网络代维等服务。
'num 要操作的小数
'n 保留几位小数,
Function getNumber(num As Double, n As Integer) As Double
Dim a As Double
a = Int(num * (10 ^ n)) / (10 ^ n)
If a = num Then
getNumber = a
Else
getNumber = a + 1 / (10 ^ n)
End If
End Function
-------------------------
调用一下:
Private Sub Command1_Click()
MsgBox (getNumber(3.1415926, 2))
End Sub
得到3.15
在VB中是这样的,没学过VB点虐 ,你变换一下就可以了
Option
Explicit
Private
Sub
Command1_Click()
Dim
Num(2)
Num(0)
=
Val(Left(Label1.Caption,
2))
Num(1)
=
Val(Mid(Label1.Caption,
3,
1))
Num(2)
=
Val(Right(Label1.Caption,
2))
MsgBox
"Num(0)="
Num(0)
vbCrLf
"Num(1)="
Num(1)
vbCrLf
"Num(2)="
Num(2)
'如果想测试是不是可以计算,可以用这一句
'MsgBox
"Num(0)+1="
Num(0)
+
1
vbCrLf
"Num(1)+1="
Num(1)
+
1
vbCrLf
"Num(2)+1="
Num(2)
+
1
End
Sub
Private
Sub
Form_Load()
Label1.Caption
=
"12345"
End
Sub
用字符串保存两个数据,当然只有你这种办法,另外提供你其它思路:
1. flexcell增加两列,这两列隐藏不显示,额外数据可以从这两列读取
2. 用自定义类型数组,保存这两列数据,数组顺序和表格一样,或者数组中增加一个ID元素,与表格对应
Dim num As Integer
Dim connstr, insertcmd, selectcmd As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\360data\重要数据\我的文档\hd.mdb"
Dim conn As OleDbConnection
Dim cmd, cmd1 As OleDbCommand
conn = New OleDbConnection(connstr)
Dim r As OleDbDataReader
conn.Open()
insertcmd = "insert into returnbooks (aid,aname,ISBN,bname,renum,reday) values("
Val(ComboBox1.Text) ",'"
TextBox2.Text "','"
ComboBox2.Text "','"
TextBox2.Text "',"
Val(TextBox3.Text) ",'"
CType(TextBox4.Text, Date) "' )"
cmd = New OleDbCommand(insertcmd, conn)
cmd.ExecuteNonQuery()
updatecmd = "update books set remainnum=" Val(num) "-" Val(TextBox3.Text) " where ISBN='" ComboBox2.Text "'"
cmd = New OleDbCommand(updatecmd, conn)
cmd.ExecuteNonQuery()
updatecmd = "select remainnum as num from books where ISBN= '" ComboBox2.Text "'"
cmd = New OleDbCommand(updatecmd, conn)
cmd.ExecuteNonQuery()
updatecom = "update books set remainnum=num+ " Val(TextBox3.Text) ""
cmd = New OleDbCommand(updatecmd, conn)
cmd.ExecuteNonQuery()
selectcmd = "select remainnum from books where ISBN='" ComboBox2.Text "'"
cmd1 = New OleDbCommand(selectcmd, conn)
r = cmd1.ExecuteReader()
If (r.Read()) Then '如果sql查询到了数据
num = r.GetInt32(0)
End If
conn.Close()
/*注意代码的格式,不然改起来太费时间*/