我想做一个计算文本里的数值的东西,也就是在一个文本里输入数值:
23
25
101.5
然后将这些书计算出来,希望高手指点两个问题:
1、我要是用vb的方法怎么解决,用open 打开文件,然后怎么办呀?
2、用sql查询能做,但是文本文件里没有字段,怎么用sql语句描述文本文件呀?指点一下吧,谢谢了
23
25
101.5
然后将这些书计算出来,希望高手指点两个问题:
1、我要是用vb的方法怎么解决,用open 打开文件,然后怎么办呀?
2、用sql查询能做,但是文本文件里没有字段,怎么用sql语句描述文本文件呀?指点一下吧,谢谢了
'bcp
dim strTmp As String
Open App.Path & "\test.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, strTmp ' 读入一行数据并将其赋予某变量。
lngSum = lngSum + Clng(strTmp)
Loop
Close #1 ' 关闭文件
dim dblSum As Double'和
dim strTmp As String
Open App.Path & "\test.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, strTmp ' 读入一行数据并将其赋予某变量。
Double = Double + Cdbl(strTmp)
Loop
Close #1 ' 关闭文件
dim dblSum As Double'和
dim strTmp As String
Open App.Path & "\test.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, strTmp ' 读入一行数据并将其赋予某变量。
dblSum = dblSum + Cdbl(strTmp)
Loop
Close #1 ' 关闭文件
用Round()函数限定小数位数
如Round(dblSum,2)保留两位小数
放进哪儿?
得到字符串,用CDbl强制转换为Double型就可以计算了,
或者CSng()强制转换为Single型
Private Sub Textlog(slog As String)
Dim hFile As Integer
Dim slogPath, stime As String
On Error Resume Next
slogPath = App.Path + "\" + "Textlog.txt"
hFile = FreeFile
Open slogPath For Append As #hFile
Print #hFile, slog
Close #hFile
End Sub您看能在这里做转换吗?让接收到的字符串转换成十进制的数值在写道text中
用CSng()强制转换为Single型怎么实现呀?