InterviewSolution
| 1. |
Solve : Visual Basic 2008 Express? |
|
Answer» I'm a complete beginner on VB and I'm making my first little program. Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click How would I add the functionality to these buttons? you write the appropriate code there... what exactly will it "open"? First of all, the save button would save the text in the INPUT field. Then the Open button would open the text into the Input field. I'm thinking of using either .txt file extension or even a completely new one.I usually use StreamWriter/Reader for reading FILES: Add the OpenFileDialog component from the toolbar to the form and name it "diaOpenFile" Under the properties of "diaOpenFile" set the Filter property to: Text File|*.txt You can edit this later to set it for any file extension you want. Add this to the top of your code: Code: [Select]Imports System Imports System.IO I'll bring up the rest, just need to find the code.Ok, found the rest of the code. Add this to the top of your code: Code: [Select]Dim objFileRead as StreamReader Asumming you only have one textbox and are saving to one line of the file add this inside the Open Click Event that you PROVIDED earlier: Code: [Select]Dim intDialogResult As INTEGER Dim strOpenFile As String intDialogResult = diaOpenFile.ShowDialog() strOpenFile = diaOpenFile.FileName() If intDialogResult = 1 And strOpenFile <> " " And File.Exists(strOpenFile) = True Then objFileRead = New StreamReader(strOpenFile) ReadFile() End If Then for the ReadFile() Sub, type this: Code: [Select]Sub ReadFile() Dim strTempString As String Dim intLineNum As Integer = 1 Do Until objFileRead.EndOfStream = True strTempString = objFileRead.ReadLine() Select Case intLineNum Case 1 txtTextbox.text = strTempString End Select strTempString = " " intLineNum += 1 Loop objFileRead.Close() End Sub You can add any amount of Cases for how many lines there are in the text file to read and how many textboxes to fill. |
|