473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ 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.tx t" For Input As #1
Input #1, List
StudentList.Lis tIndex = List
Jun 11 '07 #1
4 2453
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.tx t" For Input As #1
Input #1, List
StudentList.Lis tIndex = 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.Ini tDir = App.Path
dlgOpenFile.Fil ter = "Text Files (*.txt)|*.txt|A ll Files (*.*)|*.*"
dlgOpenFile.Fil terIndex = 1
dlgOpenFile.Dia logTitle = "Open File"
dlgOpenFile.Fla gs = _
cdlOFNFileMustE xist + _
cdlOFNHideReadO nly + _
cdlOFNLongNames + _
cdlOFNExplorer
dlgOpenFile.Can celError = True
End Sub

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


Private Sub mnuFileExit_Cli ck()
Unload Me
End Sub

Private Sub mnuFileOpen_Cli ck()
Dim fnum As Integer

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

' Read the file.
fnum = FreeFile
Open dlgOpenFile.Fil eName 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
14323
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 any file on the server. Something like the dump in phpmyadmin when we choose to save as. Thx a lot, chr -- ___________________________________________________________________ { Christian Giordano's site and blog @ http://cgws.nuthinking.com }
3
1446
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 able to do it directly in MS-Access, or I need some program at backhand. And if I need a program can anyone suggest which language will be better. As I have not use MS-Access i don't any idea about features of MS Access. ok bye
9
3020
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
12950
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 message "NON EMPTY" if it is not empty. (2) What are the steps to open a notepad file (C:\XYZ\abc.txt) in a VB Text Box. Thanks
7
13175
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 to be appended to that text file. Is there a place where I can see code to do this? I have the data/text on the clipboard using the clipboard class, now I want to append it to the text file either in Notepad or Wordpad. I have tried using the...
2
11152
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 want to change its attributes to Readonly I do not want to open it in browser or in any other editor except notepad I do not want to use MFCAppWizard of VC++ or VB to create my own editor. I do not want to paste the text in some richtextbox...
5
2223
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 TextureLoader.FromFile ( _device, @"..\..\..\Resources\Left.tga" I am not sure what the ..\..\..\ means when loading the file. I know the directory the file lives in is C:\Documents and Settings\Bill\My Documents\MSDN\BattleTank2005 (C#)\Resources
3
2479
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) { string line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) {
0
1356
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 'undefined'. My external txt was not loaded. I can't figure out what's the problem with my code: mytext1_btn.onRelease = function (){ myData = new LoadVars(); myData.onLoad = function() { myText_txt.text = this.myVariable; };...
0
7877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8009
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8240
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6661
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5411
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
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 we have to send another system
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.