473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calling a file in text format in vb

Hie
how do you call a text file in vb using textbox and command button
Jul 29 '10 #1
3 1608
Guido Geurs
767 Expert 512MB
with Commondialog if You want to select a file=

Expand|Select|Wrap|Line Numbers
  1. Private Function Open_File()
  2. Dim STRTEMP As String
  3.    TextBox.Text = ""
  4.    On Error GoTo Cancel_Function
  5.    With CommonDialog
  6.       .CancelError = True
  7.       .Filter = "Text (.txt)|*.txt"
  8.       .InitDir = Environ$("USERPROFILE") & "\My Documents"
  9.       .DialogTitle = "Open a file..."
  10.       .ShowOpen
  11.       On Error GoTo Error_Open_File
  12.       Open .FileName For Input As #1
  13.          Do Until EOF(1)
  14.             Input #1, STRTEMP
  15.             TextBox.Text = TextBox.Text & STRTEMP
  16.          Loop
  17.       Close #1
  18.       Caption = Left(Caption, 26) & ": " & .FileName
  19.    End With
  20. Exit Function
  21. Error_Open_File:
  22.    Close #1
  23.    MsgBox "There is an error opening the file"
  24. Exit Function
  25. Cancel_Function:
  26. End Function
If the file is always the same=

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim FileIn As Integer
  3.    FileIn = FreeFile
  4.    On Error GoTo Error_Laden
  5.    Open App.Path & "\document.txt" For Input As #FileIn
  6.       Do While Not EOF(FileIn)
  7.          Input #FileIn, inputdata
  8.          TEXTBOX.text = TEXTBOX.text & inputdata & vbCrLf
  9.       Loop
  10.    Close #FileIn
  11. Exit Sub
  12. Error_Laden:
  13.    Close #FileIn
  14.    MsgBox ("Error loading !")
  15. End Sub
Jul 29 '10 #2
I'm trying to implement the "with Commondialog if You want to select a file" code in Word 2007 (SP2) and when I execute the code it chokes on 'TextBox.Text = ""' and I get error "424 Object Required." Any suggestions?

Thank you in advance.
Sep 29 '10 #3
Guido Geurs
767 Expert 512MB
I think You have to add a "Common Dialog Control" (see GIF) to Your document (see attachment)
Attached Images
File Type: gif Com Dialog.GIF (9.4 KB, 153 views)
Attached Files
File Type: zip Calling a file in text format in vb_v1.zip (12.4 KB, 49 views)
Sep 29 '10 #4

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

Similar topics

14
by: Christophe Cerbourg | last post by:
hi, Bonjour, I'm using PHPMailer class to send mails and it works fine for HTML ones. But I can't manage to send correctly a text formatted mail... I tried this : - $message = "first...
1
by: Pavan Jha | last post by:
Hi, I am using File Input for one of my pages. I have multiple inputs on my page as <INPUT Type=FILE Name=File1> <INPUT Type=FILE Name=File2> and so on... I have a function for validating...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
2
by: jakub.bauer | last post by:
Hi, I have a table with in MS SQL database. A table consist a list of items bought by a customer with, item prices, item nubers etc. I would like to send an email with a list of items in the...
2
by: Eshban Bahadur | last post by:
Hello, I want to read (RTF) files in my VB.NET programme. How can i do it. I apply the same method of reading text files, but it does not save the formatting of text like (bold, italics,...
1
by: svnlakshmi | last post by:
Pls help me out in this aspect--How to convert a binary file to a file in text format using C?
0
by: yoavyoavyoav | last post by:
Hi There, I have some serious issue - I have a .Net application that is generating various reports in CSV format and then fires up excel from code to view this file. The file is viewed...
4
by: Jeff | last post by:
Hey I'm wondering how the Fixed-Width Text Format is What I know is that the top line in this text format will contain column names. and each row beneath the top line represent for example a...
0
by: babai28 | last post by:
Hi All, I have a situation where I need to read an xml file in true text format for example When I read an attribute value in the xml Document using XmlReader and the value is "," I get "," as...
2
by: p4willi | last post by:
I have an unbound text box called Notes on a MS Access 2007 form with the Text Format property set to Rich Text. The underlying database has a Memo field called NOTES with it's property set to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.