Link to home
Start Free TrialLog in
Avatar of Skale
Skale

asked on

Reading txt(ASCII) file by row index and assign them to controls in vb.net

I've text file like below and i'd like to read them by row number and assign their values automatically to Windos Form textbox control.

How is it possible to read specific rows (in my file desired values' row index is 2,5,8,11...) and assign their value to my application's textbox.

######## Log File for RBE2 elements (Be careful to have write permission to folder, file names are not important)
C:\Users\USER1\Desktop\Sample_BIF\condensRun_13042019\test4.log

######## Log File copy for RBE2 elements(Be careful to have write permission to folder, file names are not important)
C:\Users\USER1\Desktop\Sample_BIF\condensRun_13042019\test4_copy.log

######## Excel file to get set id to delete
C:\Users\USER1\Desktop\Sample_BIF\condensRun_13042019\input_condensationPrep.xlsx

######## Excel file sheet number
1

######## Column for Delete?
3

######## Column for Set ID
4

######## First Row of SetIDs (Source)
2

######## Last row of SetIDs (Source)
12

######## Sleep Time
10000

######## Column for Leaf Spring Property ID
6

######## Column for Reference Nodes
7

######## Column for Interface Nodes
8

######## BUSHING STARTS - Changed node number start. This number will be the start point while renumbering
12001

######## Bush properties K1
150000

######## Bush properties K2
200000

######## Bush properties K3
300000

######## Bush properties K4
400000

######## Bush properties K5
500000

######## Bush properties K6
600000

######## Bush property ID
120

######## Bush element ID start
30001

######## Fig file to open
C:\Users\USER1\Desktop\Sample_BIF\condensRun_13042019\test.fig

Open in new window

Avatar of ste5an
ste5an
Flag of Germany image

I must ask: What is your use-case?

Is this a kind of configuration file? Then you should use XML or better the app.config of your program.

Otherwise its something like:

Dim reader as StreamReader = My.Computer.FileSystem.OpenTextFileReader(f"iletoimport")
Dim lineContent as String
Dim lineCount as Integer

Do
  lineCount = lineCount + 1
  lineContent = reader.ReadLine   
  Select Case lineCount
  Case Is = 2
    txtApplicationTextBox.Value = txtApplicationTextBox.Value + lineContent
  Case Is = 5
    txtApplicationTextBox.Value = txtApplicationTextBox.Value + lineContent
  Case Is = 8
    txtApplicationTextBox.Value = txtApplicationTextBox.Value + lineContent
  Case Is = 11  
    txtApplicationTextBox.Value = txtApplicationTextBox.Value + lineContent
  End Select
Loop Until lineContent Is Nothing

reader.Close()

Open in new window

Avatar of Skale
Skale

ASKER

Yes you're right but this settings file not belongs to my application it's for editing 3rd part tool's settings file. I'll try your code and give feedback. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial