Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, March 29, 2012

Please anyone has confirm message box with yes No buttons in it for asp.net page

Please i am looking for a javascript code to use with confirm message box with two buttons Yes and NO in it.

Thank you very much.How about 'OK' and 'Cancel'?

if that's ok - check out :
http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=confirm
Hello David,
Thank's a lot, I will try the messagebox code.

please can someone explain the following code.

Hi Christian,

Thanks for the reply, but this is what I don't understand.... (by the way
there was a typo in my last message: "dpPageInit" should be "doPageInit").

I am new to inheritance, but I understand that if I create a classA that
inherits from classB then classA will expose properties/methods of classB.
The things I don't understand are code like:

a) override
b) +=
c) this.Init += new System.EventHandler

I am trying to create a page template (ie: a template page that contains a
header and footer), and then I want each of my pages to inherit the template
page so all I have to do is add the main body of the ASP page (the header
and footer will automatically be rendered by the template page).

I have downloaded the code from the following place
http://www.aspnetui.com/templates/ but I cant get it to work when I try it
myself. On top of that I think they have made the example more complex than
it needs to be.

All I want is a template that looks just like their red example. If someone
could post a simplified version of it it would be great.

"Christian" <pleasenononospamcmillotti@dotnet.itags.org.novasoftware.it> wrote in message
news:%23go0RMpVDHA.2316@dotnet.itags.org.TK2MSFTNGP09.phx.gbl...
> Hi Suzy
> It seems to me that you are in an inherited class, you are overriding
> virtual method OnInit in order to subscribe dbPageInit to be called in the
> Init Event, dbPageLoad to be called In the Load Event and calling OnInit
> method on base class ( that inherited from )...
> What else aren't you understanding?
> In case give details..
> Christian.
> "suzy" <me@dotnet.itags.org.nospam.com> ha scritto nel messaggio
> news:%23%23Wf4EpVDHA.532@dotnet.itags.org.TK2MSFTNGP09.phx.gbl...
> > please can someone explain the following code to a newbie... thanks
> > override protected void OnInit(EventArgs e)
> > {
> > this.Init += new System.EventHandler(dpPageInit);
> > this.Load += new System.EventHandler(doPageLoad);
> > base.OnInit(e);
> > }a) override:
If you have:
Class MyClass
{
...
protected virtual void MyMethod()
{
// Some instructions
...
}
}
MyMethod is the first implementation of the method.
You could have your ownn MyMethod in your class:
Class MySecondClass : Myclass
{
protected override void MyMethod()
{
// other instructions
...
}
}
You can override only virtual methods.

b) += :
add something to... for example:

c) this.Init += new System.EventHandler( doPageInit ):
add doPageInit method to delegate list called by Init event.
( Is Init an event ? )
When Init event is fired your class iterates through delegate: (
System.EventHandler is our delegate )
and call all methods subscribed
you subscribe your own method ( that must have the signature given by
delegate as return type, parameters, etc ) by writng
... += new System.EventHandler( doPageInit ):

Do you know what delegates are?

"suzy" <me@.nospam.com> ha scritto nel messaggio
news:eOF6lbpVDHA.2328@.TK2MSFTNGP12.phx.gbl...
> Hi Christian,
> Thanks for the reply, but this is what I don't understand.... (by the way
> there was a typo in my last message: "dpPageInit" should be "doPageInit").
> I am new to inheritance, but I understand that if I create a classA that
> inherits from classB then classA will expose properties/methods of classB.
> The things I don't understand are code like:
> a) override
> b) +=
> c) this.Init += new System.EventHandler
>
> I am trying to create a page template (ie: a template page that contains a
> header and footer), and then I want each of my pages to inherit the
template
> page so all I have to do is add the main body of the ASP page (the header
> and footer will automatically be rendered by the template page).
> I have downloaded the code from the following place
> http://www.aspnetui.com/templates/ but I cant get it to work when I try it
> myself. On top of that I think they have made the example more complex
than
> it needs to be.
> All I want is a template that looks just like their red example. If
someone
> could post a simplified version of it it would be great.

> > "suzy" <me@.nospam.com> ha scritto nel messaggio
> > news:%23%23Wf4EpVDHA.532@.TK2MSFTNGP09.phx.gbl...
> > > please can someone explain the following code to a newbie... thanks
> > > > override protected void OnInit(EventArgs e)
> > > {
> > > > this.Init += new System.EventHandler(dpPageInit);
> > > this.Load += new System.EventHandler(doPageLoad);
> > > base.OnInit(e);
> > > }
> >
> Thanks for your reply. No I don't know what delegates are. :-(

should take a look..
> Also, in your example of MyClass/MyMethod in which order will the code be
> run?
MyClass.MyMethod is 1 implementation
MySecondClass.MyMethod is another 1
they are not tied
public Class MyClass
{
...
protected virtual void MyMethod()
{
// Some instructions
MessageBox.Show( "1" );
}
protected virtual void AnotherMethod()
{
MessageBox.Show( "Hello" );
}
}
MyMethod is the first implementation of the method.
You could have your ownn MyMethod in your class:
public Class MySecondClass : Myclass
{
protected override void MyMethod()
{
// other instructions
MessageBox.Show( "2" );
...
}
protectd override AnotherMethod()
{
base.AnotherMethod();
MessageBox.Show( "Suzy" );
}
}
MyClass cl = new MyClass();
cl.MyMethod(); // displays 1
cl.AnotherMethod(); // displays Hello
MySecondClass cl2 = new MySecondClass();
cl2.MyMethod(); // displays 2
cl2.AnotherMethod(); // displays Hello and then Suzy

talking about delegates and events

this.Load += new System.EventHandler(doPageLoad);
this.Load += new System.EventHandler(doPageAnotherLoad);
this.Load += new System.EventHandler(doPageAnotherOneLoad);

On Load Fired will be executed
doPageLoad(), doPageAnotherLoad(), doPageAnotherOneLoad(), i think in order
of submission

> Someone said the following code would create a template if placed in a
page
> template class:
Sorry, i'm not the proper person for help you with asp... never worked :-(
Repost for detailed and specific helps.

> protected override void OnInit (EventArgs args)
> {
> this.Controls.AddAt(0, LoadControl("path to header.ascx " );
> base.OnInit(e);
> this.Controls.Add(LoadControl("path to footer.ascx"));
> }
> And the code in my page that inherited the above contained the
following...:
> override protected void OnInit(EventArgs e)
> {
> InitializeComponent();
> base.OnInit(e);
> }
> private void Page_Load(object sender, System.EventArgs e)
> {
> placeholder.Controls.Add (grdDataGrid);
> }
> They said this should place my placeholder/datagrid between a
header/footer.
Thanks, that explains a lot! Much appreciated!

I think I am right in saying that if I inherited a template class containing
the code below in it, then it won't place a header/footer around my ASP code
(of the page that inherits the template class).

protected override void OnInit (EventArgs args)
{
this.Controls.AddAt(0, LoadControl("path to header.ascx" );
base.OnInit(e);
this.Controls.Add(LoadControl("path to footer.ascx"));
}

"Tom" <TomRemoveThisClement@.sbcglobal.net> wrote in message
news:uMKACrzVDHA.2156@.TK2MSFTNGP11.phx.gbl...
> Hi Susy,
> A delegate (or an event) is an kind of pointer to functions. The
difference
> between an event and an ordinary pointer is that inside of the event is a
> list of pointers to functions. If you "call" the event it's called
raising
> the event and every function that has been added to the event is called in
> order.
> The way this is typicaly used in C# is if you have a class in which things
> can occur that might be of interest to others, you can declare a public
> event (like "event EventHandler Load;") Any other object that is
interested
> in (i.e wants to be notified of) this occurance (Load) registers this
> interest by adding a pointer to a function in the event. So when you see
> the code:
> this.Load += new System.EventHandler(doPageLoad);
> you are looking at an expression of interest in the Load event. When it
> occurs, the doPageLoad() function will be called (along with any other
> functions that have been registered with the Load event using the +=
syntax.
> The odd thing about this code is that it it registering with an event on
the
> same object as the current instance. There are better (or at least more
> natural) ways of accomplishing this. First, if (as is likely) the Load
> event is declared in a superclass (a class from which this current class
was
> derived - directly or indirectly) you would typically override a protected
> OnLoad() method to obtain the notification of Load. Second, if the event
is
> declared in the same object as the += code, you'd typically just call a
> function directly instead of raising an event and receiving notification
for
> it.
> Tom
> "suzy" <me@.nospam.com> wrote in message
> news:%23PoQfkrVDHA.3088@.tk2msftngp13.phx.gbl...
> > great, i am starting to understand more:
> > i thought it worked the way you say it worked, that's why i didn't
> > understand the theory behind he code that was submitted to me regarding
> the
> > page hearder/footer (shown below):
> > > protected override void OnInit (EventArgs args)
> > > {
> > > this.Controls.AddAt(0, LoadControl("path to header.ascx " );
> > > base.OnInit(e);
> > > this.Controls.Add(LoadControl("path to footer.ascx"));
> > > }
> > if the above code is in my base/template class (A), i can't see how i
can
> > write code in a class that inherits from it (B), so that my code from B
> gets
> > inserted between the header/footer.
> > i know you said you haven't done asp.net, but doesn't the theory of it
> sound
> > wrong to you?
> > "Christian" <pleasenononospamcmillotti@.novasoftware.it> wrote in message
> > news:uE5jGJrVDHA.532@.TK2MSFTNGP10.phx.gbl...
> > > > > Thanks for your reply. No I don't know what delegates are. :-(
> > > > should take a look..
> > > > > > Also, in your example of MyClass/MyMethod in which order will the
code
> > be
> > > > run?
> > > MyClass.MyMethod is 1 implementation
> > > MySecondClass.MyMethod is another 1
> > > they are not tied
> > > public Class MyClass
> > > {
> > > ...
> > > protected virtual void MyMethod()
> > > {
> > > // Some instructions
> > > MessageBox.Show( "1" );
> > > }
> > > protected virtual void AnotherMethod()
> > > {
> > > MessageBox.Show( "Hello" );
> > > }
> > > }
> > > MyMethod is the first implementation of the method.
> > > You could have your ownn MyMethod in your class:
> > > public Class MySecondClass : Myclass
> > > {
> > > protected override void MyMethod()
> > > {
> > > // other instructions
> > > MessageBox.Show( "2" );
> > > ...
> > > }
> > > protectd override AnotherMethod()
> > > {
> > > base.AnotherMethod();
> > > MessageBox.Show( "Suzy" );
> > > }
> > > }
> > > MyClass cl = new MyClass();
> > > cl.MyMethod(); // displays 1
> > > cl.AnotherMethod(); // displays Hello
> > > MySecondClass cl2 = new MySecondClass();
> > > cl2.MyMethod(); // displays 2
> > > cl2.AnotherMethod(); // displays Hello and then Suzy
> > > > talking about delegates and events
> > > > this.Load += new System.EventHandler(doPageLoad);
> > > this.Load += new System.EventHandler(doPageAnotherLoad);
> > > this.Load += new System.EventHandler(doPageAnotherOneLoad);
> > > > On Load Fired will be executed
> > > doPageLoad(), doPageAnotherLoad(), doPageAnotherOneLoad(), i think in
> > order
> > > of submission
> > > > > > > Someone said the following code would create a template if placed in
a
> > > page
> > > > template class:
> > > Sorry, i'm not the proper person for help you with asp... never worked
> :-(
> > > Repost for detailed and specific helps.
> > > > > protected override void OnInit (EventArgs args)
> > > > {
> > > > this.Controls.AddAt(0, LoadControl("path to header.ascx " );
> > > > base.OnInit(e);
> > > > this.Controls.Add(LoadControl("path to footer.ascx"));
> > > > }
> > > > > > And the code in my page that inherited the above contained the
> > > following...:
> > > > > > override protected void OnInit(EventArgs e)
> > > > > > {
> > > > > > InitializeComponent();
> > > > > > base.OnInit(e);
> > > > > > }
> > > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > > {
> > > > > > placeholder.Controls.Add (grdDataGrid);
> > > > > > }
> > > > > > They said this should place my placeholder/datagrid between a
> > > header/footer.
> > > >

Please check code - need to make generic

Hello -
This code was snagged by me from the Internet and altered. Its purpose is
to check for swear words. It works the way it currently is, but I need it t
o
be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
directly; I want to be able to plug in the name of any textbox into
CheckString(TextBox1.Text), instead of just a specific textbox. [I have man
y
textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string)
Dim alWordList as New ArrayList
Dim origtext as String
origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()
Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
InputString = r.Replace(InputString, "****")
Next
TextBox1.Text = InputString
If origtext <> TextBox1.Text Then
Label1.Text = "Funky words, please replace."
Else
Label1.Text = "Okay." 'This is just included for testing
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1.Text)
End Sub
Any suggestions will be greatly appreciated!
--
SandyHi Sandy,
You can try
Public Sub CheckString(txtBox As TextBox, lbl As Label)
Dim alWordList as New ArrayList
Dim inputstring as string = txtBox.Text
Dim origtext as String = inputstring
dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()
Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
inputString = r.Replace(inputString, "****")
Next
txtBox.Text = inputString
If Not origtext.Equals(inputString) Then
lbl.Text = "Funky words, please replace."
Else
lbl.Text = "Okay." 'This is just included for testing
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1, Label1)
End Sub
"Sandy" wrote:

> Hello -
> This code was snagged by me from the Internet and altered. Its purpose is
> to check for swear words. It works the way it currently is, but I need it
to
> be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I have m
any
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
You could achieve this by e.g. creating a new class with a static
method called
public static bool CheckString( string input, string censoredString )
that returns a bool indicating whether it had to censor the string.
The censored string is written into the second string reference you
pass.
Since I am not familiar with VB, here is the C# for that.
public class SwearWordChecker{
public static string CheckString( string input, string censoredString
){
censoredString = input;
// do your thing here
..
censoredString = r.Replace(InputString, "****");
..
//if they are the same, return true
return (input == censoredString);
}
}
and then use that class in your Button code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
string censored = null;
if( !CheckString(TextBox1.Text, censored) ){
TextBox1.Text = censored;
lblError.Text = "You cursing sombitch."
}
End Sub
Hope this helps.
Manuel
Sandy wrote:
> Hello -
> This code was snagged by me from the Internet and altered. Its
purpose is
> to check for swear words. It works the way it currently is, but I
need it to
> be more generic -- i.e., I don't want it to refer to TextBox1 or
Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I
have many
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
Thanks so much, Elton. It works beautifully!
Sandy
"Elton W" wrote:
> Hi Sandy,
> You can try
> Public Sub CheckString(txtBox As TextBox, lbl As Label)
> Dim alWordList as New ArrayList
> Dim inputstring as string = txtBox.Text
> Dim origtext as String = inputstring
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> inputString = r.Replace(inputString, "****")
> Next
> txtBox.Text = inputString
> If Not origtext.Equals(inputString) Then
> lbl.Text = "Funky words, please replace."
> Else
> lbl.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1, Label1)
> End Sub
>
> "Sandy" wrote:
>
Thanks for your response!
Sandy
"DoesDotNet" wrote:

> You could achieve this by e.g. creating a new class with a static
> method called
> public static bool CheckString( string input, string censoredString )
> that returns a bool indicating whether it had to censor the string.
> The censored string is written into the second string reference you
> pass.
> Since I am not familiar with VB, here is the C# for that.
> public class SwearWordChecker{
> public static string CheckString( string input, string censoredString
> ){
> censoredString = input;
> // do your thing here
> ...
> censoredString = r.Replace(InputString, "****");
> ...
> //if they are the same, return true
> return (input == censoredString);
> }
> }
> and then use that class in your Button code:
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> string censored = null;
> if( !CheckString(TextBox1.Text, censored) ){
> TextBox1.Text = censored;
> lblError.Text = "You cursing sombitch."
> }
> End Sub
> Hope this helps.
> Manuel
>
> Sandy wrote:
> purpose is
> need it to
> Label1
> have many
>

Please check code - need to make generic

Hello -

This code was snagged by me from the Internet and altered. Its purpose is
to check for swear words. It works the way it currently is, but I need it to
be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
directly; I want to be able to plug in the name of any textbox into
CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
textboxes on one page that all need to be checked.]

Public Sub CheckString(inputstring as string)
Dim alWordList as New ArrayList

Dim origtext as String
origtext = TextBox1.Text

dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()

Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
InputString = r.Replace(InputString, "****")
Next

TextBox1.Text = InputString
If origtext <> TextBox1.Text Then
Label1.Text = "Funky words, please replace."
Else
Label1.Text = "Okay." 'This is just included for testing
End If
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1.Text)
End Sub

Any suggestions will be greatly appreciated!
--
SandyHi Sandy,

You can try

Public Sub CheckString(txtBox As TextBox, lbl As Label)
Dim alWordList as New ArrayList
Dim inputstring as string = txtBox.Text
Dim origtext as String = inputstring

dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()

Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
inputString = r.Replace(inputString, "****")
Next

txtBox.Text = inputString
If Not origtext.Equals(inputString) Then
lbl.Text = "Funky words, please replace."
Else
lbl.Text = "Okay." 'This is just included for testing
End If
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1, Label1)
End Sub

"Sandy" wrote:

> Hello -
> This code was snagged by me from the Internet and altered. Its purpose is
> to check for swear words. It works the way it currently is, but I need it to
> be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
Hi Sandy,

You can try

Public Sub CheckString(txtBox As TextBox, lbl As Label)
Dim alWordList as New ArrayList
Dim inputstring as string = txtBox.Text
Dim origtext as String = inputstring

dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()

Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
inputString = r.Replace(inputString, "****")
Next

txtBox.Text = inputString
If Not origtext.Equals(inputString) Then
lbl.Text = "Funky words, please replace."
Else
lbl.Text = "Okay." 'This is just included for testing
End If
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1, Label1)
End Sub

"Sandy" wrote:

> Hello -
> This code was snagged by me from the Internet and altered. Its purpose is
> to check for swear words. It works the way it currently is, but I need it to
> be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
You could achieve this by e.g. creating a new class with a static
method called

public static bool CheckString( string input, string censoredString )

that returns a bool indicating whether it had to censor the string.
The censored string is written into the second string reference you
pass.
Since I am not familiar with VB, here is the C# for that.

public class SwearWordChecker{
public static string CheckString( string input, string censoredString
){
censoredString = input;
// do your thing here
...
censoredString = r.Replace(InputString, "****");
...
//if they are the same, return true
return (input == censoredString);
}
}

and then use that class in your Button code:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
string censored = null;
if( !CheckString(TextBox1.Text, censored) ){
TextBox1.Text = censored;
lblError.Text = "You cursing sombitch."
}
End Sub

Hope this helps.
Manuel

Sandy wrote:
> Hello -
> This code was snagged by me from the Internet and altered. Its
purpose is
> to check for swear words. It works the way it currently is, but I
need it to
> be more generic -- i.e., I don't want it to refer to TextBox1 or
Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I
have many
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
You could achieve this by e.g. creating a new class with a static
method called

public static bool CheckString( string input, string censoredString )

that returns a bool indicating whether it had to censor the string.
The censored string is written into the second string reference you
pass.
Since I am not familiar with VB, here is the C# for that.

public class SwearWordChecker{
public static string CheckString( string input, string censoredString
){
censoredString = input;
// do your thing here
...
censoredString = r.Replace(InputString, "****");
...
//if they are the same, return true
return (input == censoredString);
}
}

and then use that class in your Button code:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
string censored = null;
if( !CheckString(TextBox1.Text, censored) ){
TextBox1.Text = censored;
lblError.Text = "You cursing sombitch."
}
End Sub

Hope this helps.
Manuel

Sandy wrote:
> Hello -
> This code was snagged by me from the Internet and altered. Its
purpose is
> to check for swear words. It works the way it currently is, but I
need it to
> be more generic -- i.e., I don't want it to refer to TextBox1 or
Label1
> directly; I want to be able to plug in the name of any textbox into
> CheckString(TextBox1.Text), instead of just a specific textbox. [I
have many
> textboxes on one page that all need to be checked.]
> Public Sub CheckString(inputstring as string)
> Dim alWordList as New ArrayList
> Dim origtext as String
> origtext = TextBox1.Text
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> InputString = r.Replace(InputString, "****")
> Next
> TextBox1.Text = InputString
> If origtext <> TextBox1.Text Then
> Label1.Text = "Funky words, please replace."
> Else
> Label1.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1.Text)
> End Sub
> Any suggestions will be greatly appreciated!
> --
> Sandy
Thanks so much, Elton. It works beautifully!

Sandy

"Elton W" wrote:

> Hi Sandy,
> You can try
> Public Sub CheckString(txtBox As TextBox, lbl As Label)
> Dim alWordList as New ArrayList
> Dim inputstring as string = txtBox.Text
> Dim origtext as String = inputstring
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> inputString = r.Replace(inputString, "****")
> Next
> txtBox.Text = inputString
> If Not origtext.Equals(inputString) Then
> lbl.Text = "Funky words, please replace."
> Else
> lbl.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1, Label1)
> End Sub
>
> "Sandy" wrote:
> > Hello -
> > This code was snagged by me from the Internet and altered. Its purpose is
> > to check for swear words. It works the way it currently is, but I need it to
> > be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
> > directly; I want to be able to plug in the name of any textbox into
> > CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
> > textboxes on one page that all need to be checked.]
> > Public Sub CheckString(inputstring as string)
> > Dim alWordList as New ArrayList
> > Dim origtext as String
> > origtext = TextBox1.Text
> > dim xmlDocPath as string = server.mappath("bad_words2.xml")
> > dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> > While (xmlReader.Read())
> > if xmlReader.Nodetype=xmlNodeType.Text then
> > alWordList.Add(xmlReader.Value)
> > End If
> > End While
> > xmlReader.Close()
> > Dim r as Regex
> > dim element as string
> > dim output as string
> > For Each element in alWordList
> > r = New Regex("\b" & element)
> > InputString = r.Replace(InputString, "****")
> > Next
> > TextBox1.Text = InputString
> > If origtext <> TextBox1.Text Then
> > Label1.Text = "Funky words, please replace."
> > Else
> > Label1.Text = "Okay." 'This is just included for testing
> > End If
> > End Sub
> > Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > CheckString(TextBox1.Text)
> > End Sub
> > Any suggestions will be greatly appreciated!
> > --
> > Sandy
Thanks so much, Elton. It works beautifully!

Sandy

"Elton W" wrote:

> Hi Sandy,
> You can try
> Public Sub CheckString(txtBox As TextBox, lbl As Label)
> Dim alWordList as New ArrayList
> Dim inputstring as string = txtBox.Text
> Dim origtext as String = inputstring
> dim xmlDocPath as string = server.mappath("bad_words2.xml")
> dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> While (xmlReader.Read())
> if xmlReader.Nodetype=xmlNodeType.Text then
> alWordList.Add(xmlReader.Value)
> End If
> End While
> xmlReader.Close()
> Dim r as Regex
> dim element as string
> dim output as string
> For Each element in alWordList
> r = New Regex("\b" & element)
> inputString = r.Replace(inputString, "****")
> Next
> txtBox.Text = inputString
> If Not origtext.Equals(inputString) Then
> lbl.Text = "Funky words, please replace."
> Else
> lbl.Text = "Okay." 'This is just included for testing
> End If
> End Sub
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CheckString(TextBox1, Label1)
> End Sub
>
> "Sandy" wrote:
> > Hello -
> > This code was snagged by me from the Internet and altered. Its purpose is
> > to check for swear words. It works the way it currently is, but I need it to
> > be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
> > directly; I want to be able to plug in the name of any textbox into
> > CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
> > textboxes on one page that all need to be checked.]
> > Public Sub CheckString(inputstring as string)
> > Dim alWordList as New ArrayList
> > Dim origtext as String
> > origtext = TextBox1.Text
> > dim xmlDocPath as string = server.mappath("bad_words2.xml")
> > dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> > While (xmlReader.Read())
> > if xmlReader.Nodetype=xmlNodeType.Text then
> > alWordList.Add(xmlReader.Value)
> > End If
> > End While
> > xmlReader.Close()
> > Dim r as Regex
> > dim element as string
> > dim output as string
> > For Each element in alWordList
> > r = New Regex("\b" & element)
> > InputString = r.Replace(InputString, "****")
> > Next
> > TextBox1.Text = InputString
> > If origtext <> TextBox1.Text Then
> > Label1.Text = "Funky words, please replace."
> > Else
> > Label1.Text = "Okay." 'This is just included for testing
> > End If
> > End Sub
> > Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > CheckString(TextBox1.Text)
> > End Sub
> > Any suggestions will be greatly appreciated!
> > --
> > Sandy
Thanks for your response!

Sandy

"DoesDotNet" wrote:

> You could achieve this by e.g. creating a new class with a static
> method called
> public static bool CheckString( string input, string censoredString )
> that returns a bool indicating whether it had to censor the string.
> The censored string is written into the second string reference you
> pass.
> Since I am not familiar with VB, here is the C# for that.
> public class SwearWordChecker{
> public static string CheckString( string input, string censoredString
> ){
> censoredString = input;
> // do your thing here
> ...
> censoredString = r.Replace(InputString, "****");
> ...
> //if they are the same, return true
> return (input == censoredString);
> }
> }
> and then use that class in your Button code:
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> string censored = null;
> if( !CheckString(TextBox1.Text, censored) ){
> TextBox1.Text = censored;
> lblError.Text = "You cursing sombitch."
> }
> End Sub
> Hope this helps.
> Manuel
>
> Sandy wrote:
> > Hello -
> > This code was snagged by me from the Internet and altered. Its
> purpose is
> > to check for swear words. It works the way it currently is, but I
> need it to
> > be more generic -- i.e., I don't want it to refer to TextBox1 or
> Label1
> > directly; I want to be able to plug in the name of any textbox into
> > CheckString(TextBox1.Text), instead of just a specific textbox. [I
> have many
> > textboxes on one page that all need to be checked.]
> > Public Sub CheckString(inputstring as string)
> > Dim alWordList as New ArrayList
> > Dim origtext as String
> > origtext = TextBox1.Text
> > dim xmlDocPath as string = server.mappath("bad_words2.xml")
> > dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> > While (xmlReader.Read())
> > if xmlReader.Nodetype=xmlNodeType.Text then
> > alWordList.Add(xmlReader.Value)
> > End If
> > End While
> > xmlReader.Close()
> > Dim r as Regex
> > dim element as string
> > dim output as string
> > For Each element in alWordList
> > r = New Regex("\b" & element)
> > InputString = r.Replace(InputString, "****")
> > Next
> > TextBox1.Text = InputString
> > If origtext <> TextBox1.Text Then
> > Label1.Text = "Funky words, please replace."
> > Else
> > Label1.Text = "Okay." 'This is just included for testing
> > End If
> > End Sub
> > Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > CheckString(TextBox1.Text)
> > End Sub
> > Any suggestions will be greatly appreciated!
> > --
> > Sandy
>
Thanks for your response!

Sandy

"DoesDotNet" wrote:

> You could achieve this by e.g. creating a new class with a static
> method called
> public static bool CheckString( string input, string censoredString )
> that returns a bool indicating whether it had to censor the string.
> The censored string is written into the second string reference you
> pass.
> Since I am not familiar with VB, here is the C# for that.
> public class SwearWordChecker{
> public static string CheckString( string input, string censoredString
> ){
> censoredString = input;
> // do your thing here
> ...
> censoredString = r.Replace(InputString, "****");
> ...
> //if they are the same, return true
> return (input == censoredString);
> }
> }
> and then use that class in your Button code:
> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> string censored = null;
> if( !CheckString(TextBox1.Text, censored) ){
> TextBox1.Text = censored;
> lblError.Text = "You cursing sombitch."
> }
> End Sub
> Hope this helps.
> Manuel
>
> Sandy wrote:
> > Hello -
> > This code was snagged by me from the Internet and altered. Its
> purpose is
> > to check for swear words. It works the way it currently is, but I
> need it to
> > be more generic -- i.e., I don't want it to refer to TextBox1 or
> Label1
> > directly; I want to be able to plug in the name of any textbox into
> > CheckString(TextBox1.Text), instead of just a specific textbox. [I
> have many
> > textboxes on one page that all need to be checked.]
> > Public Sub CheckString(inputstring as string)
> > Dim alWordList as New ArrayList
> > Dim origtext as String
> > origtext = TextBox1.Text
> > dim xmlDocPath as string = server.mappath("bad_words2.xml")
> > dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
> > While (xmlReader.Read())
> > if xmlReader.Nodetype=xmlNodeType.Text then
> > alWordList.Add(xmlReader.Value)
> > End If
> > End While
> > xmlReader.Close()
> > Dim r as Regex
> > dim element as string
> > dim output as string
> > For Each element in alWordList
> > r = New Regex("\b" & element)
> > InputString = r.Replace(InputString, "****")
> > Next
> > TextBox1.Text = InputString
> > If origtext <> TextBox1.Text Then
> > Label1.Text = "Funky words, please replace."
> > Else
> > Label1.Text = "Okay." 'This is just included for testing
> > End If
> > End Sub
> > Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > CheckString(TextBox1.Text)
> > End Sub
> > Any suggestions will be greatly appreciated!
> > --
> > Sandy
>

Please evaluate C# code - Beginner level

I have recently, with the help of Fishcake and Sevenhalo, figured out how to connect to a SQL Server and retrieve some data.

In order to expand my knowledge, my goal is to write a class that will encapsulate this code. I understand that writing a class for my tiny website may be a bit excessive, but its more for the knowledge of "how-to" than practicality.

The class that I have written does somewhat work:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;

public class Database
{

private String DatabaseConnectionString = "Data source=*;" +
"Database=*;" +
"uid=*;" +
"pwd=*";

private SqlConnection objConnection;
private SqlCommand objCommand;
public SqlDataReader objReader;
public String dbError;



public String GetConnectionString()
{
return DatabaseConnectionString;
}

private SqlConnection CreateConnection()
{
SqlConnection objConnection = new SqlConnection(DatabaseConnectionString);
return objConnection;
}

private SqlCommand CreateCommand(String p_Command, SqlConnection p_Connection)
{
SqlCommand objCommand = new SqlCommand(p_Command, p_Connection);
return objCommand;
}

//Article Related
public void GetArticleByID(String p_CategoryID, String p_ArticleID)
{
objConnection = CreateConnection();
objCommand = CreateCommand("SELECT * FROM tblArticle " +
"WHERE tblArticle.charArticleID=@dotnet.itags.org.Article " +
"AND tblArticle.charCategoryID=@dotnet.itags.org.Category", objConnection);

SqlDataReader objReader;

try
{
objConnection.Open();
objCommand.Parameters.AddWithValue("@dotnet.itags.org.Article",p_ArticleID);
objCommand.Parameters.AddWithValue("@dotnet.itags.org.Category",p_CategoryID);

objReader = objCommand.ExecuteReader();


}
catch(System.Exception ex)
{
dbError = ex.Message;
objReader= null;
}


}

//End Articles
}

The class is used like this:

<script runat="server" language="c#">



protected void Page_Load(Object sender, EventArgs e)
{
String strCategoryID = Request.QueryString["ci"];
String strArticleID = Request.QueryString["ai"];


Database objDatabase = new Database();
objDatabase.GetArticleByID(strCategoryID,strArticleID);

if(objDatabase.objReader != null)
{
while(objDatabase.objReader.Read());
{
label1.Text += objDatabase.objReader["charTitle"].ToString();
}
}
else
label1.Text = objDatabase.dbError;

}

</script>

Question 1: Is my method even correct? Am I taking the right approach to this?

I'm trying to create shortcuts by making functions that create the connectionstring and command for me without me having to type it out each time. The idea behind the class is that, it will do all the work for me and store a SqlDataReader object in itself, that I will then manipulate in my Page_Load event.

Any input in regards to this question is greatly appreciated. Thanks!What you've created is called a DAL - Data Access Layer. It's a class which encapsulates the database-specific methods. You're doing fine. Your approach is right, but the datareader isn't required here. In addition, your GetArticleById method is returning void. So, you need to make it return a dataset, and change its function signature to return a dataset.

In the code that calls this method, assign a dataset to the method, and use that dataset to... whatever.
when is it best to use the DataAdapter/DataSet approach and when is it best to use a DataReader?

I mean the DataAdapter/DataSet just seems like the long way instead of just using a DataReader.
It depends on what you need... if you need to get some records, manipulate the data in memory and then send the changes back, a DataSet/Table would be the candidate. But if you are doing something like filling a combobox, then a Reader is ideal. Any time you need to loop through the data quickly and use it for something other than modifying the data, odds are, a reader will suffice. They come at a small price: 1) they create an exclusive lock on the connection, meaning you cannot use it for anything else. If you need to connect to do another db operation, a second connection will be needed. 2) They are read-only and forward only. You can't change the data and cannot move backwards in the data. But that's also where thier power comes from. By being what's called a Firehose cursor, it is very fast and efficient.

-tg
awesome... that is great to know, thanks tg!
I'll add to that. In a situation when you need to work with and update a very, very, very large set of data, do not use a dataset. Instead, use a datareader, and use separate code for the database manipulation.
Mendhak & TechGnome,

Thanks so much for the reply. Your opinions are appreciated!

In addition, your GetArticleById method is returning void.

This is true. I actually changed the code without making the correct change in my question. Instead of returning something, I attached the Datareader to the object itself.

Instead of doing:
DataReader MyObject = GetArticleByID(X,Y)

I am manipulating the DataReader as part of the object:
objDatabase.DataReader

I think this is the best way to do it. I will update my initial post.

but the datareader isn't required here

I guess I'm a little confused about what TechGnome said.

t depends on what you need... if you need to get some records, manipulate the data in memory and then send the changes back, a DataSet/Table would be the candidate. But if you are doing something like filling a combobox, then a Reader is ideal.

Since in the example I am only getting one article, its title, and the picture that is associated with it, would a DataReader not be the best? I only need a read only connection that retrieves data, I do not manipulate it in any way.

It seems to me that the dataset would be more appropriate for functions that modify the data such as:
AddNewArticle(X,Y);
EditArticle(X,Y);

Thanks again for the replies.
Actualy if all you are returning is a single record... you should look into using output parameters and use the ExecuteNonQuery method.

-tg
Since in the example I am only getting one article, its title, and the picture that is associated with it, would a DataReader not be the best?

Nope. A dataset would be ideal here. You have a chunk of text, a string, and an image. You are not moving anywhere within the data. So, you need a dataset.

Have your method GetArticleById() return a dataset.
Got it, thanks for the replies all. I will use a DataSet!

Please explain Delegates

Can someone pls explain the concept of delegates in laymans terms. Code samples in VB will be most helpful as I am having a lot of trouble understanding this subject.Delegates are objects with one the most important method. You may think of it by namecall();

if you wnat a method of one object to be called by third object. you give to this third object delegate to the method of the first object.
Hi,

Delegates are like function pointers in C++. They are used to pass the functions as parameter to the other function. There are so many articles on this topic. please visit
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=141

Thanks,
Sridhar!!

Please explain what "Empty path has no directory" means with Server.MapPath

Hello,

I have the following line of code in a script...

litMsg.Text = Server.MapPath("/");

where litMsg is an ASP.Net Literal control. When I try and run this
page, I get the error ...

System.ArgumentException: Empty path has no directory.

Anyone any idea what this means? I have used Server.MapPath many times
before without error, I'm not sure why it suddenly stopped working here.

I'm sure I'm missing something blindingly obvious and would be grateful
if anyone could point it out!! TIA.

--
Alan Silver
(anything added below this line is nothing to do with me)IN case it's of any use to anyone, I found out that the problem was
caused by me having the following two lines in Page_Load...

HttpContext myContext = HttpContext.Current;
myContext.RewritePath("/");

I'm not actually sure *why* I had those lines there, they must have been
from something I was doing before. As soon as I removed them, the
Server.MapPath worked fine.

If anyone has an explanation, I would like to hear it ;-)

>Hello,
>I have the following line of code in a script...
>litMsg.Text = Server.MapPath("/");
>where litMsg is an ASP.Net Literal control. When I try and run this
>page, I get the error ...
>System.ArgumentException: Empty path has no directory.
>Anyone any idea what this means? I have used Server.MapPath many times
>before without error, I'm not sure why it suddenly stopped working here.
>I'm sure I'm missing something blindingly obvious and would be grateful
>if anyone could point it out!! TIA.

--
Alan Silver
(anything added below this line is nothing to do with me)

Monday, March 26, 2012

please help

hi i am using a word application to get data from a word file, i use the following code to open the word application and document:

Dim objWord As New Word.Application
Dim docNew As New Word.Document

and i am using the following code to close and quit the applications:

'Close the Automation object
objWord.Quit()
' Cleanup the unmanaged objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWord)

but when i look at the processes in my task manager winword.exe with username asp.net never ends, and the more i run the application, the more winword.exe's that open. Am i trying to close it wrong?
thanks in advance for any help!I'm not familiar with using word with ASP.NET, but after you release the object you should set it = nothing. This marks the object for garbage collection and allows the object to be destroyed.
You need to do:

docNew.Close(Word.wdSaveOptions.wdDoNotSaveChanges)
Marshal.ReleaseComObject(docNew)
docNew = nothing

objWord.Quit(Word.wdSaveOptions.wdDoNotSaveChanges)
Marshal.ReleaseComObject(objWord)
objWord = nothing

Brian
Thanks a million, that works perfectly! thanks for your help!

Please help

I am completely perplexed as to why the code below is not functioning. Let me clarify that, the first portion of the code below is working just fine, meaning the "For Next" loop, but the code that is supposed to execute the Stored Procedure isn't even firing. I know that the code isn't making the request to the database because I asked our SQL Admin to turn Trace on and watch for the request. I know that my connection string to the Database is fine because I use this code elsewhere without any problems.

Any assistance would be very much appreciated. Thanks.


Public Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
'Build list of message recipients
Dim dlItem As DataListItem
Dim Recipients As String
For Each dlItem In dtlAssocList.Items
Dim chbSelAssoc As CheckBox = CType(dlItem.FindControl("chbSelAssoc"), CheckBox)
If chbSelAssoc.Checked = True Then
Dim lblAssocCode As Label = CType(dlItem.FindControl("lblAssocCode"), Label)
Recipients += lblAssocCode.Text + ","
End If
Next dlItem

'Check to see if the SelectAll checkbox is checked.
Dim SelectAll As String
If chbSelectAll.Checked = True Then
SelectAll = "1"
Else
SelectAll = "0"
End If

Dim cnnConnection As System.Data.SqlClient.SqlConnection
Dim connString2 As String = ConfigurationSettings.AppSettings("connString2")
Dim cmdCommand As System.Data.SqlClient.SqlDataAdapter

cnnConnection = New System.Data.SqlClient.SqlConnection(connString2)
cmdCommand = New System.Data.SqlClient.SqlDataAdapter("wpsp_MM_I_Message", cnnConnection)

cmdCommand.SelectCommand.CommandType = CommandType.StoredProcedure

cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.msg_title", SqlDbType.VarChar, 50))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.msg_title").Value = txbMsgTitle.Text
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.msg_text", SqlDbType.VarChar, 500))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.msg_text").Value = txbMessageText.Text
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.sendAll", SqlDbType.Bit, 1))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.sendAll").Value = SelectAll
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.AssocList", SqlDbType.VarChar, 4000))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.AssocList").Value = Recipients

Response.Redirect("ManagersMessage.aspx")
End Sub

Hmmm, ... where do you execute your command? It seems that you forgot the execution of the command.
You are not aactually doing anything here. You are setting parameters, and then doing nothing. You never open the connection or fill a dataset or anything.

You should debug the application (if using VS.NET) or otherwise, you can use tracing or even Response.Write() to see where you are going.

What are you indending to do?
The 'wpsp_MM_I_Message' Stored Procedure takes the variables that I pass to it and then executes another Stored Procedure (behind the scenes).

What code do I need to include to get the 'wpsp_MM_I_Message' Stored Procedure to execute?
Presuming this returns no records:


Dim cnnConnection As System.Data.SqlClient.SqlConnection
Dim connString2 As String = ConfigurationSettings.AppSettings("connString2")
Dim cmdCommand As System.Data.SqlClient.SqlCommand

cnnConnection = New System.Data.SqlClient.SqlConnection(connString2)
cmdCommand = New System.Data.SqlClient.SqlDataAdapter("wpsp_MM_I_Message", cnnConnection)

cmdCommand.CommandType = CommandType.StoredProcedure

cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.msg_title", SqlDbType.VarChar, 50))

cmdCommand.Parameters("@.msg_title").Value = txbMsgTitle.Text

cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.msg_text", SqlDbType.VarChar, 500))
cmdCommand.Parameters("@.msg_text").Value = txbMessageText.Text

cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.sendAll", SqlDbType.Bit, 1))
cmdCommand.Parameters("@.sendAll").Value = SelectAll
cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.AssocList", SqlDbType.VarChar, 4000))
cmdCommand.Parameters("@.AssocList").Value = Recipients

cmdCommand.ExecuteNonQuery()

Note cmdCommand is changed into a SqlCommand object rather than a SqldataAdapter

if it returns records, you could either create a SQLDataReader or a Dataset
That's what I needed. Thank you very much.

Please help - CLR Debugger and ASP code

Hi all,
I'm not able to use CLR debugger to step into the asp code the way I'm
debugging my asp.net code. I wonder if even this is doable and if not what
are my other options for debugging asp code.
Thanks in advance,
RoyASP code is not managed code. The CLR debugger applies to managed code only.
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @. www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
----
"Roy" <Roy@.discussions.microsoft.com> wrote in message
news:21CB3F36-69D3-4EA8-AFDA-D884915ACA44@.microsoft.com...
> Hi all,
> I'm not able to use CLR debugger to step into the asp code the way I'm
> debugging my asp.net code. I wonder if even this is doable and if not what
> are my other options for debugging asp code.
> Thanks in advance,
> Roy
Alvin,
Is any other tool for dubugging asp code beside Visual Studio itself?
"Alvin Bruney - ASP.NET MVP" wrote:

> ASP code is not managed code. The CLR debugger applies to managed code onl
y.
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
> [Shameless Author plug]
> The Microsoft Office Web Components Black Book with .NET
> Now Available @. www.lulu.com/owc
> Forth-coming VSTO.NET - Wrox/Wiley 2006
> ----
>
> "Roy" <Roy@.discussions.microsoft.com> wrote in message
> news:21CB3F36-69D3-4EA8-AFDA-D884915ACA44@.microsoft.com...
>
>

Please Help - HW question

Go here:
http://sb.pch.com/cat/05/01-55/mult...hmail.com&ti=mr.

There is one line of code that needs to be changed in order to accommodate a
new feature. In order to allow us to accept the character "$" in the
address1 field, what is the single line of code that would have to be
updated to correctly validate the address1 field when the submit button is
clicked. Hint: this information is 100% within your attainable view based on
the information provided.Why shall I go there?

Eliyahu

"giganews" <rob012669@.inbox.com> wrote in message
news:jYKdnRje3IuM0VbfRVn-3w@.rcn.net...
> Go here:
http://sb.pch.com/cat/05/01-55/mult...hmail.com&ti=mr.
> There is one line of code that needs to be changed in order to accommodate
a
> new feature. In order to allow us to accept the character "$" in the
> address1 field, what is the single line of code that would have to be
> updated to correctly validate the address1 field when the submit button is
> clicked. Hint: this information is 100% within your attainable view based
on
> the information provided.

Please Help - HTML parsing

