# VB函數-Split()

Open "C:\test3.txt" For Input As #1

Input #1, C

Open "C:\result3.txt" For Output As #2

Dim A(5), B(5), D(5), E(5) As Integer

A(1) = 2000

A(2) = 1000

A(3) = 500

A(4) = 200

A(5) = 100

For I = 1 To 5

B(I) = C \ A(I)

D(I) = A(I): E(I) = B(I)

C = C - A(I) * B(I)

TN = TN + B(I)

Next I

Write #2, TN

For I = 1 To 5

Write #2, D(I), E(I)

Next I

Close #2

Close #1

End Sub

9

2000,3

1000,2

500,1

200,2

100,1

9

2000　3

1000　2

500 　1

200 　2

100 　1

Update:

Litfal大大

Update 2:

Join

Update 3:

Print解決了

Update 4:

1 50 1

2 35 3

3 25 4

4 48 2

Split函數去讀取囉!!?

Rating
• litfal
Lv 5

把Write改用Print看看會不會是你要的結果

Print #2, D(I), E(I)

至於split的用法是...把含分隔符號的字串切成字串陣列，直接舉例

Dim s() As String

s = Split("56,22,,a,b", ",") '分隔符號是","

s = Split("56 22 a b", " ") '分隔符號是" "

上面兩條的結果是一樣的, 陣列基底設定以0開始的話

s(0) 會= "56"

s(1) 會= "22"

s(2) 會= "" ←因為22與a中間有兩個","

s(3) 會= "a"

s(4) 會= "b"

Split通常是在讀取時使用

寫入的話應該比較常用Join

2009-06-21 17:22:52 補充：

Join用法就跟Split相反，也就是把某陣列中每一項以某字串分隔串接，成為新的字串。

拿上面的s( )舉例

Dim s() As String

Dim A as String

s(0) = "56"

s(1) = "22"

s(2) = ""

s(3) = "a"

s(4) = "b"

A = Join( s , ",") 'A會 = "56,22,,a,b"

A = Join( s , " ") 'A會 = "56 22 a b"

你的問題很單純，根本也用不到Join

用 Print #2, (D(I) & " " & E(I))

做字串相加就好了

2009-06-22 05:47:17 補充：

沒錯

通常配合Line Input服用