Jump to content

Hi,

I'm currently using VB.net, on Microsoft Visual Basic 2010 Express, to create a program for a small business, as a school project

In a form named MainUI, and I'm trying to display a text file in a multiline textbox named notes, I want the user to be able to read what is in the textfile and edit the contents through the same textbox with a button underneath named savetext. However I am unable to make this work and am wondering if anyone could help me or direct me to a webpage that already has an explanation.

Thanks in advance

WaspishVyper

Link to comment
https://linustechtips.com/topic/7003-vbnet-help/
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Hi Im doing the exact same thing!! What business are you doing? I've gone with a hotel.

Saving a file is easy you need to open one first

FileOpen(1, filedirectory, openmode.random, , , filesize)

if you make a random access file you get more marks - so my teacher said anyway :)

the saving is fileput (1, structurename, len(structure)

1 is just a file reference :)

Link to comment
https://linustechtips.com/topic/7003-vbnet-help/#findComment-91523
Share on other sites

Link to post
Share on other sites

Hi Im doing the exact same thing!! What business are you doing? I've gone with a hotel.

Saving a file is easy you need to open one first

FileOpen(1, filedirectory, openmode.random, , , filesize)

if you make a random access file you get more marks - so my teacher said anyway :)

the saving is fileput (1, structurename, len(structure)

1 is just a file reference :)

Thanks for the help, I'm doing it for a bunch of PHD students that work for my mum
Link to comment
https://linustechtips.com/topic/7003-vbnet-help/#findComment-102841
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...

To read in the text file:

Dim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt")MsgBox(fileReader)

To then write the text file out, add a save button and in the event handler put

My.Computer.FileSystem.WriteAllText("C:\test.txt", VariableContainingTheUsersText,True)

A better way of doing this

 

Firstly right at the top, before your form definition, Put the following line

Imports System.Environment

Like so:

WnnBpyK.png

 

As to where to write your text file, To maintain compatibility with Windows 8 I suggest writing to %appdata% like this (All of the below code goes in an event handler like OnClick

        Dim appData As String = GetFolderPath(SpecialFolder.ApplicationData)        Dim fileName As String = appData & "\test.txt"        My.Computer.FileSystem.WriteAllText(fileName, VariableContainingTheUsersText,True)

Current rig: AMD Piledriver fx-8320 OC'd to 4.9ghz on 1.45v vcore | Asus Sabertooth 990fx r2 board | Gigabyte 7950 W3x| 8GB Corsair XMS3 1333mhz | 240GB OCZ Agility 3 SSD

Link to comment
https://linustechtips.com/topic/7003-vbnet-help/#findComment-119839
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×