Hi all, i am writing an application where you can view the html code of a webpage (URL), i am using j#. does anyone know how i would go about doing this. any help would be appreciated. thanks all!Hi,
you can use Server.HtmlEncode(yourstring) for this.
Grz, Kris.
Thanks for that,
lets say i wanted to return the HTML of http://www.google.com , how exactly would i do that. thanks again for you help
Hi,
this is known as "screen scraping". Take a look at this article:Screen Scraping with ASP.NET
Grz, Kris.
Take a look at this posting:
http://forums.asp.net/1092188/ShowPost.aspx

Please help - retrieving session variable before pageload sub

I have the following code where I need to get the data from a session variable before I've done the page load. I can't seem to do this without getting the following message:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive.

I am using session variables fine in other parts of the program but I'm reading them after the page load.


<%@dotnet.itags.org.Import Namespace="System.data.SqlClient" %>
<%@dotnet.itags.org.Import Namespace="System.data" %>
<script runat="server">
Dim SQLCmd as string
Dim dbConn = Session("UserConnectionString")
Sub Page_Load
...

Thanks!Just set the enableSessionState to true.

If that dosen't work, just pass the conn string in to the URL, less secure though.
Thanks for the reply! I can't use a querystring in this instance and I've tried putting a PAGE directive with enablesessionstate but it didn't work. The session variable becomes available after the pageload so I think that session state is enabled.

Any more help would be greatly appreciated!

PLEASE help - simple problem

The problem I am having is actually easier to explain if you look at my code, so I'll start there (note: this is coded in whidbey - but I thought this question would be more appropriate here than the 2.0 forum)

<cod>
Function GetValue(ByVal field As String, ByVal type As String) As String

Dim value As String = ""

If (type = "Text") Then
value = CType(MyFormView.FindControl("HomeWidthText"), TextBox).Text.ToString
'value = CType(MyFormView.FindControl(field), TextBox).Text.ToString
End If
...
Return value
End Function

Sub validateAllFields()
If (GetValue("HomeWidthText", "Text") = "") Then
...
End If
...
End Sub
</code
So, what's not working about that code you might ask? Well, absolutely nothing if you run the code as is. Now, replace the green with the red and you get the following error:
"Object reference not set to an instance of an object."

What? That doesn't make any sense at all to me as field is set to a string and is exactly that - "HomeWidthText". I just don't get it.

Aaroninstead of:
Function GetValue(ByVal field As String,

make field a control, in the function instead of a string
That would makes sense but that ignores the whole intention of that function...to reduce code!

You see, I didn't want to consistently have to write the following...


Dim homeWidth As String = GetValue(CType(MyForm.FindControl("HomeWidthText"), Control), "Text")

There are literally hundreds of these and I want to be able to do something like

Dim homeWidth As String = GetValue("HomeWidthText", "Text")

And, it should take the "Text" parameter and determine that it is dealing with a text field and do that appropriately.

Can this not be done in ASP.Net 2.0?

Aaron

Saturday, March 24, 2012

Please Help - Where is the mistake in my code

Hi all

When I run this app, select the checkbox and press the calculate button i get the following error:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] nihe.SimpleRent.calculate(Object source, EventArgs e) +173 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292

My code is as follows, does anyone know what i have done wrong, any help/advice would be very much appreciated.

<%@dotnet.itags.org. Page Language="VB" Debug="true"Inherits="nihe.SimpleRent" ContentType="text/html" ResponseEncoding="iso-8859-1" %><html><body> <form runat="server"> Bathroom with W/C: <asp:CheckBox id="bath_wc" runat="server"></asp:CheckBox> <p> <asp:button id="calcbutton" onclick="calculate" runat="server" text="calculate"></asp:button> </p> </form></body></html>
' SimpleRent.vb'Imports SystemImports System.WebImports System.Web.UIImports System.Web.UI.WebControlsNamespace nihePublic Class SimpleRent : inherits page protected withevents bath_wcAs system.web.ui.webcontrols.checkbox protected withevents row_bwcAs system.web.ui.webcontrols.TableRowPublic sub calculate(source asObject, e as EventArgs) if bath_wc.checked then bath_wc.text ="+3" Context.Items.Add("bath_wc", bath_wc.text) row_bwc.Visible = bath_wc.checked end ifserver.transfer("SimpleResult.aspx")End SubEnd ClassEnd Namespace
<%@dotnet.itags.org. Page Language="vb" %><script runat="server">Sub Page_Load(Source asObject, E as EventArgs) cell_bwc.text ="Bathroom With WC" value_bwc.text = Context.Items("bath_wc")End Sub</script><html><body><form> <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table></form></body></html>

Where did you get this code from?

<html>
<body>
<form>
<asp:Table runat="server">
<asp:TableRow id="row_bwc">
<asp:TableCell id="cell_bwc"></asp:TableCell>
<asp:TableCell id ="value_bwc"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>

I see 2 html parts in the code you posted.

Thanks


Because your Calculate method is encapsulated in a page that does not exist. Therefore, "row_bwc" does not exist.

For some reason, it seems you have attempted to create an inheritable base page that is actually a "real" page?


Sorry should have been more specific.

The code show is actaully three seperate pages

page one, codebehind for page one and results page.

Hope this clarifies things

Sorry

Kevin


The last line of your Calculate method attempts to executerow_bwc.Visible = bath_wc.checked. No instance of row_bc has been created. Therefore,row_bc is a null reference.

Remember, there's no row_bc on page one. It's only on the results page.


Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin


It seems you mix 2 web pages.You have 2 webpages A and B,you can only access controls of A in codebehind of A.

"So where do i need to reference row_bwc and how do it do it?"

You have 2 choice .

1: Combine page one and result page to a single page.That means add:

 <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table>

to page one and don't forget add code in pageload to page one. Then use YourControl.visible to display or hide controls.

2: pass parameter (like row_bwc.Visible,etc )to SimpleResult.aspx then do the action within SimpleResult.aspx.


Kipster:

Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin

You need to pass the value to set the visibility of row_bwc to the SimpleResult page. You could do this in one of the many ways that you would normally pass values between pages -- like in a QueryString, or drop the Server.Transfer and do a crosspost instead. Let me know if you need an example.

please help + impersonate problem

Hi

Using this code I am try to imperosnate the user.

I did the sample page using this code, thats working fine. When i try place
this code into my existing application its working fine when I HARD CODED THE
USER NAME AND PASSWORD. if I pass the user name and password as variable
string, the imepersonate got failed.

Please help me.. its very urgent...

http://support.microsoft.com/defaul...B;EN-US;Q306158Hi Bala,

Can you post your code assigning the username and password? It's possible
you are making a minor syntax error or other mistake there. Also, you can
check in debug mode to make sure the username and password being passed are
the same as your hardcoded values.

--

Joshua Mitts
joshrm@.msn.com

"Bala" <Bala@.discussions.microsoft.com> wrote in message
news:A538D982-0140-435F-92A1-15FE30E119FE@.microsoft.com...
> Hi
> Using this code I am try to imperosnate the user.
> I did the sample page using this code, thats working fine. When i try
> place
> this code into my existing application its working fine when I HARD CODED
> THE
> USER NAME AND PASSWORD. if I pass the user name and password as variable
> string, the imepersonate got failed.
> Please help me.. its very urgent...
>
> http://support.microsoft.com/defaul...B;EN-US;Q306158

Please Help DDL

I have code that populated a drop down list and with the users selection in the ddl it populates the text fields. This works fine with one exception

The first record in the Drop Down List doesn't populate at all... Please help....I should explain a little better

Here is a snippett from both pages the user selects the item in the drop down menu then they are rerouted to another page than takes that value and populates the textboxes

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim mystring As String = DropDownList1.SelectedItem.Text
'passing the variable to the next page
Response.Redirect("WebForm2.aspx?mystring=" & DropDownList1.SelectedValue)
End Sub

' this is the second page where it takes that variable and populates the textboxes
'then I am populating the texboxes based on the selectedtext in a fillbox() function

Sub fillBox()
Dim ds As New DataSet

Dim myCommand As OleDbDataAdapter
Dim smyString As String

'retreiving the variable passed from page 1 using the drop down list
smyString = Request.QueryString("mystring")

'code ot take out an apapostrophe
smyString = Replace(smyString, "'", "''")

sql = "Select * From SiteDocNew where [River/Site Name_en] ='" & smyString & "'"
myCommand = New OleDbDataAdapter(sql, conn)

'Fill command to fill the textboxes
myCommand.Fill(ds, "SiteDocNew")
txtLocationDesc.Text = ds.Tables("SiteDocNew").Rows(0).Item("Location & Access Description_en").ToString()
Is the 2nd page not working?
The second page is working with all other records with the exception of the first record on the drop down list.

And if I do click on the first record the second page does not even open...
Sorry I figured it out I just added a null line in the drop down list...

Please help how to call stored procedure from asp.net code

Please help, first time trying to use the stored procedure.

Can you please modify my code below which is in asp.net to insert the record's in table(tbl_labels), i don't have not problem in inserting records, but i want to use my stored procedure to insert the record. Please help I never used a stored procedure.

**********


CREATE PROCEDURE sp_insert_label
(
@dotnet.itags.org.engl nvarchar,
@dotnet.itags.org.espl nvarchar,
@dotnet.itags.org.frlbl nvarchar,
@dotnet.itags.org.gerlbl nvarchar
)
AS
INSERT INTO tbl_labels
(
eng_lbl,
esp_lbl,
fr_lbl,
ger_lbl
)
VALUES
(
@dotnet.itags.org.engl,
@dotnet.itags.org.espl,
@dotnet.itags.org.frlbl,
@dotnet.itags.org.gerlbl
)
GO

********** the following is my asp.net code***

Sub Addlabel_Click(Sender As Object, E As EventArgs)
Page.Validate()
If Not Page.IsValid
Return
End If

Dim DS As DataSet
Dim MyCommand As SqlCommand
Dim InsertCmd As String = "insert into tbl_labels(eng_lbl, esp_lbl, " & _
"fr_lbl, ger_lbl) values " & _
"(@dotnet.itags.org.engl, @dotnet.itags.org.espn, @dotnet.itags.org.fren, @dotnet.itags.org.german)"

MyCommand = New SqlCommand(InsertCmd, MyConnection)

