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.
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.
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
>
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!!
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)
Dim objWord As New Word.Application
Dim docNew As New Word.Document
'Close the Automation object
objWord.Quit()
' Cleanup the unmanaged objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWord)
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!
Any assistance would be very much appreciated. Thanks.
Hmmm, ... where do you execute your command? It seems that you forgot the execution of the command.
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 IfDim cnnConnection As System.Data.SqlClient.SqlConnection
Dim connString2 As String = ConfigurationSettings.AppSettings("connString2")
Dim cmdCommand As System.Data.SqlClient.SqlDataAdaptercnnConnection = 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 = RecipientsResponse.Redirect("ManagersMessage.aspx")
End Sub
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.SqlCommandcnnConnection = 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.TextcmdCommand.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 = RecipientscmdCommand.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.
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.
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!
<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
Hi all
When I run this app, select the checkbox and press the calculate button i get the following error:
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.[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.
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
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...
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.
**********
Hi,
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 IfDim 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 TryMyCommand.Connection.Close()
BindGrid()
End Sub
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.
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...
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>
>
>
- 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>
>
>
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>")
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
= " &
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 ?
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
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
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.
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 _
'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
>
'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
'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.
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
'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>