473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

loading a notepad file (.txt) to a listbox

8 New Member
i have a notepad file which is C:/Students.txt and i want the file to open up into a listbox on VB. is there any way i can do that?

This is what i have so far, but i recieve an error saying "Type Mismatch" does anyone know what im doing wrong? if so please help me correct it!

---------------------------
Dim List As String <<Declaration
-----------------------------
Open "C:\students.txt" For Input As #1
Input #1, List
StudentList.ListIndex = List
Jun 11 '07 #1
4 2446
Microchip
4 New Member
i have a notepad file which is C:/Students.txt and i want the file to open up into a listbox on VB. is there any way i can do that?

This is what i have so far, but i recieve an error saying "Type Mismatch" does anyone know what im doing wrong? if so please help me correct it!

---------------------------
Dim List As String <<Declaration
-----------------------------
Open "C:\students.txt" For Input As #1
Input #1, List
StudentList.ListIndex = List
ListIndex is a NUMBER. List is defined a s a string. Hence your type mismatch.

You may wish to use the AddItem method.
Jun 13 '07 #2
debasisdas
8,127 Recognized Expert Expert
Read the file line by line and add it to the listbox using ADDITEM method.

But if u want to displat tthe content of text file in a control , rich textbox control would be a better option for you.
Jun 13 '07 #3
ansumansahu
149 New Member
Read the file line by line and add it to the listbox using ADDITEM method.

But if u want to displat tthe content of text file in a control , rich textbox control would be a better option for you.
Hi ,

Yes debasis is correct. If you just want to display the content of the file go for a rich text box control. What is the purpose of using the list box?? Do you have a specific requirement.

-ansuman sahu
Jun 13 '07 #4
ajusingh222
3 New Member
Option Explicit

Private Sub Form_Load()
dlgOpenFile.InitDir = App.Path
dlgOpenFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
dlgOpenFile.FilterIndex = 1
dlgOpenFile.DialogTitle = "Open File"
dlgOpenFile.Flags = _
cdlOFNFileMustExist + _
cdlOFNHideReadOnly + _
cdlOFNLongNames + _
cdlOFNExplorer
dlgOpenFile.CancelError = True
End Sub

Private Sub Form_Resize()
txtFile.Move 0, 0, ScaleWidth, ScaleHeight
End Sub


Private Sub mnuFileExit_Click()
Unload Me
End Sub

Private Sub mnuFileOpen_Click()
Dim fnum As Integer

On Error Resume Next
dlgOpenFile.ShowOpen
If Err.Number = cdlCancel Then
' The user canceled.
Exit Sub
ElseIf Err.Number <> 0 Then
' Unknown error.
MsgBox "Error " & Format$(Err.Number) & _
" selecting file." & vbCrLf & _
Err.Description
Exit Sub
End If
On Error GoTo 0

' Read the file.
fnum = FreeFile
Open dlgOpenFile.FileName For Input As #fnum
txtFile.Text = Input$(LOF(fnum), fnum)
Close #fnum
End Sub
Jun 29 '07 #5

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

Similar topics

6
14305
by: Christian Giordano | last post by:
Hi guys, does anyone knows which are the functions I've to use to create a file, in this case a txt or a csv, that will be asked in runtime to the user to download it? So I suppose without creating...
3
1440
by: hirenshah.05 | last post by:
Hi, I am having lots of records in *.txt format. I want to extract some of data from notepad file and arrange it in a tabular form, so i can use it in MS-Access. I just want to know will i be...
9
2995
by: Sandy | last post by:
can mfc application, send text data to opened notepad file in desktop?(live transfer of data) . can anybody help
21
12935
by: Sender | last post by:
I have two questions: (1) I just want to check whether a .txt file is empty or not (without opening it). Like I click on a command button then it should give message EMPTY if is empty and show...
7
13153
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. I would like a command button in VB.Net 2002 to open a text file, then to allow text from a textbox on the current form...
2
11135
by: Suma | last post by:
Hi To open a notepad file, right now I am using Process.start. But this does not ensure that the file is opened in readonly mode How can I make a notepad file open in Readonly mode I do not...
5
2215
by: Bill Q | last post by:
Hello, this may not be the correct group for the post although I am using c# to follow one of the code4fun directx tutorial. Anyway the author is loading a texture file using the following ...
3
2469
by: Learning.Net | last post by:
How to read a Unicode data saved as ASCII in notepad file as txt ? I tried using streamReader but it is not showing Unicode data. eg. using (StreamReader sr = new StreamReader(test.txt) {...
0
1344
by: wez03 | last post by:
Hi everyone.. I got a problem in loading an external txt into my dynamic text. It says that there are no error in my script but when I publish it, the only thing seen in the text field is...
0
7027
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
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6719
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
5312
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,...
0
2980
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
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.