Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Vb Note Pad Help Plz


  • Please log in to reply
2 replies to this topic

#1 Zashin

Zashin

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:05:22 PM

Posted 29 March 2007 - 07:26 PM

In vb verson 6.0 im programing a notepad based program. Im trying to figure out how to save it as txt 24/7 and pick diffrent saving like rich, or all file text. Also I want to know how to save the text without the " " in the text document. If anyone can help i would be very happy.

BC AdBot (Login to Remove)

 


#2 Keithuk

Keithuk

  • Members
  • 957 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:22 PM

Posted 10 April 2007 - 07:13 AM

Im trying to figure out how to save it as txt 24/7 and pick diffrent saving like rich, or all file text. Also I want to know how to save the text without the " " in the text document.

I'm not understand this txt 24/7. To pick different saving you need to use a CommonDialog control. You can save as an rtf file but you need to use a RichTextBox not a TextBox to write into.

When you save the text you don't get " " in the file.

I don't have Notepad code at work and this Forum doesn't allow anyone to attach projects so I will post the code when I get home.

The code is on my Forum if you want to search. :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#3 Keithuk

Keithuk

  • Members
  • 957 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:22 PM

Posted 10 April 2007 - 02:50 PM

Ok Zashin this is how I go about loading and saving the text in my NotePad. As I said before you need to use a RichTextBox which will allow you to load and save an rtf file. Also you should be using a CommonDialog control. :thumbsup:
Private Sub mnuOpen_Click() 'menu item

On Error GoTo ErrHandler
Dim FileNum As Integer

With CommonDialog1
	.CancelError = True
	.FileName = ""
	.Filter = "Rich Text Files (*.rtf)|*.rtf|Text Files (*.txt)|*.txt"
	.Flags = cdlOFNPathMustExist
	.ShowOpen
	If .FileName = "" Then Exit Sub
	Select Case LCase$(Right(.FileName, 3)) 'find extension so you know which type of file to open
		Case "rtf"
			'clear RichTextBox1.text
			RichTextBox1.Text = ""
			'Opens the file in a Rich Text Format
			RichTextBox1.LoadFile .FileName, rtfRTF
		Case "txt"
			'If no file selected
			If .FileName = "" Then Exit Sub
			FileNum = FreeFile()
			'clear RichTextBox1.Text
			RichTextBox1.Text = ""
			Open .FileName For Input As #FileNum
			RichTextBox1.Text = Input$(LOF(FileNum), #FileNum)
			Close #FileNum
	End Select
	Me.Caption = .FileTitle & " - NotePad"
End With

Exit Sub
ErrHandler:
If Err <> cdlCancel Then
	MsgBox Err.Description, 16, "Error"
	Close #FileNum
End If

End Sub

Private Sub mnuSaveAs_Click() 'menu item

On Error GoTo ErrHandler
Dim FileNum As Integer

With CommonDialog1
	.CancelError = True
	'Set flag to prompt to overwrite file and the path must exist
	.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
	.Filter = "Rich Text Files (*.rtf)|*.rtf|Text Files (*.txt)|*.txt"
	.FileName = ""
	.ShowSave
	If .FileName = "" Then Exit Sub
	Select Case LCase$(Right(.FileName, 3)) 'find extension so you know which type of file to save
		Case "rtf"
			.DefaultExt = "rtf"
			'Saved the file in a Rich Text Format
			If .FileName = "" Then Exit Sub
			RichTextBox1.SaveFile .FileName, rtfRTF 'save as an rtf file
		Case "txt"
			.DefaultExt = "txt"
			'If no file selected
			If .FileName = "" Then Exit Sub
			FileNum = FreeFile()
			Open .FileName For Output As #FileNum
			Print #FileNum, RichTextBox1.Text 'save as an Ascii text file
			Close #FileNum
	End Select
	Me.Caption = .FileTitle & " - NotePad"
End With

Exit Sub
ErrHandler:
If Err <> cdlCancel Then
	MsgBox Err.Description, 16, "Error"
	Close #FileNum
End If

End Sub

Edited by Keithuk, 10 April 2007 - 02:52 PM.

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users