473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need help on optional arg

GS
I have this:
Public Function CleanHtml(ByVal strHtml As String, Optional ByVal doc As
HtmlDocument = WebBrowser1.Document) As String
flagged by vb as
Error 5 Reference to a non-shared member requires an object reference.
c:\myproject\WebCtl.vb 73 93 myproject

webctl is an usercontrol with webbrowser control named as webbrowser1. vb
express 2005 just does not like the webBrowser1. part in the optional
arguments
for now I got around declaring two sub, one with 1 arg calling the 2nd with
two arts . the 2nd sub test if doc is nothing then set it to
webbrowser1.document.

this work around is awkward and counterproductive.
I appreciate help in getting optional arg with default working
Oct 6 '06 #1
3 1193
GS wrote:
webctl is an usercontrol with webbrowser control named as
webbrowser1. vb express 2005 just does not like the webBrowser1. part
in the optional arguments
When you use optional parameters, the compiler needs to be able to build the
actual values that are to be used when the parameter is omitted into the
compiled code. Here you are telling it to use a specific object from a form.
As the form doesn't exist at compile time, it is unable to use that object
as the default value.

How about:

\\\
Public Function CleanHtml(ByVal strHtml As String, Optional ByVal doc As
HtmlDocument = Nothing) As String

If doc Is Nothing Then
doc = webbrowser1.Document
End If

[...rest of code...]
///

Does that do what you need?

--

(O)enone
Oct 6 '06 #2
Hello Oenone,

Oenone is correct in their assessment of optional values.

I would suggest avoiding optional parameters though. Instead use overloaded
procedures.

Public Function CleanHtml(ByVal strHtml As String) As String
Return CleanHtml(strHtml, Webbrowser1.Document)
End Function

Public Function CleanHtml(ByVal strHtml As String, ByVal doc As HtmlDocument)
As String

if nothing is doc then
throw new NullReferenceException("Eh, wassup Doc?")
end if

' Do crap here.

End Function

-Boo
GS wrote:
>webctl is an usercontrol with webbrowser control named as
webbrowser1. vb express 2005 just does not like the webBrowser1. part
in the optional arguments
When you use optional parameters, the compiler needs to be able to
build the actual values that are to be used when the parameter is
omitted into the compiled code. Here you are telling it to use a
specific object from a form. As the form doesn't exist at compile
time, it is unable to use that object as the default value.

How about:

\\\
Public Function CleanHtml(ByVal strHtml As String, Optional ByVal doc
As
HtmlDocument = Nothing) As String
If doc Is Nothing Then
doc = webbrowser1.Document
End If
[...rest of code...]
///
Does that do what you need?

Oct 6 '06 #3
GS
thank you all.

I guess optional parameter can be troublesome especially when there is more
than one.

IN this single optional parameter at the end of the parameter list, what
kind problem should one expect?
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
I have this:
Public Function CleanHtml(ByVal strHtml As String, Optional ByVal doc
As
HtmlDocument = WebBrowser1.Document) As String
flagged by vb as
Error 5 Reference to a non-shared member requires an object reference.
c:\myproject\WebCtl.vb 73 93 myproject

webctl is an usercontrol with webbrowser control named as webbrowser1. vb
express 2005 just does not like the webBrowser1. part in the optional
arguments
for now I got around declaring two sub, one with 1 arg calling the 2nd
with
two arts . the 2nd sub test if doc is nothing then set it to
webbrowser1.document.

this work around is awkward and counterproductive.
I appreciate help in getting optional arg with default working


Oct 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DD | last post by:
I have developed a a nice little software package(Packaged with Wise and SageKey) My product works great in a clean enviroment on Win98 and Win2k and XP As soon as i introduce Office 2000 Pro onto...
4
by: MLH | last post by:
The following function declaration confuses me... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean I tried pasting it and its code into an...
106
by: xtra | last post by:
Hi Folk I have about 1000 procedures in my project. Many, many of them are along the lines of function myfuntion () as boolean on error goto er '- Dim Dbs as dao.database Dim Rst as...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
1
by: Tookelso | last post by:
Hello, I would like to have a group of elements which are *required* in one context, but each one is *optional* in another context. For example: I have a configuration file which has a...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
6
by: mohaaron | last post by:
Hello all, I'm not very good with writing regular expressions and need some help with this one. I need to validate an email address which has the full name of the person appended to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.