作者UniFish (闪光鱼)
看板Visual_Basic
标题Re: [VB6 ]字串转数值的问题
时间Mon Jun 22 23:12:14 2009
我的做法是这样...
Dim Str_Key As String = " "←可以代任何东西
If Mid(Str_Temp, Str_Temp.Length, 1) <> Str_Key Then Str_Temp += Str_Key
'没有这行的话,它会在最後一笔出现错误
While Str_Temp <> Nothing
Dim Position As Integer = InStr(Str_Temp, Str_Key)
Dim Str_Result As String = Mid(Str_Temp, 1, Position - 1)
Str_Temp = Mid(Str_Temp, Position + 1, Str_Temp.Length - (Position))
Print Str_Result
End While
※ 引述《resc (>.<)》之铭言:
: 请问一下各位大大
: 如果我用开档案的方式去抓字串
: 抓出来的字串要转成Intrger或是Double
: (比较想用Double来写,因为有的数值小数点後有10位数)
: 然後字串中一共有四个数值 0.160771704 0 2.8 6.0
: ^^^^^^^^^^^ ^ ^^^ ^^^
: 1 2 3 4 <--数值的顺序
: 每个数值间都有一个空白键的存在
: 我想用a、b、c、d分别代表字串转成数值後的四个数值
: 我该怎麽写成程式码呢?
: 我的程式码如下:
: Private Sub MacroWorkshop()
: Dim tempstr As String
: Dim numStr As String
: Dim str As String
: Dim pp As String
: Dim ii As Integer
: Dim anum As Double
: Dim bnum As Double
: Open "E:\\test\\testfile.txt" For Input As #1 <---开档的路径
: While Not EOF(1)
: Line Input #1, tempstr
: str = tempstr
: Debug.Print str
: For ii = 1 To 3 <----回圈要读数值的 前三个数值可在这显示
: pp = InStr(str, " ")
: numStr = Trim(Left(str, pp)) <--删除空白
: Debug.Print numStr
: 'anum = Val(numStr) <----这行是想将字串转成数值
: 'Debug.Print anum
: str = Trim(Right(str, Len(str) - pp))
: Next
: Debug.Print str <-----显示第四个数值
: 'bnum = Val(str)
: Wend
: Close
: End Sub
: 如果我的字串有很多个(100个以上)
: 然後要将跑过回圈後的字串转换成数值再指定到a、b、c、d上
: 跑过後的字串要删除掉
: 然後继续读下个字串一直到将字串读完为止
: 请问一下我该怎麽写呢?
: 可以麻烦会的大大回答我一下吗?
: 拜托各位了
: 谢谢
--
◣◥
◤◢ ◣▁◢ 请‧尊‧重‧生‧命
◤
◢◤ ‧‧▏ ◥ ◤
以 认 养 代 替 购 买
◤◢ ▄▄▄▄ ‧‧
◢◤ 请领养我 ▄ ▄ 以 绝 育 代 替 扑 杀
◤◢ 请领养我▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
ψQSWEET
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.40.148.28
1F:推 resc:谢谢大大的提示 我会再试试看 谢谢 06/23 10:31