MyCommand.Parameters.Add( "@dotnet.itags.org.engl", eng_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.espn", esp_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.fren", fr_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()
ger_lbl.Value = ""
fr_lbl.Value = ""
esp_lbl.Value = ""
eng_lbl.Value = ""

Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the " & _
"same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record, please ensure " & _
"the fields are correctly filled out"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()
BindGrid()
End Sub

Hi,

Dim DS As DataSet

Dim MyCommand As SqlCommand

Dim pmEngl, pmEspn, pmFren, pmGerman As SqlParameter = New SqlParameter()

MyCommand = New SqlCommand("sp_insert_label", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure;

pmEngl = MyCommand.Parameters.Add( "@.engl", eng_lbl.Value )

pmEspn = MyCommand.Parameters.Add( "@.espn", esp_lbl.Value )

pmFren = MyCommand.Parameters.Add( "@.fren", fr_lbl.Value )

pmGerman = MyCommand.Parameters.Add( "@.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try

MyCommand.ExecuteNonQuery()

Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()

ger_lbl.Value = ""

fr_lbl.Value = ""

esp_lbl.Value = ""

eng_lbl.Value = ""

hope it helps.
You can add parameters to stored procedures in different ways:

One of the useful way is:

myCommand.Parameters.Add(new SqlParameters("@.ParameterName",SqlDbType.nvarchar,50));
Thank you very much for your help Harish.

Please Help how do I Microsoft.XMLHTTP in .net

I am using the following code to parse a .txt file from a remote server using asp

set xml1 = CreateObject("Microsoft.XMLHTTP")
xml1.Open "GET", strURL, False
xml1.send
strXmlContents = xml1.responseText

how do I do this in .aspx?with the HTTPWebRequest class. here :

http://rtfm.atrax.co.uk/infinitemonkeys/articles/asp.net/990h.asp
That looks really nice for an advanced programer but I am completly lost. Is that in c#?

<%@. import namespace="System.Net" %>
WebClient objClient = new WebClient();
private void Page_Load(Object o, EventArgs e){
WebClient objClient = new WebClient();
}

private void Page_Load(Object o, EventArgs e){
WebClient objClient = new WebClient();
Stream objStream = objClient.OpenRead("http://lycosa/default.asp");
}

Is this all I need? what do I save this as?
> Is this all I need?

not quite. this is the code you need, sure, but you need to fill in a few bits round it. I take it you're a raw novice then?
I think I got thst part

<%@. import namespace="System.IO" %>
<%@. Control Language="vb" debug="true" Codebehind="Live Lines.ascx.vb" %>
<HTML>
<HEAD>
<title>Messing around with ASP.NET in VB</title>
</HEAD>
<body>
<script language="VB" runat="server"
Public Sub Page_Load()
Dim fileName as String
fileName = "C:\schedule.txt"
Dim strmR as StreamReader = File.OpenText(fileName)
lblStart.Text = Server.HtmlEncode(strmR.ReadToEnd()).Replace(vbcrlf, "<br />")
strmR.Close()
End Sub

</script>
<asp:label runat="server" id="lblStart" font-name="verdana" />
</body>
</HTML
This seems to work for me. 2 questions

1. How can I change this fileName = "C:\schedule.txt" for non local files? Like this, fileName = "http://blah/schedule.txt" ?
2. My information is now displayed like this
1| 1|20030915|18:05|DALLAS |219| 37|
1| 1|20030915|18:05|NY GIANTS |220| 7|

How do I convert this to xml and display it if I know the name for each category?
Yes I am a super nooob
Anyone have a suggestion?
You're going to need to split the delimited file first at the linebreaks, then at the pipe characters (|), then you'll be able to loop through the resulting arrays and stick them in an XML document.

I'll scout around and see if there's a tutorial on it somewhere, but equally there may be a library for this task on this very site...

Please Help me Optimize my Code

Hello all,

I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored
with specific RGB values in separate columns. A user sees all the
colors listed on the page with hyperlinks that open the "mixes" page.
The mixes page goes through each record, compares it with all other
records in a ratio up to "maxratio". If it finds a ratio that matches
the redvalue of the chosen color, it checks the green and blue as
well. If it's a close match, within "maxdiff" tolerance, it writes
that combo to the page. The code works on my development p4 laptop,
1gb ram, running xppro and developing with VWDEx05. The problem is
that it takes 2.5 minutes to run it. The resulting page isn't huge,
it just takes a long time to get there. This is going on a free host
so I can't change any server settings. I used stringbuilder and put
andalso where I thought it would help but now I don't know what to
do. Please, any help you can give to streamline this will be greatly
appreciated. And of course if it's a hopeless effort, I'd like to
hear any alternatives to get the same sort of results. My code is
below. Thanks very much for any advice you can give.

TF

<%@dotnet.itags.org. Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

'coming from PM page w/querystring vals - make sure the're
what is expected.
'if not, bail out of the page load sub
'should be 4 values: r,g,b,id. r,g,b must be between (not
equal) 0 and 256.
If Request.QueryString.Count <4 _
Or Request.QueryString("red") < 0 Or
Request.QueryString("red") 255 _
Or Request.QueryString("green") < 0 Or
Request.QueryString("green") 255 _
Or Request.QueryString("blue") < 0 Or
Request.QueryString("blue") 255 Then

'bail from the page load sub
Exit Sub

Else

'dim all variables first
Dim startRed, testRed, compRed1, compRed2 As Integer
Dim compFactor1, compFactor2 As Integer
Dim startGreen, testGreen, compGreen1, compGreen2 As
Integer
Dim startBlue, testBlue, compBlue1, compBlue2 As Integer
Dim maxRatio, maxDiff As Integer
Dim Rows1, Rows2 As Integer
Dim startID As Integer

Dim usedIDStr As String = "xxxxxxxxxxx"
Dim testIDStr1 As String = "" 'id pairs
Dim testIDStr2 As String = "" 'id pairs reversed

'create the stringbuilder objects
Dim testID1 As New Text.StringBuilder(15)
Dim testID2 As New Text.StringBuilder(15)
Dim usedIDs As New Text.StringBuilder(500)

'starting r,g,b,id; get from querystring
startRed = Request.QueryString("red")
startGreen = Request.QueryString("green")
startBlue = Request.QueryString("blue")
startID = Request.QueryString("id")

'max ratio of comparison. too high and this REALLY crawls
maxRatio = 8

'max diff from start color for display: tolerance window
maxDiff = 3

'the database connction stuff
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=C:\Inetpub\WebSite1\App_Data\PaintsDbase.md b"
Dim myConn As Data.OleDb.OleDbConnection = New
Data.OleDb.OleDbConnection(myConnString)
Dim mySQLText As String = "SELECT [id],[brand],[redvalue],
[greenvalue],[bluevalue],[thinnedby] FROM [Allpaints] "
Dim myCmd1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(mySQLText, myConn)
myConn.Open()

'QUERIED COLUMN ORDNALS
'0 - ID; 1 - BRAND; 2 - REDVALUE; 3 - GREENVALUE; 4 -
BLUEVALUE; 5 - THINNER

'dim myReader1 for the outside loop; forward moving only
Dim myReader1 As Data.OleDb.OleDbDataReader =
myCmd1.ExecuteReader()

'dim and fill myDataSet2 for the inside loop; need to go
both directions
Dim dataAdapter As New
System.Data.OleDb.OleDbDataAdapter(mySQLText, myConn)
Dim myDataSet2 As System.Data.DataSet = New
System.Data.DataSet
Dim myDS2Row As System.Data.DataRow
dataAdapter.Fill(myDataSet2)

'start first/outside reader loop
While myReader1.Read()

'this loops through each record
For Rows1 = 0 To myReader1.FieldCount - 1

'get comp color values for the current OUTSIDE
loop record
compRed1 =
myReader1.Item(myReader1.GetOrdinal("redvalue"))
compGreen1 =
myReader1.Item(myReader1.GetOrdinal("greenvalue"))
compBlue1 =
myReader1.Item(myReader1.GetOrdinal("bluevalue"))

'the actual inside looper; goes through each
myDataSet2 record
For Each myDS2Row In myDataSet2.Tables(0).Rows

'get comp color values for the current INSIDE
loop
compRed2 = myDS2Row.Item(2)
compGreen2 = myDS2Row.Item(3)
compBlue2 = myDS2Row.Item(4)

'first/outside ratio loop
For compFactor1 = 1 To maxRatio

'second/inside ratio loop
For compFactor2 = 1 To maxRatio

'the math to get testRed, testGreen,
testBlue based on current ratios
testRed = ((compRed1 * compFactor1) +
(compRed2 * compFactor2)) / (compFactor1 + compFactor2)
testGreen = ((compGreen1 *
compFactor1) + (compGreen2 * compFactor2)) / (compFactor1 +
compFactor2)
testBlue = ((compBlue1 * compFactor1)
+ (compBlue2 * compFactor2)) / (compFactor1 + compFactor2)

If (testRed < startRed + maxDiff And
testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen +
maxDiff And testGreen startGreen - maxDiff) _
AndAlso (testBlue < startBlue +
maxDiff And testBlue startBlue - maxDiff) Then

'use stringbuilder to create fwd/
rev ID pairs to test against used pairs
testID1.Remove(0,
testID1.Length())
testID1.Append("::" &
myReader1.Item(myReader1.GetOrdinal("id")) & ":" & myDS2Row.Item(0) &
"::")
testID2.Remove(0,
testID2.Length())
testID2.Append("::" &
myDS2Row.Item(0) & ":" & myReader1.Item(myReader1.GetOrdinal("id")) &
"::")

'the inner/outer brand should be
the same and block out already displayed combos
'at least for now;later we can
maybe turn on mixed brand recipes
If
myReader1.Item(myReader1.GetOrdinal("brand")) = myDS2Row.Item(1) _
AndAlso
myReader1.Item(myReader1.GetOrdinal("id")) <startID _
AndAlso myDS2Row.Item(0) <>
startID _
AndAlso
usedIDs.ToString().IndexOf(testID1.ToString()) = -1 _
AndAlso
usedIDs.ToString().IndexOf(testID2.ToString()) = -1 Then

usedIDs.Append(testID1.ToString())

'the ligter/darker flag
If testRed startRed And
testGreen startGreen And testBlue startBlue Then
Response.Write("Slightly
Lighter than chosen color<BR>")
ElseIf testRed < startRed And
testGreen < startGreen And testBlue < startBlue Then
Response.Write("Slightly
Darker than chosen color<BR>")
End If

Response.Write("testred
= " & testRed & "<br>")
Response.Write("testgreen
= " & testGreen & "<br>")
Response.Write("testblue
= " & testBlue & "<br>")

Response.Write(myReader1.Item(1) & "<br>")
Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " & compRed1 & "<br>")
Response.Write("compgreen1
= " & compGreen1 & "<br>")
Response.Write("compblue1
= " & compBlue1 & "<br>")

Response.Write(myDS2Row.Item(1) & "<br>")
Response.Write("compfact2
= " & compFactor2 & "<br>")
Response.Write("compred2
= " & compRed2 & "<br>")
Response.Write("compgreen2
= " & compGreen2 & "<br>")
Response.Write("compblue2
= " & compBlue2 & "<br><br><br>")
End If

End If

Next compFactor2

Next compFactor1

Next myDS2Row

Next Rows1

End While

End If

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: x-small; font-family: Verdana">
<form id="form1" runat="server">
<div>
Mixer Results<br />
<br />

</div>
</form>
</body>
</html>Aside from the fact that you are using MS Access, I don't see anywhere in
your sample code where you are closing your connections or DataReaders. If
you get all your data into memory (dataSets, not readers) you will only need
to get it once and then you can do all your manipulations without open
connections.
If that helps, then you can optimize more by using databinding to controls
rather than a series of Response.Write's .
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"TF" wrote:

Quote:

Originally Posted by

Hello all,
>
I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored
with specific RGB values in separate columns. A user sees all the
colors listed on the page with hyperlinks that open the "mixes" page.
The mixes page goes through each record, compares it with all other
records in a ratio up to "maxratio". If it finds a ratio that matches
the redvalue of the chosen color, it checks the green and blue as
well. If it's a close match, within "maxdiff" tolerance, it writes
that combo to the page. The code works on my development p4 laptop,
1gb ram, running xppro and developing with VWDEx05. The problem is
that it takes 2.5 minutes to run it. The resulting page isn't huge,
it just takes a long time to get there. This is going on a free host
so I can't change any server settings. I used stringbuilder and put
andalso where I thought it would help but now I don't know what to
do. Please, any help you can give to streamline this will be greatly
appreciated. And of course if it's a hopeless effort, I'd like to
hear any alternatives to get the same sort of results. My code is
below. Thanks very much for any advice you can give.
>
TF
>
<%@dotnet.itags.org. Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
>
'coming from PM page w/querystring vals - make sure the're
what is expected.
'if not, bail out of the page load sub
'should be 4 values: r,g,b,id. r,g,b must be between (not
equal) 0 and 256.
If Request.QueryString.Count <4 _
Or Request.QueryString("red") < 0 Or
Request.QueryString("red") 255 _
Or Request.QueryString("green") < 0 Or
Request.QueryString("green") 255 _
Or Request.QueryString("blue") < 0 Or
Request.QueryString("blue") 255 Then
>
'bail from the page load sub
Exit Sub
>
Else
>
'dim all variables first
Dim startRed, testRed, compRed1, compRed2 As Integer
Dim compFactor1, compFactor2 As Integer
Dim startGreen, testGreen, compGreen1, compGreen2 As
Integer
Dim startBlue, testBlue, compBlue1, compBlue2 As Integer
Dim maxRatio, maxDiff As Integer
Dim Rows1, Rows2 As Integer
Dim startID As Integer
>
Dim usedIDStr As String = "xxxxxxxxxxx"
Dim testIDStr1 As String = "" 'id pairs
Dim testIDStr2 As String = "" 'id pairs reversed
>
'create the stringbuilder objects
Dim testID1 As New Text.StringBuilder(15)
Dim testID2 As New Text.StringBuilder(15)
Dim usedIDs As New Text.StringBuilder(500)
>
'starting r,g,b,id; get from querystring
startRed = Request.QueryString("red")
startGreen = Request.QueryString("green")
startBlue = Request.QueryString("blue")
startID = Request.QueryString("id")
>
'max ratio of comparison. too high and this REALLY crawls
maxRatio = 8
>
'max diff from start color for display: tolerance window
maxDiff = 3
>
'the database connction stuff
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=C:\Inetpub\WebSite1\App_Data\PaintsDbase.md b"
Dim myConn As Data.OleDb.OleDbConnection = New
Data.OleDb.OleDbConnection(myConnString)
Dim mySQLText As String = "SELECT [id],[brand],[redvalue],
[greenvalue],[bluevalue],[thinnedby] FROM [Allpaints] "
Dim myCmd1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(mySQLText, myConn)
myConn.Open()
>
'QUERIED COLUMN ORDNALS
'0 - ID; 1 - BRAND; 2 - REDVALUE; 3 - GREENVALUE; 4 -
BLUEVALUE; 5 - THINNER
>
'dim myReader1 for the outside loop; forward moving only
Dim myReader1 As Data.OleDb.OleDbDataReader =
myCmd1.ExecuteReader()
>
'dim and fill myDataSet2 for the inside loop; need to go
both directions
Dim dataAdapter As New
System.Data.OleDb.OleDbDataAdapter(mySQLText, myConn)
Dim myDataSet2 As System.Data.DataSet = New
System.Data.DataSet
Dim myDS2Row As System.Data.DataRow
dataAdapter.Fill(myDataSet2)
>
'start first/outside reader loop
While myReader1.Read()
>
'this loops through each record
For Rows1 = 0 To myReader1.FieldCount - 1
>
'get comp color values for the current OUTSIDE
loop record
compRed1 =
myReader1.Item(myReader1.GetOrdinal("redvalue"))
compGreen1 =
myReader1.Item(myReader1.GetOrdinal("greenvalue"))
compBlue1 =
myReader1.Item(myReader1.GetOrdinal("bluevalue"))
>
'the actual inside looper; goes through each
myDataSet2 record
For Each myDS2Row In myDataSet2.Tables(0).Rows
>
'get comp color values for the current INSIDE
loop
compRed2 = myDS2Row.Item(2)
compGreen2 = myDS2Row.Item(3)
compBlue2 = myDS2Row.Item(4)
>
'first/outside ratio loop
For compFactor1 = 1 To maxRatio
>
'second/inside ratio loop
For compFactor2 = 1 To maxRatio
>
'the math to get testRed, testGreen,
testBlue based on current ratios
testRed = ((compRed1 * compFactor1) +
(compRed2 * compFactor2)) / (compFactor1 + compFactor2)
testGreen = ((compGreen1 *
compFactor1) + (compGreen2 * compFactor2)) / (compFactor1 +
compFactor2)
testBlue = ((compBlue1 * compFactor1)
+ (compBlue2 * compFactor2)) / (compFactor1 + compFactor2)
>
>
If (testRed < startRed + maxDiff And
testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen +
maxDiff And testGreen startGreen - maxDiff) _
AndAlso (testBlue < startBlue +
maxDiff And testBlue startBlue - maxDiff) Then
>
'use stringbuilder to create fwd/
rev ID pairs to test against used pairs
testID1.Remove(0,
testID1.Length())
testID1.Append("::" &
myReader1.Item(myReader1.GetOrdinal("id")) & ":" & myDS2Row.Item(0) &
"::")
testID2.Remove(0,
testID2.Length())
testID2.Append("::" &
myDS2Row.Item(0) & ":" & myReader1.Item(myReader1.GetOrdinal("id")) &
"::")
>
'the inner/outer brand should be
the same and block out already displayed combos
'at least for now;later we can
maybe turn on mixed brand recipes
If
myReader1.Item(myReader1.GetOrdinal("brand")) = myDS2Row.Item(1) _
AndAlso
myReader1.Item(myReader1.GetOrdinal("id")) <startID _
AndAlso myDS2Row.Item(0) <>
startID _
AndAlso
usedIDs.ToString().IndexOf(testID1.ToString()) = -1 _
AndAlso
usedIDs.ToString().IndexOf(testID2.ToString()) = -1 Then
>
>
usedIDs.Append(testID1.ToString())
>
'the ligter/darker flag
If testRed startRed And
testGreen startGreen And testBlue startBlue Then
Response.Write("Slightly
Lighter than chosen color<BR>")
ElseIf testRed < startRed And
testGreen < startGreen And testBlue < startBlue Then
Response.Write("Slightly
Darker than chosen color<BR>")
End If
>
Response.Write("testred
= " & testRed & "<br>")
Response.Write("testgreen
= " & testGreen & "<br>")
Response.Write("testblue
= " & testBlue & "<br>")
>
Response.Write(myReader1.Item(1) & "<br>")
Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " & compRed1 & "<br>")
Response.Write("compgreen1
= " & compGreen1 & "<br>")
Response.Write("compblue1
= " & compBlue1 & "<br>")
>
Response.Write(myDS2Row.Item(1) & "<br>")
Response.Write("compfact2
= " & compFactor2 & "<br>")
Response.Write("compred2
= " & compRed2 & "<br>")
Response.Write("compgreen2
= " & compGreen2 & "<br>")
Response.Write("compblue2
= " & compBlue2 & "<br><br><br>")
End If
>
End If
>
Next compFactor2
>
Next compFactor1
>
Next myDS2Row
>
Next Rows1
>
End While
>
End If
>
End Sub
</script>
>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: x-small; font-family: Verdana">
<form id="form1" runat="server">
<div>
Mixer Results<br />
<br />
>
</div>
</form>
</body>
</html>
>
>


TF, you have just a HUGE number of iterations happenning on the page - and
some of them are unnecessary. A few suggestions:

- create a vew on the datatable from the dataset
Dim myView As DataView = myDS2Row.Tables(0).DefaultView

and then on every reader row assign a filter to it:

myView.RowFilter = "brand='" & myReader1("brand").ToString & "' and id<>" &
myReader1("id").ToString

then instead of going though the whole table loop through the view rows

- instead of StringBuilders to keep IDs I would suggest using generic lists
of Integer:
Dim usedIDs As List(Of Integer) = New List(Of Integer)

then you could easily test whether an ID is already there (Contains method)
and add new ID (Add method)

Try that for a start, I may try to come up with a few more suggestions if I
have some more time...

"TF" wrote:

Quote:

Originally Posted by

Hello all,
>
I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored
with specific RGB values in separate columns. A user sees all the
colors listed on the page with hyperlinks that open the "mixes" page.
The mixes page goes through each record, compares it with all other
records in a ratio up to "maxratio". If it finds a ratio that matches
the redvalue of the chosen color, it checks the green and blue as
well. If it's a close match, within "maxdiff" tolerance, it writes
that combo to the page. The code works on my development p4 laptop,
1gb ram, running xppro and developing with VWDEx05. The problem is
that it takes 2.5 minutes to run it. The resulting page isn't huge,
it just takes a long time to get there. This is going on a free host
so I can't change any server settings. I used stringbuilder and put
andalso where I thought it would help but now I don't know what to
do. Please, any help you can give to streamline this will be greatly
appreciated. And of course if it's a hopeless effort, I'd like to
hear any alternatives to get the same sort of results. My code is
below. Thanks very much for any advice you can give.
>
TF
>
<%@dotnet.itags.org. Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
>
'coming from PM page w/querystring vals - make sure the're
what is expected.
'if not, bail out of the page load sub
'should be 4 values: r,g,b,id. r,g,b must be between (not
equal) 0 and 256.
If Request.QueryString.Count <4 _
Or Request.QueryString("red") < 0 Or
Request.QueryString("red") 255 _
Or Request.QueryString("green") < 0 Or
Request.QueryString("green") 255 _
Or Request.QueryString("blue") < 0 Or
Request.QueryString("blue") 255 Then
>
'bail from the page load sub
Exit Sub
>
Else
>
'dim all variables first
Dim startRed, testRed, compRed1, compRed2 As Integer
Dim compFactor1, compFactor2 As Integer
Dim startGreen, testGreen, compGreen1, compGreen2 As
Integer
Dim startBlue, testBlue, compBlue1, compBlue2 As Integer
Dim maxRatio, maxDiff As Integer
Dim Rows1, Rows2 As Integer
Dim startID As Integer
>
Dim usedIDStr As String = "xxxxxxxxxxx"
Dim testIDStr1 As String = "" 'id pairs
Dim testIDStr2 As String = "" 'id pairs reversed
>
'create the stringbuilder objects
Dim testID1 As New Text.StringBuilder(15)
Dim testID2 As New Text.StringBuilder(15)
Dim usedIDs As New Text.StringBuilder(500)
>
'starting r,g,b,id; get from querystring
startRed = Request.QueryString("red")
startGreen = Request.QueryString("green")
startBlue = Request.QueryString("blue")
startID = Request.QueryString("id")
>
'max ratio of comparison. too high and this REALLY crawls
maxRatio = 8
>
'max diff from start color for display: tolerance window
maxDiff = 3
>
'the database connction stuff
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=C:\Inetpub\WebSite1\App_Data\PaintsDbase.md b"
Dim myConn As Data.OleDb.OleDbConnection = New
Data.OleDb.OleDbConnection(myConnString)
Dim mySQLText As String = "SELECT [id],[brand],[redvalue],
[greenvalue],[bluevalue],[thinnedby] FROM [Allpaints] "
Dim myCmd1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(mySQLText, myConn)
myConn.Open()
>
'QUERIED COLUMN ORDNALS
'0 - ID; 1 - BRAND; 2 - REDVALUE; 3 - GREENVALUE; 4 -
BLUEVALUE; 5 - THINNER
>
'dim myReader1 for the outside loop; forward moving only
Dim myReader1 As Data.OleDb.OleDbDataReader =
myCmd1.ExecuteReader()
>
'dim and fill myDataSet2 for the inside loop; need to go
both directions
Dim dataAdapter As New
System.Data.OleDb.OleDbDataAdapter(mySQLText, myConn)
Dim myDataSet2 As System.Data.DataSet = New
System.Data.DataSet
Dim myDS2Row As System.Data.DataRow
dataAdapter.Fill(myDataSet2)
>
'start first/outside reader loop
While myReader1.Read()
>
'this loops through each record
For Rows1 = 0 To myReader1.FieldCount - 1
>
'get comp color values for the current OUTSIDE
loop record
compRed1 =
myReader1.Item(myReader1.GetOrdinal("redvalue"))
compGreen1 =
myReader1.Item(myReader1.GetOrdinal("greenvalue"))
compBlue1 =
myReader1.Item(myReader1.GetOrdinal("bluevalue"))
>
'the actual inside looper; goes through each
myDataSet2 record
For Each myDS2Row In myDataSet2.Tables(0).Rows
>
'get comp color values for the current INSIDE
loop
compRed2 = myDS2Row.Item(2)
compGreen2 = myDS2Row.Item(3)
compBlue2 = myDS2Row.Item(4)
>
'first/outside ratio loop
For compFactor1 = 1 To maxRatio
>
'second/inside ratio loop
For compFactor2 = 1 To maxRatio
>
'the math to get testRed, testGreen,
testBlue based on current ratios
testRed = ((compRed1 * compFactor1) +
(compRed2 * compFactor2)) / (compFactor1 + compFactor2)
testGreen = ((compGreen1 *
compFactor1) + (compGreen2 * compFactor2)) / (compFactor1 +
compFactor2)
testBlue = ((compBlue1 * compFactor1)
+ (compBlue2 * compFactor2)) / (compFactor1 + compFactor2)
>
>
If (testRed < startRed + maxDiff And
testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen +
maxDiff And testGreen startGreen - maxDiff) _
AndAlso (testBlue < startBlue +
maxDiff And testBlue startBlue - maxDiff) Then
>
'use stringbuilder to create fwd/
rev ID pairs to test against used pairs
testID1.Remove(0,
testID1.Length())
testID1.Append("::" &
myReader1.Item(myReader1.GetOrdinal("id")) & ":" & myDS2Row.Item(0) &
"::")
testID2.Remove(0,
testID2.Length())
testID2.Append("::" &
myDS2Row.Item(0) & ":" & myReader1.Item(myReader1.GetOrdinal("id")) &
"::")
>
'the inner/outer brand should be
the same and block out already displayed combos
'at least for now;later we can
maybe turn on mixed brand recipes
If
myReader1.Item(myReader1.GetOrdinal("brand")) = myDS2Row.Item(1) _
AndAlso
myReader1.Item(myReader1.GetOrdinal("id")) <startID _
AndAlso myDS2Row.Item(0) <>
startID _
AndAlso
usedIDs.ToString().IndexOf(testID1.ToString()) = -1 _
AndAlso
usedIDs.ToString().IndexOf(testID2.ToString()) = -1 Then
>
>
usedIDs.Append(testID1.ToString())
>
'the ligter/darker flag
If testRed startRed And
testGreen startGreen And testBlue startBlue Then
Response.Write("Slightly
Lighter than chosen color<BR>")
ElseIf testRed < startRed And
testGreen < startGreen And testBlue < startBlue Then
Response.Write("Slightly
Darker than chosen color<BR>")
End If
>
Response.Write("testred
= " & testRed & "<br>")
Response.Write("testgreen
= " & testGreen & "<br>")
Response.Write("testblue
= " & testBlue & "<br>")
>
Response.Write(myReader1.Item(1) & "<br>")
Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " & compRed1 & "<br>")
Response.Write("compgreen1
= " & compGreen1 & "<br>")
Response.Write("compblue1
= " & compBlue1 & "<br>")
>
Response.Write(myDS2Row.Item(1) & "<br>")
Response.Write("compfact2
= " & compFactor2 & "<br>")
Response.Write("compred2
= " & compRed2 & "<br>")
Response.Write("compgreen2
= " & compGreen2 & "<br>")
Response.Write("compblue2
= " & compBlue2 & "<br><br><br>")
End If
>
End If
>
Next compFactor2
>
Next compFactor1
>
Next myDS2Row
>
Next Rows1
>
End While
>
End If
>
End Sub
</script>
>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: x-small; font-family: Verdana">
<form id="form1" runat="server">
<div>
Mixer Results<br />
<br />
>
</div>
</form>
</body>
</html>
>
>


On May 29, 3:37 pm, Peter Bromberg [C# MVP]
<pbromb...@dotnet.itags.org.yahoo.yabbadabbadoo.comwrote:

Quote:

Originally Posted by

Aside from the fact that you are using MS Access, I don't see anywhere in
your sample code where you are closing your connections or DataReaders. If
you get all your data into memory (dataSets, not readers) you will only need
to get it once and then you can do all your manipulations without open
connections.
If that helps, then you can optimize more by using databinding to controls
rather than a series of Response.Write's .
Peter
>
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>

Quote:

Originally Posted by

Response.Write("compblue1
= " & compBlue1 & "<br>")


>
...
>
read more


Thanks. I originally had datasets for both main loops and it was even
slower. I learned about datareaders being faster so I tried that and
it was faster but I had to keep the dataset for the inner loop because
otherwise I have to recreate the datareader with each loop (forward
moving only) and it took over 6 min. Are you saying there is a way to
"clone" the table in ram and then close the db connections and work
off the table in ram? I should tell you the result page is completely
static. No user inputs, just a report page really. Also, I'm no
programmer. The learning curve needs to be...well...flat. Thanks.

TF
On May 29, 8:56 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF, you have just a HUGE number of iterations happenning on the page - and
some of them are unnecessary. A few suggestions:
>
- create a vew on the datatable from the dataset
Dim myView As DataView = myDS2Row.Tables(0).DefaultView
>
and then on every reader row assign a filter to it:
>
myView.RowFilter = "brand='" & myReader1("brand").ToString & "' and id<>" &
myReader1("id").ToString
>
then instead of going though the whole table loop through the view rows
>
- instead of StringBuilders to keep IDs I would suggest using generic lists
of Integer:
Dim usedIDs As List(Of Integer) = New List(Of Integer)
>
then you could easily test whether an ID is already there (Contains method)
and add new ID (Add method)
>
Try that for a start, I may try to come up with a few more suggestions ifI
have some more time...
>
"TF" wrote:

Quote:

Originally Posted by

Hello all,


>

Quote:

Originally Posted by

I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored


Quote:

Originally Posted by

Quote:

Originally Posted by

Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " &


>
...
>
read more


Sergey,
I really think most of my iterations are looping just to get skipped
with no results. Let me see if I understand your first suggestion.
Create the view on the table before any looping. Then inside the
first/outer loop filter the view so that the inner loop will only see
brands that match the outer loop? Also exclude the id? If that's
what I think it is then that will cut the inner loops by about 70%
since the most records of any brand is about 255. Hmmm. Very
interesting. For the second suggestion, I see how it could be more
efficient but I don't understand how it will tell me what combos were
used. I track the IDs in pairs because it's ok if either component
gets used again with some other recipe. Maybe I'm missing your
point. Thanks very much!

TF
TF,

I did not quite understand your logic with IDs - so if you could explain it
better, I will try to come up with a solution. Meanwhile, we could shrink the
number of calculations that your code performs. Though arithmetic operations
do not seem to be expensive, but considering the number of times you loop
inside your code...
For example,

a) consider the following line (executed for every 1000 rows in reader):
compRed1 = myReader1.Item(myReader1.GetOrdinal("redvalue"))
I would declare a redOrdinal variable instead before the loop:
Dim columns As DataColumnCollection = myDS2Row.Tables(0).Columns
Dim redOrdinal As Integer = columns.IndexOf("redvalue")

b) testRed = (compRed1 * compFactor1 + compRed2 * compFactor2) /
(compFactor1 + compFactor2)
(compFactor1 + compFactor2) - in your algorithm is calculated 3 times
instead of 1 for 1000 rows (in reader) * 255 (by brand) * maxRatio * maxRatio
- and now it makes sense to declare a variable:
Dim compFactorSum As Integer = compFactor1 + compFactor2

c) "startRed + maxDiff" and "startRed - maxDiff" could also be calculated
outside the very first (reader) loop

d) myReader1.GetOrdinal("brand")) and myReader1.GetOrdinal("id") - again -
move outside the loops

e) in your inner loop, where you check:
If (testRed < startRed + maxDiff And testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen + maxDiff And testGreen startGreen -
maxDiff) _
AndAlso (testBlue < startBlue + maxDiff And testBlue startBlue - maxDiff)
Then
ensure that you use AndAlso instead of And - this way you can cut quite a
number of comparisons as the second token in the And statement will not be
evaluated (for AndAlso) if the first one is False.

I know that some of the suggestions look like very minor improvements, but
taken into account the number of iterations, I think every bit counts.

"TF" wrote:

Quote:

Originally Posted by

On May 29, 8:56 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF, you have just a HUGE number of iterations happenning on the page - and
some of them are unnecessary. A few suggestions:

- create a vew on the datatable from the dataset
Dim myView As DataView = myDS2Row.Tables(0).DefaultView

and then on every reader row assign a filter to it:

myView.RowFilter = "brand='" & myReader1("brand").ToString & "' and id<>" &
myReader1("id").ToString

then instead of going though the whole table loop through the view rows

- instead of StringBuilders to keep IDs I would suggest using generic lists
of Integer:
Dim usedIDs As List(Of Integer) = New List(Of Integer)

then you could easily test whether an ID is already there (Contains method)
and add new ID (Add method)

Try that for a start, I may try to come up with a few more suggestions if I
have some more time...

"TF" wrote:

Quote:

Originally Posted by

Hello all,


Quote:

Originally Posted by

I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " &


...

read more ?


>
Sergey,
I really think most of my iterations are looping just to get skipped
with no results. Let me see if I understand your first suggestion.
Create the view on the table before any looping. Then inside the
first/outer loop filter the view so that the inner loop will only see
brands that match the outer loop? Also exclude the id? If that's
what I think it is then that will cut the inner loops by about 70%
since the most records of any brand is about 255. Hmmm. Very
interesting. For the second suggestion, I see how it could be more
efficient but I don't understand how it will tell me what combos were
used. I track the IDs in pairs because it's ok if either component
gets used again with some other recipe. Maybe I'm missing your
point. Thanks very much!
>
TF
>
>


On May 30, 3:59 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF,
>
I did not quite understand your logic with IDs - so if you could explain it
better, I will try to come up with a solution. Meanwhile, we could shrinkthe
number of calculations that your code performs. Though arithmetic operations
do not seem to be expensive, but considering the number of times you loop
inside your code...
For example,
>
a) consider the following line (executed for every 1000 rows in reader):
compRed1 = myReader1.Item(myReader1.GetOrdinal("redvalue"))
I would declare a redOrdinal variable instead before the loop:
Dim columns As DataColumnCollection = myDS2Row.Tables(0).Columns
Dim redOrdinal As Integer = columns.IndexOf("redvalue")
>
b) testRed = (compRed1 * compFactor1 + compRed2 * compFactor2) /
(compFactor1 + compFactor2)
(compFactor1 + compFactor2) - in your algorithm is calculated 3 times
instead of 1 for 1000 rows (in reader) * 255 (by brand) * maxRatio * maxRatio
- and now it makes sense to declare a variable:
Dim compFactorSum As Integer = compFactor1 + compFactor2
>
c) "startRed + maxDiff" and "startRed - maxDiff" could also be calculated
outside the very first (reader) loop
>
d) myReader1.GetOrdinal("brand")) and myReader1.GetOrdinal("id") - again -
move outside the loops
>
e) in your inner loop, where you check:
If (testRed < startRed + maxDiff And testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen + maxDiff And testGreen startGreen -
maxDiff) _
AndAlso (testBlue < startBlue + maxDiff And testBlue startBlue - maxDiff)
Then
ensure that you use AndAlso instead of And - this way you can cut quite a
number of comparisons as the second token in the And statement will not be
evaluated (for AndAlso) if the first one is False.
>
I know that some of the suggestions look like very minor improvements, but
taken into account the number of iterations, I think every bit counts.
>
"TF" wrote:

Quote:

Originally Posted by

On May 29, 8:56 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF, you have just a HUGE number of iterations happenning on the page - and
some of them are unnecessary. A few suggestions:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

- create a vew on the datatable from the dataset
Dim myView As DataView = myDS2Row.Tables(0).DefaultView


>

Quote:

Originally Posted by

Quote:

Originally Posted by

and then on every reader row assign a filter to it:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

myView.RowFilter = "brand='" & myReader1("brand").ToString & "' and id<>" &
myReader1("id").ToString


>

Quote:

Originally Posted by

Quote:

Originally Posted by

then instead of going though the whole table loop through the view rows


>

Quote:

Originally Posted by

Quote:

Originally Posted by

- instead of StringBuilders to keep IDs I would suggest using genericlists
of Integer:
Dim usedIDs As List(Of Integer) = New List(Of Integer)


>

Quote:

Originally Posted by

Quote:

Originally Posted by

then you could easily test whether an ID is already there (Contains method)
and add new ID (Add method)


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Try that for a start, I may try to come up with a few more suggestions if I
have some more time...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"TF" wrote:
Hello all,


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " &


>

Quote:

Originally Posted by

Quote:

Originally Posted by

...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

read more


>

Quote:

Originally Posted by

Sergey,
I really think most of my iterations are looping just to get skipped
with no results. Let me see if I understand your first suggestion.
Create the view on the table before any looping. Then inside the
first/outer loop filter the view so that the inner loop will only see
brands that match the outer loop? Also exclude the id? If that's
what I think it is then that will cut the inner loops by about 70%
since the most records of any brand is about 255. Hmmm. Very
interesting. For the second suggestion, I see how it could be more
efficient but I don't understand how it will tell me what combos were
used. I track the IDs in pairs because it's ok if either component
gets used again with some other recipe. Maybe I'm missing your
point. Thanks very much!


>

Quote:

Originally Posted by

TF


Sergey,
First the IDs. It's just an autonumber field w/no duplicates. When I
started this I found that paint pairs that met the criteria at, say
2:1 ratio, were also displayed at 4:2, 8:4, etc. I want them to only
display the first time so I started concatting strings (later traded
for stringbuilder). I needed the ID pairs to be fwd and rev because
the outer loop would eventually get to the second record of the combo
and it would display again. It's the only workaround I could come up
with to keep used pairs from displaying more than once.

I created lowRed, hiRed, etc variables before the first loop. Good
idea. Would like to tackle an issue with your previous suggestion
before going into the others. I put in the statement...

Dim myView As Data.DataView = myDS2Row.Tables(0).DefaultView

...right after the "dataAdapter.Fill(myDataSet2)" line. VWD made me
change it to...

Dim myView As System.Data.DataView = myDS2Row.Table().DefaultView

...and VWD is now warning me that myDS2 is used before it's been
assigned a value. Also errors out when I try to run it. I think
filtering out most of the rows before the inner loop starts would be a
huge step. Am I missing something?

Thanks for your help, Sergey.
TF,

1) You should use dataset, not datarow to get the initial dataview:
Dim myView As Data.DataView = myDataSet2.Tables(0).DefaultView

2) To avoid duplicate IDs you do not have to use any of the methods you
described - you could just change your loops as follows:

For compFactor1 = 1 To maxRatio
For compFactor2 = compFactor1 To maxRatio

and this way you will cut the number of iterations, as well as resolve the
problem of possible duplicates.

"TF" wrote:

Quote:

Originally Posted by

On May 30, 3:59 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF,

I did not quite understand your logic with IDs - so if you could explain it
better, I will try to come up with a solution. Meanwhile, we could shrink the
number of calculations that your code performs. Though arithmetic operations
do not seem to be expensive, but considering the number of times you loop
inside your code...
For example,

a) consider the following line (executed for every 1000 rows in reader):
compRed1 = myReader1.Item(myReader1.GetOrdinal("redvalue"))
I would declare a redOrdinal variable instead before the loop:
Dim columns As DataColumnCollection = myDS2Row.Tables(0).Columns
Dim redOrdinal As Integer = columns.IndexOf("redvalue")

b) testRed = (compRed1 * compFactor1 + compRed2 * compFactor2) /
(compFactor1 + compFactor2)
(compFactor1 + compFactor2) - in your algorithm is calculated 3 times
instead of 1 for 1000 rows (in reader) * 255 (by brand) * maxRatio * maxRatio
- and now it makes sense to declare a variable:
Dim compFactorSum As Integer = compFactor1 + compFactor2

c) "startRed + maxDiff" and "startRed - maxDiff" could also be calculated
outside the very first (reader) loop

d) myReader1.GetOrdinal("brand")) and myReader1.GetOrdinal("id") - again -
move outside the loops

e) in your inner loop, where you check:
If (testRed < startRed + maxDiff And testRed startRed - maxDiff) _
AndAlso (testGreen < startGreen + maxDiff And testGreen startGreen -
maxDiff) _
AndAlso (testBlue < startBlue + maxDiff And testBlue startBlue - maxDiff)
Then
ensure that you use AndAlso instead of And - this way you can cut quite a
number of comparisons as the second token in the And statement will not be
evaluated (for AndAlso) if the first one is False.

I know that some of the suggestions look like very minor improvements, but
taken into account the number of iterations, I think every bit counts.

"TF" wrote:

Quote:

Originally Posted by

On May 29, 8:56 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :
TF, you have just a HUGE number of iterations happenning on the page - and
some of them are unnecessary. A few suggestions:


Quote:

Originally Posted by

- create a vew on the datatable from the dataset
Dim myView As DataView = myDS2Row.Tables(0).DefaultView


Quote:

Originally Posted by

and then on every reader row assign a filter to it:


Quote:

Originally Posted by

myView.RowFilter = "brand='" & myReader1("brand").ToString & "' and id<>" &
myReader1("id").ToString


Quote:

Originally Posted by

then instead of going though the whole table loop through the view rows


Quote:

Originally Posted by

- instead of StringBuilders to keep IDs I would suggest using generic lists
of Integer:
Dim usedIDs As List(Of Integer) = New List(Of Integer)


Quote:

Originally Posted by

then you could easily test whether an ID is already there (Contains method)
and add new ID (Add method)


Quote:

Originally Posted by

Try that for a start, I may try to come up with a few more suggestions if I
have some more time...


Quote:

Originally Posted by

"TF" wrote:
Hello all,


Quote:

Originally Posted by

I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored


Quote:

Originally Posted by

Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " &


Quote:

Originally Posted by

...


Quote:

Originally Posted by

read more ?


Quote:

Originally Posted by

Sergey,
I really think most of my iterations are looping just to get skipped
with no results. Let me see if I understand your first suggestion.
Create the view on the table before any looping. Then inside the
first/outer loop filter the view so that the inner loop will only see
brands that match the outer loop? Also exclude the id? If that's
what I think it is then that will cut the inner loops by about 70%
since the most records of any brand is about 255. Hmmm. Very
interesting. For the second suggestion, I see how it could be more
efficient but I don't understand how it will tell me what combos were
used. I track the IDs in pairs because it's ok if either component
gets used again with some other recipe. Maybe I'm missing your
point. Thanks very much!


Quote:

Originally Posted by

TF


>
Sergey,
First the IDs. It's just an autonumber field w/no duplicates. When I
started this I found that paint pairs that met the criteria at, say
2:1 ratio, were also displayed at 4:2, 8:4, etc. I want them to only
display the first time so I started concatting strings (later traded
for stringbuilder). I needed the ID pairs to be fwd and rev because
the outer loop would eventually get to the second record of the combo
and it would display again. It's the only workaround I could come up
with to keep used pairs from displaying more than once.
>
I created lowRed, hiRed, etc variables before the first loop. Good
idea. Would like to tackle an issue with your previous suggestion
before going into the others. I put in the statement...
>
Dim myView As Data.DataView = myDS2Row.Tables(0).DefaultView
>
...right after the "dataAdapter.Fill(myDataSet2)" line. VWD made me
change it to...
>
Dim myView As System.Data.DataView = myDS2Row.Table().DefaultView
>
...and VWD is now warning me that myDS2 is used before it's been
assigned a value. Also errors out when I try to run it. I think
filtering out most of the rows before the inner loop starts would be a
huge step. Am I missing something?
>
Thanks for your help, Sergey.
>
>
>


On May 30, 11:49 pm, Sergey Poberezovskiy <
SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF,
>


Quote:

Originally Posted by

Quote:

Originally Posted by

filtering out most of the rows before the inner loop starts would be a
huge step. Am I missing something?


>

Quote:

Originally Posted by

Thanks for your help, Sergey.


Sergey,

I thought I posted this already but I guess it didn't get through.
Here
goes again. Thank you so much for all your help so far. I
implemented most
of your excellent suggestions and as I was going through my code I
realized
I was looping through all six columns on every loop. I took that
datareader.fieldcount loop out and now the page loads in 40 seconds
even
with maxratio at 10. Of course that made me VERY happy. But I still
can't
get the filter to work. I tried running with the filter and
commenting it
out and it's still 40 seconds. Also I get combos of mixed brands and
that
shouldn't happen if the filter's working. I'm sure I'm missing
something
simple. Here's my revised code. Can you see what's going wrong here?
Thanks again.

TF (code below)

<%@dotnet.itags.org. Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

'coming from PM - make sure the querystring values are what is
expected.
'if not, bail out of the page load sub
'should be 4 values: r,g,b,id. r,g,b must be between (not
equal) 0
and 256.
If Request.QueryString.Count <4 _
Or Request.QueryString("red") < 0 Or
Request.QueryString("red") >
255 _
Or Request.QueryString("green") < 0 Or
Request.QueryString("green")

Quote:

Originally Posted by

255 _


Or Request.QueryString("blue") < 0 Or
Request.QueryString("blue") >
255 Then

'bail from the page load sub
Exit Sub

Else

'dim all variables first
Dim startRed, testRed, compRed1, compRed2 As Integer
Dim hiRed, loRed As Integer
Dim redColOrdinal, blueColOrdinal, greenColOrdinal As
Integer
Dim startGreen, testGreen, compGreen1, compGreen2 As
Integer
Dim hiGreen, loGreen As Integer
Dim startBlue, testBlue, compBlue1, compBlue2 As Integer
Dim hiBlue, loBlue As Integer
Dim compFactor1, compFactor2, compFactorSum As Integer
Dim maxRatio, maxDiff As Integer
Dim startID, outerID, innerID As Integer
Dim outerBrand, innerBrand As String
Dim usedIDStr As String = "xxxxxxxxxxx"
Dim testIDStr1 As String = "" 'id pairs
Dim testIDStr2 As String = "" 'id pairs reverse order

'create the stringbuilder objects
Dim testID1 As New Text.StringBuilder(15)
Dim testID2 As New Text.StringBuilder(15)
Dim usedIDs As New Text.StringBuilder(500)

'max ratio of comparison
maxRatio = 10

'max diff from start color for display: +/- tolerance
maxDiff = 3

'starting id,r,g,b; get from querystring
startID = Request.QueryString("id")
startRed = Request.QueryString("red")
startGreen = Request.QueryString("green")
startBlue = Request.QueryString("blue")

'hi/lo bounds of RGB colors
hiRed = startRed + maxDiff
loRed = startRed - maxDiff
hiGreen = startGreen + maxDiff
loGreen = startGreen - maxDiff
hiBlue = startBlue + maxDiff
loBlue = startBlue - maxDiff

'the database connction stuff
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.
4.0;
Data Source=C:\Inetpub\WebSite1\App_Data\PaintsDbase.md b"
Dim myConn As Data.OleDb.OleDbConnection = New
Data.OleDb.OleDbConnection(myConnString)
Dim mySQLText As String = "SELECT
[id],[brand],[redvalue],[greenvalue],[bluevalue],[thinnedby] FROM
[Allpaints] ORDER BY [brand]"
Dim myCmd1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(mySQLText, myConn)
myConn.Open()

'QUERIED COLUMN ORDNALS
'0 - ID; 1 - BRAND; 2 - REDVALUE; 3 - GREENVALUE; 4 -
BLUEVALUE;
5 - THINNER

'dim myReader1 for the outside loop; forward moving only
Dim myReader1 As Data.OleDb.OleDbDataReader =
myCmd1.ExecuteReader()

'dim and fill myDataSet2 for the inside loop; need to go
both
directions
Dim dataAdapter As New
System.Data.OleDb.OleDbDataAdapter(mySQLText,
myConn)
Dim myDataSet2 As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(myDataSet2)

'set red, green, blue column ordinal variables
redColOrdinal = myReader1.GetOrdinal("redvalue")
greenColOrdinal = myReader1.GetOrdinal("greenvalue")
blueColOrdinal = myReader1.GetOrdinal("bluevalue")

'uncommented for debugging
Response.Write("maxdiff=" & maxDiff & "<br>")
Response.Write("maxratio=" & maxRatio & "<br><br>")

'dim myview to try and filter the dataset2
Dim myView As Data.DataView =
myDataSet2.Tables(0).DefaultView
Dim myDVRow As Data.DataRow
Dim myFilterStr As String
Dim filterFlag As String = ""
Dim insideLoopCount As Integer = 0

'start first/outside reader loop
While myReader1.Read()

'set the outerID and outerBrand variables
outerID = myReader1.Item(myReader1.GetOrdinal("id"))
outerBrand =
myReader1.Item(myReader1.GetOrdinal("brand"))

'takes same time with or without filter; not working.
If filterFlag <outerBrand Then
myFilterStr = "Brand = '" & outerBrand & "'"
myView.RowFilter = myFilterStr
Response.Write("Just changed filter.<BR>")
Response.Write("Loops: " & insideLoopCount &
"<BR>")
Response.Write("rowfilter tostring: " &
myView.RowFilter.ToString() & "<BR>")
insideLoopCount = 0
filterFlag = outerBrand
End If

'get comp color values for the current OUTSIDE loop
record
compRed1 = myReader1.Item(redColOrdinal)
compGreen1 = myReader1.Item(greenColOrdinal)
compBlue1 = myReader1.Item(blueColOrdinal)

'the actual inside looper; goes through each myView
record
For Each myDVRow In myView.Table().Rows()

'get comp color values for the current INSIDE loop
compRed2 = myDVRow.Item(2)
compGreen2 = myDVRow.Item(3)
compBlue2 = myDVRow.Item(4)

'set the innerID variable
innerID = myDVRow.Item(0)
innerBrand = myDVRow.Item(1)

'increment the inside loop counter
insideLoopCount = insideLoopCount + 1

'first/outside ratio loop
For compFactor1 = 1 To maxRatio

'second/inside ratio loop
For compFactor2 = 1 To maxRatio

'compfactor1 plus compfactor2 variable
compFactorSum = compFactor1 + compFactor2

'the math to get testRed, testGreen,
testBlue
based on current ratios
testRed = ((compRed1 * compFactor1) +
(compRed2
* compFactor2)) / compFactorSum
testGreen = ((compGreen1 * compFactor1) +
(compGreen2 * compFactor2)) / compFactorSum
testBlue = ((compBlue1 * compFactor1) +
(compBlue2 * compFactor2)) / compFactorSum

If testRed < hiRed AndAlso testRed loRed
_
AndAlso testGreen < hiGreen AndAlso
testGreen >
loGreen _
AndAlso testBlue < hiBlue AndAlso testBlue

Quote:

Originally Posted by

>


loBlue Then

'use stringbuilder to create fwd/rev
ID
pairs to test against used pairs
testID1.Remove(0, testID1.Length())
testID1.Append("::" & outerID & ":" &
innerID & "::")
testID2.Remove(0, testID2.Length())
testID2.Append("::" & innerID & ":" &
outerID & "::")

'the inner/outer brand should be the
same
and block out used id pairs
'at least for now;later we can maybe
turn on
mixed brand recipes
If outerID <startID _
AndAlso innerID <startID _
AndAlso usedIDs.ToString().IndexOf(
testID1.ToString()) = -1 _
AndAlso usedIDs.ToString().IndexOf(
testID2.ToString()) = -1 Then

'append the used id pair
usedIDs.Append(testID1.ToString())

'display for debugging
Response.Write(usedIDs.ToString()
&
"<br>")

'the ligter/darker flag
If testRed startRed AndAlso
testGreen

Quote:

Originally Posted by

startGreen AndAlso testBlue startBlue Then


Response.Write("Slightly
Lighter<BR>")
ElseIf testRed < startRed AndAlso
testGreen < startGreen AndAlso testBlue < startBlue Then
Response.Write("Slightly
Darker<BR>")
End If

'display for debugging
Response.Write("testred =
" & testRed & "<br>")
Response.Write("testgreen
= " & testGreen & "<br>")
Response.Write("testblue =
" & testBlue & "<br>")
Response.Write(outerBrand &
"<br>")
Response.Write("compfact1
= "
& compFactor1 & "<br>")
Response.Write("compred1
= "
& compRed1 & "<br>")
Response.Write("compgreen1 =
" & compGreen1 & "<br>")
Response.Write("compblue1 =
" & compBlue1 & "<br>")
'Response.Write(myDS2Row.Item(1) &
"<br>")
Response.Write(innerBrand &
"<br>")
Response.Write("compfact2
= "
& compFactor2 & "<br>")
Response.Write("compred2
= "
& compRed2 & "<br>")
Response.Write("compgreen2 =
" & compGreen2 & "<br>")
Response.Write("compblue2 =
" & compBlue2 & "<br><br><br>")
End If

End If

Next compFactor2

Next compFactor1

Next myDVRow

End While

End If

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: x-small; font-family: Verdana">
<form id="form1" runat="server">
<div>
Mixer Results<br />
<br />

</div>
</form>
</body>
</html>
On May 30, 11:49 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@dotnet.itags.org.discussions.microsoft.comwrote :

Quote:

Originally Posted by

TF,
>


Quote:

Originally Posted by

Quote:

Originally Posted by

filtering out most of the rows before the inner loop starts would be a
huge step. Am I missing something?


>

Quote:

Originally Posted by

Thanks for your help, Sergey.


Sergey,

I thought I posted this already but I guess it didn't get through.
Here goes again. Thank you so much for all your help so far. I
implemented most of your excellent suggestions and as I was going
through my code I realized I was looping through all six columns on
every loop. I took that datareader.fieldcount loop out and now the
page loads in 40 seconds even with maxratio at 10. Of course that
made me VERY happy. But I still can't get the filter to work. I
tried running with the filter and commenting it out and it's still 40
seconds. Also I get combos of mixed brands and that shouldn't happen
if the filter's working. I'm sure I'm missing something simple.
Here's my revised code. Can you see what's going wrong here? Thanks
again.

TF (code below)

<%@dotnet.itags.org. Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

'coming from PM - make sure the querystring values are what is
expected.
'if not, bail out of the page load sub
'should be 4 values: r,g,b,id. r,g,b must be between (not
equal) 0 and 256.
If Request.QueryString.Count <4 _
Or Request.QueryString("red") < 0 Or
Request.QueryString("red") 255 _
Or Request.QueryString("green") < 0 Or
Request.QueryString("green") 255 _
Or Request.QueryString("blue") < 0 Or
Request.QueryString("blue") 255 Then

'bail from the page load sub
Exit Sub

Else

'dim all variables first
Dim startRed, testRed, compRed1, compRed2 As Integer
Dim hiRed, loRed As Integer
Dim redColOrdinal, blueColOrdinal, greenColOrdinal As
Integer
Dim startGreen, testGreen, compGreen1, compGreen2 As
Integer
Dim hiGreen, loGreen As Integer
Dim startBlue, testBlue, compBlue1, compBlue2 As Integer
Dim hiBlue, loBlue As Integer
Dim compFactor1, compFactor2, compFactorSum As Integer
Dim maxRatio, maxDiff As Integer
Dim startID, outerID, innerID As Integer
Dim outerBrand, innerBrand As String
Dim usedIDStr As String = "xxxxxxxxxxx"
Dim testIDStr1 As String = "" 'id pairs
Dim testIDStr2 As String = "" 'id pairs reverse order

'create the stringbuilder objects
Dim testID1 As New Text.StringBuilder(15)
Dim testID2 As New Text.StringBuilder(15)
Dim usedIDs As New Text.StringBuilder(500)

'max ratio of comparison
maxRatio = 10

'max diff from start color for display: +/- tolerance
maxDiff = 3

'starting id,r,g,b; get from querystring
startID = Request.QueryString("id")
startRed = Request.QueryString("red")
startGreen = Request.QueryString("green")
startBlue = Request.QueryString("blue")

'hi/lo bounds of RGB colors
hiRed = startRed + maxDiff
loRed = startRed - maxDiff
hiGreen = startGreen + maxDiff
loGreen = startGreen - maxDiff
hiBlue = startBlue + maxDiff
loBlue = startBlue - maxDiff

'the database connction stuff
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=C:\Inetpub\WebSite1\App_Data\PaintsDbase.md b"
Dim myConn As Data.OleDb.OleDbConnection = New
Data.OleDb.OleDbConnection(myConnString)
Dim mySQLText As String = "SELECT [id],[brand],[redvalue],
[greenvalue],[bluevalue],[thinnedby] FROM [Allpaints] ORDER BY
[brand]"
Dim myCmd1 As Data.OleDb.OleDbCommand = New
Data.OleDb.OleDbCommand(mySQLText, myConn)
myConn.Open()

'QUERIED COLUMN ORDNALS
'0 - ID; 1 - BRAND; 2 - REDVALUE; 3 - GREENVALUE; 4 -
BLUEVALUE; 5 - THINNER

'dim myReader1 for the outside loop; forward moving only
Dim myReader1 As Data.OleDb.OleDbDataReader =
myCmd1.ExecuteReader()

'dim and fill myDataSet2 for the inside loop; need to go
both directions
Dim dataAdapter As New
System.Data.OleDb.OleDbDataAdapter(mySQLText, myConn)
Dim myDataSet2 As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(myDataSet2)

'set red, green, blue column ordinal variables
redColOrdinal = myReader1.GetOrdinal("redvalue")
greenColOrdinal = myReader1.GetOrdinal("greenvalue")
blueColOrdinal = myReader1.GetOrdinal("bluevalue")

'uncommented for debugging
Response.Write("maxdiff=" & maxDiff & "<br>")
Response.Write("maxratio=" & maxRatio & "<br><br>")

'dim myview to try and filter the dataset2
Dim myView As Data.DataView =
myDataSet2.Tables(0).DefaultView
Dim myDVRow As Data.DataRow
Dim myFilterStr As String
Dim filterFlag As String = ""
Dim insideLoopCount As Integer = 0

'start first/outside reader loop
While myReader1.Read()

'set the outerID and outerBrand variables
outerID = myReader1.Item(myReader1.GetOrdinal("id"))
outerBrand =
myReader1.Item(myReader1.GetOrdinal("brand"))

'takes same time with or without filter; not working.
If filterFlag <outerBrand Then
myFilterStr = "Brand = '" & outerBrand & "'"
myView.RowFilter = myFilterStr
Response.Write("Just changed filter.<BR>")
Response.Write("Loops: " & insideLoopCount &
"<BR>")
Response.Write("rowfilter tostring: " &
myView.RowFilter.ToString() & "<BR>")
insideLoopCount = 0
filterFlag = outerBrand
End If

'get comp color values for the current OUTSIDE loop
record
compRed1 = myReader1.Item(redColOrdinal)
compGreen1 = myReader1.Item(greenColOrdinal)
compBlue1 = myReader1.Item(blueColOrdinal)

'the actual inside looper; goes through each myView
record
For Each myDVRow In myView.Table().Rows()

'get comp color values for the current INSIDE loop
compRed2 = myDVRow.Item(2)
compGreen2 = myDVRow.Item(3)
compBlue2 = myDVRow.Item(4)

'set the innerID variable
innerID = myDVRow.Item(0)
innerBrand = myDVRow.Item(1)

'increment the inside loop counter
insideLoopCount = insideLoopCount + 1

'first/outside ratio loop
For compFactor1 = 1 To maxRatio

'second/inside ratio loop
For compFactor2 = 1 To maxRatio

'compfactor1 plus compfactor2 variable
compFactorSum = compFactor1 + compFactor2

'the math to get testRed, testGreen,
testBlue based on current ratios
testRed = ((compRed1 * compFactor1) +
(compRed2 * compFactor2)) / compFactorSum
testGreen = ((compGreen1 * compFactor1) +
(compGreen2 * compFactor2)) / compFactorSum
testBlue = ((compBlue1 * compFactor1) +
(compBlue2 * compFactor2)) / compFactorSum

If testRed < hiRed AndAlso testRed loRed
_
AndAlso testGreen < hiGreen AndAlso
testGreen loGreen _
AndAlso testBlue < hiBlue AndAlso testBlue

Quote:

Originally Posted by

loBlue Then


'use stringbuilder to create fwd/rev
ID pairs to test against used pairs
testID1.Remove(0, testID1.Length())
testID1.Append("::" & outerID & ":" &
innerID & "::")
testID2.Remove(0, testID2.Length())
testID2.Append("::" & innerID & ":" &
outerID & "::")

'the inner/outer brand should be the
same and block out used id pairs
'at least for now;later we can maybe
turn on mixed brand recipes
If outerID <startID _
AndAlso innerID <startID _
AndAlso
usedIDs.ToString().IndexOf(testID1.ToString()) = -1 _
AndAlso
usedIDs.ToString().IndexOf(testID2.ToString()) = -1 Then

'append the used id pair
usedIDs.Append(testID1.ToString())

'display for debugging
Response.Write(usedIDs.ToString()
& "<br>")

'the ligter/darker flag
If testRed startRed AndAlso
testGreen startGreen AndAlso testBlue startBlue Then
Response.Write("Slightly
Lighter<BR>")
ElseIf testRed < startRed AndAlso
testGreen < startGreen AndAlso testBlue < startBlue Then
Response.Write("Slightly
Darker<BR>")
End If

'display for debugging
Response.Write("testred
= " & testRed & "<br>")
Response.Write("testgreen
= " & testGreen & "<br>")
Response.Write("testblue
= " & testBlue & "<br>")
Response.Write(outerBrand &
"<br>")
Response.Write("compfact1
= " & compFactor1 & "<br>")
Response.Write("compred1
= " & compRed1 & "<br>")
Response.Write("compgreen1
= " & compGreen1 & "<br>")
Response.Write("compblue1
= " & compBlue1 & "<br>")
'Response.Write(myDS2Row.Item(1) &
"<br>")
Response.Write(innerBrand &
"<br>")
Response.Write("compfact2
= " & compFactor2 & "<br>")
Response.Write("compred2
= " & compRed2 & "<br>")
Response.Write("compgreen2
= " & compGreen2 & "<br>")
Response.Write("compblue2
= " & compBlue2 & "<br><br><br>")
End If

End If

Next compFactor2

Next compFactor1

Next myDVRow

End While

End If

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: x-small; font-family: Verdana">
<form id="form1" runat="server">
<div>
Mixer Results<br />
<br />

</div>
</form>
</body>
</html>