rich text box

rich text box

Page 1 of 1

11 Replies - 9652 Views - Last Post: 30 January 2008 - 05:03 AM Rate Topic: -----

#1 realwish  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 47
  • Joined: 29-January 08

rich text box

Posted 29 January 2008 - 10:02 PM

i want the source code for
visual basic application
rich text box which will check that every line
entered in the rich text box is ended with a full stop (.) and shows which line does not have full stop at the end

help me please
Is This A Good Question/Topic? 0
  • +

Replies To: rich text box

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: rich text box

Posted 29 January 2008 - 10:25 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 JohnnyThoughtful  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-January 08

Re: rich text box

Posted 29 January 2008 - 10:34 PM

There are several methods for doing this. The crux of the matter though is knowing what you are searching for. From what you say in your post there are two criteria, one which would PASS and one which would FAIL. The criteria for a PASS is where you would find a full stop followed immediately by a Carriage Return and Line Feed. The criteria for a FAIL is where there is just a Carriage Return and Line Feed.

If you loop through the contents of the Rich Text Box and search for
vbCrLf
this will provide a pointer to each end of line. Looking at the PREVIOUS character will then tell you if it is a PASS or FAIL.

		Dim currentContents As String = rtb.Text
		Dim NextEndOfLine As Integer = 0

		While Len(currentContents) > 0
			NextEndOfLine = InStr(currentContents, vbCrLf)
			If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
				'PASS
			Else
				'FAIL
			End If
			currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
		End While



I foresee some minor issues with this code but the general principal is right and will get you on the right track.
Was This Post Helpful? 0
  • +
  • -

#4 realwish  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 47
  • Joined: 29-January 08

Re: rich text box

Posted 29 January 2008 - 11:53 PM

i had put the code in the button click but it shows the syntax error


Private Sub Command1_Click()
Dim currentContents As String = rtb.Text
		Dim NextEndOfLine As Integer = 0

		While Len(currentContents) > 0
			NextEndOfLine = InStr(currentContents, vbCrLf)
			If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
			   MsgBox " PASS"
			Else
				MsgBox "FaIL"
			End If
			currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
		End While
End Sub

Was This Post Helpful? 0
  • +
  • -

#5 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: rich text box

Posted 30 January 2008 - 12:04 AM

Please :code:

Your error is on the first line of your Command1_Click() function.

You cannot declare a variable and assign it's value in one statement.

Put the assigning statement on the next line, like so:

Dim currentContents As String
currentContents = rtb.Text


This post has been edited by Nayana: 30 January 2008 - 12:06 AM

Was This Post Helpful? 0
  • +
  • -

#6 realwish  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 47
  • Joined: 29-January 08

Re: rich text box

Posted 30 January 2008 - 12:11 AM

i had modify the code as you said but still not working syntax error
end while is in still red , help me
Private Sub Command1_Click()
Dim currentContents As String
	currentContents = rtb.Text
		Dim NextEndOfLine As Integer
			NextEndOfLine = 0

		While Len(currentContents) > 0
			NextEndOfLine = InStr(currentContents, vbCrLf)
			If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
			   MsgBox " PASS"
			Else
				MsgBox "FaIL"
			End If
			currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
		End While
End Sub


Was This Post Helpful? 0
  • +
  • -

#7 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: rich text box

Posted 30 January 2008 - 01:05 AM

Don't use End While, use Wend instead.

It looks like you were trying to put VB.net code into Visual Basic.

The two are not one and the same.

When you find code examples, try and make sure they are referring to VB5 or VB6. VB.net stuff will not work for you.

If you want to, you can download it for free from Microsoft's website though.
Was This Post Helpful? 0
  • +
  • -

#8 realwish  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 47
  • Joined: 29-January 08

Re: rich text box

Posted 30 January 2008 - 02:07 AM

yes i am trying this code on vb 6.0
can you help me

i am doing this on vbasic 6.0
i had used wend but the error message says run time error object recquired
Private Sub Command1_Click()
Dim currentContents As String
	currentContents = rtb.Text
		Dim NextEndOfLine As Integer
			NextEndOfLine = 0

		While Len(currentContents) > 0
			NextEndOfLine = InStr(currentContents, vbCrLf)
			If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
			   MsgBox " PASS"
			Else
				MsgBox "FaIL"
			End If
			currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
		Wend
