473,503 Members | 12,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Visual Basic "Line By Line" text file.

2 New Member
Ok i am making program wicth has from txt file put lines from first to last.

well If i code it like this:
----
Expand|Select|Wrap|Line Numbers
  1. nFileNum = FreeFile
  2.  
  3. Open "C:/VB/VB.txt" For Input As nFileNum
  4.  
  5. FreeNum = 1
  6.  
  7.     While Not EOF(nFileNum)
  8.     Line Input #nFileNum, sData
  9.     Text1.Text = sData
  10.     Wend
  11.  
  12. Close #1
----
But then it only shows me the last line and if i do without EOF it only shows me first line. so Please help, whats wrong?
Feb 1 '07 #1
4 4135
Rabbit
12,516 Recognized Expert Moderator MVP
Ok i am making program wicth has from txt file put lines from first to last.

well If i code it like this:
----
nFileNum = FreeFile

Open "C:/VB/VB.txt" For Input As nFileNum

FreeNum = 1

While Not EOF(nFileNum)
Line Input #nFileNum, sData
Text1.Text = sData
Wend

Close #1
----
But then it only shows me the last line and if i do without EOF it only shows me first line. so Please help, whats wrong?
When you do Text1.Text = sData, whatever was in Text1.Text is replaced with whatever's in sData during each iteration of the loop.

What you want is Text1.Text = Text1.Text & chr(13) & sData.
This will take whatever is in Text1.Text, add a new line character chr(13), and then concatenate whatever's in sData.
Feb 1 '07 #2
Killer42
8,435 Recognized Expert Expert
When you do Text1.Text = sData, whatever was in Text1.Text is replaced with whatever's in sData during each iteration of the loop.

What you want is Text1.Text = Text1.Text & chr(13) & sData.
This will take whatever is in Text1.Text, add a new line character chr(13), and then concatenate whatever's in sData.
You're on the right path, but use vbNewline rather than Chr(13). Also, I think the textbox will need to have the Multiline property set to True.
Feb 2 '07 #3
Hexes
2 New Member
Hmm ok what ever let it be, but ok like i have text file... it has 20 lines, and into text1.text i want to put like line number 12, what I have to do?
Feb 2 '07 #4
iburyak
1,017 Recognized Expert Top Contributor
Dim Counter as integer

nFileNum = FreeFile

Open "C:/VB/VB.txt" For Input As nFileNum

FreeNum = 1

While Not EOF(nFileNum)
Line Input #nFileNum, sData
Counter = Counter + 1
IF Counter = 12 then Text1.Text = sData
Wend

Close #1
Feb 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1721
by: Jason Charalambides | last post by:
I have created this little routine to export the values of some variables. However there are two things I need to fix: 1. Instead of being on a line, I want them arranged one under another. 2. ...
2
1789
by: Andr? Roberge | last post by:
I want to "import and execute" a python program (input_test.py below) within another program (execute_test.py below) and "watch it" being executed. By watching it, I mean to display the file...
5
10787
by: Nathan Sokalski | last post by:
I have an ASP.NET application which is giving the following JavaScript error: 'theForm' is undefined However, when I do a View Source one of the <scriptelements is as follows: <script...
12
1579
by: Dom | last post by:
VB had a "line" control, just a simple line that let you separate controls without the wasted space of a Groupbox. Did CSharp drop this? Dom
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.