Shimi Weitzhandler

1) I'am trying to write a function like this:

Code Snippet

Private Sub TextBox1_TextChanged(sender As System.Object, e _

As System.EventArgs) Handles TextBox1.TextChanged

If Not myfunction(sender, "Hello", ErrorProvider1) Then

Exit Sub

End If

End Sub

Public Function MyFunction(TB As TextBox, Str As String, Optional Err _ As system.Windows.Forms.ErrorProvider = New ErrorProvider()) As Boolean

If tb.Text = Str Then

Err.SetError(tb, "It matches!")

TB.BackColor = Color.LightCoral

Return False

Exit Function

End If

Return True

End Function

and I get an error "Constant expression is required".

can anybody explain about const and what makes the problem occur.

2) Also, I can I write descriptions tp apear in the ToolTip while using the function




Re: Visual Basic Language have problems writing a function

Alex Moura

optional argument's default value has to be a constant expression (which "New ErrorProvider()" isn't). The only valid constant value for reference types is "Nothing". Inside the function, you can potentially check if err is nothing, and set it to a new errorprovider if so. Of course, if a user mistakenly gives you an empty error object, that could result in a tough to find bug. You can also define two overloaded signatures instead of the optional one.

Type ''' over the function declaration - under vs2005 that should generate a template xml documentation that intellisense uses to display informational tooltips on. (Note that this creates a .xml file that has to be distributed along your assembly)






Re: Visual Basic Language have problems writing a function

Spidermans_DarkSide - MSP, VSIP

Shimi Weitzhandler wrote:

and I get an error "Constant expression is required".

can anybody explain about const and what makes the problem occur.

2) Also, I can I write descriptions tp apear in the ToolTip while using the function

Hi Shimi,

Here are the corrections to your code.

I have changed the checking of the STR to

ToUpper

so that

It matches!!

no matter if you spell Hello HELLO or hello or HeLlo or whichever version of Hello in the textbox.

Change it back if you want to.

A Const or Constant is something that will not change in your code.

You could say

Const Pi As Double = Math.PI

Const littleE As Double = Math.E

Const myForumId As String = "Spidermans_DarkSide MSP,VSIP"

Anyway here are the code corrections.>>>>

Code Snippet

Public Class Form1

'Some example CONSTants, please ignore.>>>>

Const Pi As Double = Math.PI

Const littleE As Double = Math.E

Const myForumId As String = "Spidermans_DarkSide MSP,VSIP"

'The next highlighted line should be one line of code in your code window.>>>>

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

Dim ErrorProvider1 As New ErrorProvider

If Not MyFunction(sender, "Hello", ErrorProvider1) Then

Exit Sub

End If

End Sub

'The next highlighted line should be one line of code in your code window.>>>>

Public Function MyFunction(ByVal TB As TextBox, ByVal Str As String, Optional ByVal Err As System.Windows.Forms.ErrorProvider = Nothing) As Boolean

If TB.Text.ToUpper = Str.ToUpper Then

Err.SetError(TB, "It matches!")

TB.BackColor = Color.LightCoral

Return False

Exit Function

End If

Return True

End Function

End Class

E.G. You could have

Optional ByVal aString As String = ""

Regards,

S_DS






Re: Visual Basic Language have problems writing a function

Spidermans_DarkSide - MSP, VSIP

Hi again,

As moderator Alex Moura stated if you hit the single quote mark three times you get the summary XML block appearing.

E.G. >>

Code Snippet

''' <summary text in here.

''' </summary>

''' <param name="TB">A Textbox.</param>

''' <paramsummary>

''' Put your name="Str">A String.</param>

''' <param name="Err">An ErrorProvider.</param>

''' <returns>TRUE or FALSE</returns>

''' <remarks>Depending on whether the TextBox contains "Hello" or not.</remarks>

Public Function MyFunction(ByVal TB As TextBox, ByVal Str As String, Optional ByVal Err As System.Windows.Forms.ErrorProvider = Nothing) As Boolean

If TB.Text.ToUpper = Str.ToUpper Then

Err.SetError(TB, "It matches!")

TB.BackColor = Color.LightCoral

Return False

Exit Function

End If

Return True

End Function

Regards,

S_DS






Re: Visual Basic Language have problems writing a function

Shimi Weitzhandler

thanks friends for sharing your knowledge and correcting me, it was very helpful although I didn't understand exactly what is constant.

What is about question number 2

Shimi Weitzhandler wrote:

2) Also, how can I write descriptions to appear in a ToolTip while using the function






Re: Visual Basic Language have problems writing a function

Spidermans_DarkSide - MSP, VSIP

Shimi Weitzhandler wrote:

thanks friends for sharing your knowledge and correcting me, it was very helpful although I didn't understand exactly what is constant.

What is about question number 2

Shimi Weitzhandler wrote:

2) Also, how can I write descriptions to appear in a ToolTip while using the function

Hi Shimi,

I think the only option is to enter the stuff above the function as per my second post below your initial question.

This will give feedback as you type the function name in with Intellisense but as for tooltips ( with your mouse pointer ), hover over parts of your code and you will see various decriptions appear.

Regards,

S_DS






Re: Visual Basic Language have problems writing a function

Shimi Weitzhandler

I ment like when you're in middle of writing a .NET function, a tooltip shows some descriptions

the same when you eriting a property or method like MessageBox.Show(x,x,x,x,x,x,x,x)...






Re: Visual Basic Language have problems writing a function

Spidermans_DarkSide - MSP, VSIP

Shimi Weitzhandler wrote:

I ment like when you're in middle of writing a .NET function, a tooltip shows some descriptions

the same when you eriting a property or method like MessageBox.Show(x,x,x,x,x,x,x,x)...

Hi Shimi,

That is known as the IntelliSense ( Intelligent - Sense or Sensor ) dialog and as far as I am aware you can do

no more

than what I have already suggested other than change.>>

Public Function MyFunction(ByVal TB As TextBox, ByVal Str As String, Optional ByVal Err As System.Windows.Forms.ErrorProvider = Nothing) As Boolean

to

Public Function MyFunction(ByVal aTextBox As TextBox, ByVal aString As String, Optional ByVal anErrorProvider As System.Windows.Forms.ErrorProvider = Nothing) As Boolean

This helps you to understand what the FUNCTION requires as you type it.

Hope that helps.

Regards,

S_DS






Re: Visual Basic Language have problems writing a function

Shimi Weitzhandler

I got it and it's not a bad idea, but I am wondering how can they do that that there will be a whole description

it is important for me to know that because I write a few functionsun a DLL file and a long time later I want to use the DLL with it's function/property description






Re: Visual Basic Language have problems writing a function

Spidermans_DarkSide - MSP, VSIP

Shimi Weitzhandler wrote:

I got it and it's not a bad idea, but I am wondering how can they do that that there will be a whole description

it is important for me to know that because I write a few functionsun a DLL file and a long time later I want to use the DLL with it's function/property description

Hi,

If you write a managed code DLL file in VB.Net in a project ( open a project as Class Library ) then you can add a reference to it in another project from the PROJECT menu.

Then just add the appropriate IMPORTS statement in your new project.

If say your DLL project is called myDLL and the CLASS is called myFunctions then the IMPORTS statement becomes

IMPORTS myDLL.myFunctions

You then have access to all your functions.

Hope that helps

Regards,

S_DS