| |

VerySource

 Forgot password?
 Register
Search
View: 705|Reply: 2

How to read and write values ​​in a text file in VB

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-5 19:30:01
| Show all posts |Read mode
Ask: How to read and write values ​​in text files in VB
Reply

Use magic Report

0

Threads

2

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-6 12:24:28
| Show all posts
Private Sub Command1_Click () 'Import from root to text
    Open App.Path&"\123.txt" For Binary As # 1
    Text1.Text = Input (LOF (1), 1)
    Close # 1
End Sub

Private Sub Command2_Click () 'Import from root to list
    Dim a As String
    Open App.Path&"\123.txt" For Binary As # 1
    a = Input (LOF (1), 1)
    Close # 1
    '------------------------------------------- Import variables
    List1.Clear
    Dim b () As String
    Dim c As Integer
    b = Split (a, vbCrLf)
    For c = LBound (b) To UBound (b)
        List1.AddItem b (c)
    Next c
    '------------------------------------------- Branch Import
End Sub

Private Sub Command3_Click () 'Text import to list
    List1.Clear
    Dim b () As String
    Dim c As Integer
    b = Split (Text1.Text, vbCrLf)
    For c = LBound (b) To UBound (b)
        List1.AddItem b (c)
    Next c
End Sub

Private Sub Command4_Click () 'list import to Text
    Dim a As Integer
    Dim b As String
    For a = 0 To List1.ListCount-1
        b = b&List1.List (a)&vbCrLf
    Next a
    Text1.Text = b
End Sub
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-5-21 17:15:01
| Show all posts
Dim n1, n2, n3 'test
Private Sub Form_Load () 'read points
If Dir ("c:\a.txt") = "" Then Exit Sub
Open "c:\a.txt" For Input As 1
Input # 1, n1, n2, n3
Close
Text1 = n1: Text2 = n2: Text3 = n3
End Sub

Private Sub Form_Unload (Cancel As Integer) '
Open "c:\a.txt" For Output As 1
Write # 1, Text1, Text2, Text3
Close
End Sub
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list