473,414 Members | 1,757 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,414 software developers and data experts.

How to create/open a file on button click

I'm new to programing in Visual Basic, but what im wondering is, how can i open a file and create a file by clicking a button?
Like when i click button 1 it creates a file (to desktop) and when i click another button it opens a specific file(declared in code)
Could anyone help? Thanks in advance
Apr 15 '07 #1
2 4132
devonknows
137 100+
I'm new to programing in Visual Basic, but what im wondering is, how can i open a file and create a file by clicking a button?
Like when i click button 1 it creates a file (to desktop) and when i click another button it opens a specific file(declared in code)
Could anyone help? Thanks in advance
I believe That something along these lines can help you, This allows you to use something like

Expand|Select|Wrap|Line Numbers
  1. Call SetFileContents(App.Path & "\MyFileName.txt", "This Is My Content")
that will create a file called MyFileName.txt, and write This Is My Content to the file. And it all depends on what you want to do with the file that you have created, wether you want to use it as a temp file to store vars to, or just to make a program think that there is somehting there... etc etc.. its a bit like recycling... the possibilities are endless :P lol But i hope this helps you out...
Expand|Select|Wrap|Line Numbers
  1. Public Sub SetFileContents(ByVal file_name As String, ByVal contents As String)
  2. Dim fnum As Integer
  3.  
  4.     ' Open the file.
  5.     fnum = FreeFile
  6.     Open file_name For Output As fnum
  7.  
  8.     ' Write the file's contents (without an
  9.     ' extra trailing vbCrLf).
  10.     Print #fnum, contents;
  11.  
  12.     ' Close the file.
  13.     Close fnum
  14. End Sub
Kind Regards
Devon.
Apr 15 '07 #2
Killer42
8,435 Expert 8TB
I'm new to programing in Visual Basic, but what im wondering is, how can i open a file and create a file by clicking a button?
Like when i click button 1 it creates a file (to desktop) and when i click another button it opens a specific file(declared in code)
Could anyone help? Thanks in advance
You would place code in the button's Click event procuedure to use either FileSystemObject or the simpler (but less useful) Open/Print/Close statements.

For details on how to use these specific parts of the language, check your documentation or look up a good beginner VB tutorial - there are lots of them around, and you can use the Search tool on this page. Just try key words like "VB tutorial" and so on.
Apr 15 '07 #3

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
3
by: sanghavi | last post by:
how to create a set up project in vb.net..how to run an application on a different machine
17
by: DeZZar | last post by:
Hi all, I need to regularly backup my database as an Excel file and have been using the File Export option. Problem is I need anyone using the database to be able to do this easily - nopt...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
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
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...

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.