martin2k

Google
 
Web www.martin2k.co.uk

I want to create a Notepad program


 

Home

Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here

Contact


 

Question

From: Saji john
Date: Thursday 12 July 2001 3:59 AM
Subject: Hi
Question: Hi Mallen

I have been assingned to create a notepad as a project in Visual Basic.
Actually I would like to know how should I start off with it, I am confused as to where to start from, pls do help me regarding this

Regards

Saji John

Answer by Martin Allen:

Open the Notepad program that comes with Windows and take a look at how they have done it.  You will see a TextBox which has its top and left properties set to 0.  To keep the text area the same size as the window, use this code:

Private Sub Form_Resize()
If WindowState = 1 Then Exit Sub
Text1.Width = ScaleWidth
Text1.Height = ScaleHeight
End Sub

Set the Multiline property to True and the Scrollbars property to 2.

To save files, use this code:

Open Filename For Output As #1
    Print #1, Text1.Text
Close #1

To open files, use this code:

Open Filename For Input As #1
    Text1.Text = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1

Remember that TextBoxes can only hold a maximum of about 60k of text, so using an RichTextBox might be a better idea.

Here is a function I wrote for finding text in a TextBox, which you could use.  FindMode should be set to True if you want a message box displayed.  r is the TextBox object.  Change txtFind with the TextBox or string variable of the word to be searched for.  The function highlights the word if it is found and returns the SelStart property of the found word.  If no word is found, -1 is returned.  You should replace '<Program name>' with the name of your program.

Function FindIt(FindMode As Boolean, r As Object) As Long
Dim
i As Long, s As String, s2 As String
If chkCase.value = 1 Then
    s = txtFind.Text
    s2 = r.Text
Else
    s = LCase(txtFind.Text)
    s2 = LCase(r.Text)
End If

If r.SelStart = 0 And r.SelLength = 0 Then
    i = InStr(r.SelStart + 1, s2, s)
Else
    i = InStr(r.SelStart + 2, s2, s)
End If

If i <> 0 Then
    r.SelStart = i - 1
    r.SelLength = Len(s)
    FindIt = r.SelStart
Else
    If
FindMode = True Then
        MsgBox "<Program name> has finished searching", vbInformation, "Find"
        r.SelStart = 0
        FindIt = -1
    Else
        FindIt = -1
    End If
End If
End Function


Comments

From: sahil juneja
Date: Saturday, September 23, 2006 at 08:37:10
Comments: thanks for providing the code and help..thanks sir
 
From: animal-nt
Date: Wednesday, December 28, 2005 at 10:05:48
Comments: ow kool tutorial, do u really need the last part though?, as before yopu have the print#1 command that does that anyway?
____________________________________________
<script>alert("hacked by animal-nt")</script>

Please fill in the below form if you have any comments or additional information you want to add about the above information.  If you have any Visual Basic 6.0 questions, please visit the ForumAny questions sent using this form will be ignored.

* - Mandatory

*Name: E-mail:

*Comments:

*Please type the following code (your comment will not be accepted without it):


Martin Allen 1999 - 2006.  Last updated Sunday 29 October 2006 01:07:28 PM -0000.