1.

Solve : Visual Basic 2008 Express?

Answer»

I'm a complete beginner on VB and I'm making my first little program.

I have made a menu strip along the top and I would like to know how to configure the

Open
Save
Exit

Copy
Paste

Help

buttons as the book I'm using doesn't explain how to.

Any help please?Are you asking how to change the appearance of the menu or do you want to know how to add functionality to each menu item?How to add the functionality. I have already added the buttons.I'm not sure about the newer versions... haven't messed about with them enough- but in VB6 you click the menu and the menu item, and it will show the code procedure for that menu.

...

EDIT: I checked in Visual Studio 2008- after you add the menu items, you double-click the item whose code you want to see to view the procedure.Yeah, you double click to add the code, but all I have written in the code at the moment is:

Quote

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

MsgBox("This would open a new file", MsgBoxStyle.Information)

End Sub

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.



Discussion

No Comment Found