End Sub


Was This Post Helpful? 0
  • +
  • -

#9 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: rich text box

Posted 30 January 2008 - 02:56 AM

That's because you need to have RichTextBox called "rtf" on your form. If you already have a RichTextBox, change it's name, or change what you call it in the Command1_Click() function.

If you don't know how to get a RichTextBox:
  • Right-click on the components panel (on the left hand side)
  • Choose Components... from the pop-up menu.
  • Scroll down until you see Microsoft RichTextBox Control and tick it.
  • Press OK

It should appear in your list of components and you can put it on the form.

There are also other errors with the code that JohnnyThoughtful wrote:
vbCrLf is actually 2 characters long, so:
change
If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
to
If Mid(currentContents, NextEndOfLine - 2, 1) = "." Then

and
currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
to
currentContents = Mid(currentContents, NextEndOfLine + 2)

And another problem is what if the last characters in the RichTextBox are not vbCrLf? The program crashes. So change
currentContents = rtb.Text
to
currentContents = rtb.Text + vbCrLf

This post has been edited by Nayana: 30 January 2008 - 02:59 AM

Was This Post Helpful? 0
  • +
  • -

#10 JohnnyThoughtful  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-January 08

Re: rich text box

Posted 30 January 2008 - 03:13 AM

View PostNayana, on 30 Jan, 2008 - 02:56 AM, said:

That's because you need to have RichTextBox called "rtf" on your form. If you already have a RichTextBox, change it's name, or change what you call it in the Command1_Click() function.

If you don't know how to get a RichTextBox:
  • Right-click on the components panel (on the left hand side)
  • Choose Components... from the pop-up menu.
  • Scroll down until you see Microsoft RichTextBox Control and tick it.
  • Press OK
It should appear in your list of components and you can put it on the form.

There are also other errors with the code that JohnnyThoughtful wrote:
vbCrLf is actually 2 characters long, so:
change
If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
to
If Mid(currentContents, NextEndOfLine - 2, 1) = "." Then

and
currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
to
currentContents = Mid(currentContents, NextEndOfLine + 2)

And another problem is what if the last characters in the RichTextBox are not vbCrLf? The program crashes. So change
currentContents = rtb.Text
to
currentContents = rtb.Text + vbCrLf


Actually, the fact that vbCrLf is two characters long is irrelevant as INSTR returns the START of the searched for string. So regardless of how many letters/characters you search for, it will return the position of the start of the searched for string. :)
Was This Post Helpful? 0
  • +
  • -

#11 realwish  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 47
  • Joined: 29-January 08

Re: rich text box

Posted 30 January 2008 - 04:03 AM

thanks a lot
i have two more problems
(i)
on each line i have to click ok and then program proceeds.how can it check itself and tell me calculated no of full stops left and can give me the respective line nos so that i can correct the text
(ii)
how my rich text box can get data from clipboard memory
i have to paste the no. of lines from another text editor to my rich text box


regards
Was This Post Helpful? 0
  • +
  • -

#12 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: rich text box

Posted 30 January 2008 - 05:03 AM

View PostJohnnyThoughtful, on 30 Jan, 2008 - 03:13 AM, said:

Actually, the fact that vbCrLf is two characters long is irrelevant as INSTR returns the START of the searched for string. So regardless of how many letters/characters you search for, it will return the position of the start of the searched for string. :)


Johnny: you are correct, my mistake.

Sorry realwish, where I said:

Quote

change
If Mid(currentContents, NextEndOfLine - 1, 1) = "." Then
to
If Mid(currentContents, NextEndOfLine - 2, 1) = "." Then

I was wrong so change it back to - 1.

The statement still applies to this line:
currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine)
which should have read
currentContents = Right(currentContents, Len(currentContents) - NextEndOfLine - 1)
Due to CrLf being two chars.

And I rewrote it as
currentContents = Mid(currentContents, NextEndOfLine + 2)
Because it's more compact.

This post has been edited by Nayana: 30 January 2008 - 05:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1