|
Besides the above you might want to learn about logging libraries and how to catch exceptions and log them.
|
|
|
|
|
I need to ALTER merge sort algorithm to get length of an array and enter strings then sort them alphabetically ... Im stuck on the sort...my code atm.... The code doesnt sort as I know that it isnt comparing the strings it works in the original form with numbers already hard coded as in ALL the things i have seen and i understand the int sorting but as i said earlier i want it to accept inputted strings and compare them alphabetically and am finding no guidance on how this is to be achieved apart from the compareTo method...so when this runs i get the strings inputed on the txtoutput UNSorted but cant seem to alter the mergeSort to sort the entered strings alphabetically
private void btnExecute_Click(object sender, EventArgs e)
{
int length = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("Enter a Number for how many Names to Sort :"));
string[] nameArray = new string[length];
foreach (string n in nameArray)
{
string name = Microsoft.VisualBasic.Interaction.InputBox("Enter " + length + " Names to add to Array:");
length = length - 1;
txtOutput.Text += name + "\r\n";
}
txtOutput.Text += nameArray.Length + "Names Added to List Unsorted ";
txtOutput.Text += "Sorted List : " + "\r\n";
mergeSort(nameArray, 0, nameArray.Length - 1);
foreach (string i in nameArray)
{
txtOutput.Text += i +"\t";
}
public void mergeSort(string[] nameArray, int lower, int upper)
{
int middle;
if (upper == lower)
return;
else
{
middle = (lower + upper) / 2;
mergeSort(nameArray, lower, middle);
mergeSort(nameArray, middle + 1, upper);
Merge(nameArray, lower, middle + 1, upper);
}
}
public void Merge(string[] nameArray, int lower, int middle, int upper)
{
string[] temp = new string[nameArray.Length];
int lowEnd = middle - 1;
int low = lower;
int n = upper - lower + 1;
while ((lower <= lowEnd) && (middle <= upper))
{
if ((nameArray[lower]).CompareTo(nameArray[middle])<= 0)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
else
{
temp[low] = nameArray[middle];
low++;
middle++;
}
}
while (lower <= lowEnd)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
while (middle <= upper)
{
temp[low] = nameArray[middle];
low++;
middle++;
}
for (int i = 0; i < n; i++)
{
nameArray[upper] = temp[upper];
upper--;
}
}
modified 12-Feb-15 6:50am.
|
|
|
|
|
int length = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("Enter a Number for how many Names to Sort :"));
string[] nameArray = new string[length];
foreach (string n in nameArray)
{
You cannot use foreach at this point, since your array does not contain any strings. And even if it did, you never add them to the array. You should use the number as a loop counter and enter a string at each offset. Although you could probably improve this by using a collection class rather than an array.
|
|
|
|
|
Why? Sorting is already implemented in several places (for example in List<T> and Array, both are unstable introsorts)
|
|
|
|
|
The first thing you're going to have to do is actually split the strings out that you received in the InputBox. There's a massive hint there that you have to use string.Split to split the input[^] and return an array of characters.
|
|
|
|
|
Please, don't post code like that:
public void Merge(string[] nameArray, int lower, int middle, int upper)
{
string[] temp = new string[nameArray.Length];
int lowEnd = middle - 1;
int low = lower;
int n = upper - lower + 1;
while ((lower <= lowEnd) && (middle <= upper))
{
if ((nameArray[lower]).CompareTo(nameArray[middle])<= 0)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
else
{
temp[low] = nameArray[middle];
low++;
middle++;
}
}
while (lower <= lowEnd)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
while (middle <= upper)
{
temp[low] = nameArray[middle];
low++;
middle++;
}
for (int i = 0; i < n; i++)
{
nameArray[upper] = temp[upper];
upper--;
}
}
It makes it very hard to read!
Instead, use the "code" button above the text box to insert the <pre> tags which preserve formatting:
public void Merge(string[] nameArray, int lower, int middle, int upper)
{
string[] temp = new string[nameArray.Length];
int lowEnd = middle - 1;
int low = lower;
int n = upper - lower + 1;
while ((lower <= lowEnd) && (middle <= upper))
{
if ((nameArray[lower]).CompareTo(nameArray[middle])<= 0)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
else
{
temp[low] = nameArray[middle];
low++;
middle++;
}
}
while (lower <= lowEnd)
{
temp[low] = nameArray[lower];
low++;
lower++;
}
while (middle <= upper)
{
temp[low] = nameArray[middle];
low++;
middle++;
}
for (int i = 0; i < n; i++)
{
nameArray[upper] = temp[upper];
upper--;
}
}
Second, a problem report like "Im stuck on the sort...my code atm.... Help its driving me loopy" tells us nothing at all about the problem you are having.
Tell us what it does that you didn't expect, or doesn't do that you did!
Tell us what data you use to test it, and what you expect to get as a result. Then show us what you do get!
The better the information you give us (and remember that we can't see your screen, access your HDD, or read your mind) the better we can help you to fix the problem.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thankyou I apologize I am new to this but i did say I am having trouble ALTERING the code to accept strings rather than ints
as the original code has hard coded numbers the question needs to get 1 input box to give the array length which is working but the strings that are entered on the second input box i can not find where to compare the entered text to and sort them alphabetically on the go ....
|
|
|
|
|
That doesn't tell us anything about what kind of problem you are having doing it.
Since you wrote the code, we can safely assume that you fully understand it, but we don't know what part of your code you don't know to change! Or what is making it difficult for you.
Seriously, we can't see your screen - we only get what you give us to work with. So teh better the info you give us, the better we can answer...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I use to mark Dictionary of Cell type (of the GridView of DevExpress), for example, declare the type of row, I declared thus:
[code]
Dictionary<datarow, color=""> colors = new Dictionary<datarow, color="">();
[/code]
code above the type of row, declaration row is: DataRow, I want to replace the type DataRow is Cell type of the DevExpress GridView What is keyword in C# ?
|
|
|
|
|
What?? Your question made no sense at all.
How does a Dictionary relate to a GridView? What does a DataRow have to do with any of this?
|
|
|
|
|
my obstacles and express language, English is not my main language
In C # it allows type declarations corresponding row and column types as follows:
Dictionary<DataRow, Color> colors = new Dictionary<DataRow, Color>();
Dictionary<DataColumn, Color> colors = new Dictionary<DataColumn, Color>();
but I want to declare the type of cell that is the type of grid, I don't found place.
Dictionary<???, Color> colors = new Dictionary<???, Color>();
|
|
|
|
|
I have no idea what you're doing because the code doesn't make any sense to me. Why would you have an entire DataRow or Column as a key in a dictionary??
|
|
|
|
|
because I do not want to use the loop (for or while) to access grid
|
|
|
|
|
Very, very weird. It's like you're trying to treat the grid like it was an Excel sheet. These data grids are not designed for that.
Individual cells do not have a data type. The type is determine by the type of the column.
|
|
|
|
|
saving keypairs , public keys to file, using these keys to encrypt decrypt a file?
|
|
|
|
|
Saving keypairs? Which keypairs?
Which type of file are you using?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thanks for your reply. I figured this out
KeyPair keyPair = PublicKeyBox.GenerateKeyPair();
byte[] privateKey = keyPair.PrivateKey;
byte[] publicKey = keyPair.PublicKey;
File.WriteAllBytes(privateFilePath, privateKey);
File.WriteAllBytes(publicFilePath, publicKey);
|
|
|
|
|
This is my first time trying to do anything more than open a webpage as a process.
I'd like to open a page in IE and then fill in a text box with the id being shown below in the small code snippet.
I think I can use WebRequest for this, but I've tried a few code samples I found online and it does not open the webpage in IE, so I'm not sure where to start to get a simple example working and build off of it.
<div class="formControl"><input name= "username" id= "txtlogin" maxlength= "75" placeholder= "Username" size= "25" type= "text" class= "" />
</div>
<html style="height: 100%;">
<HEAD>
<meta http-equiv="x-ua-compatible" content="IE=Edge"/>
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Self Service Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="robots" content="noindex">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
</HEAD>
<BODY style="height: 100%;">
Employee Self-Service
<form method= "POST" action= "ee-loginproc.php" name= "frmEELogin" class= "" >
<label class="standard" for="username">
Username
</label>
<input name= "username" id= "txtlogin" maxlength= "75" placeholder= "Username" size= "25" type= "text" class= "" />
<label class="standard" for="userpass">
Password
</label>
<input type= "password" name= "userpass" id= "txtpass" maxlength= "40" placeholder= "Password" autocomplete= "off" size= "25" class= "" />
<label class="standard" for="userpin">
Last 4 digits of SSN
</label>
<input name= "userpin" id= "userpinid" type= "password" maxlength= "4" placeholder= "Last 4 digits of SSN" size= "25" class= "" />
<input size= "1" type= "submit" value= "Log in" name= "submit" id= "submit" class= "buttonPrimary" />
Forgot Password</form>
<script src="js/modernizr.js"></script>
<script src="../cl/js/pcm_cl_cust.js"></script>
<script>
$(document).ready(function(){
$("#txtlogin").focus();
});
</script>
</body>
</html>
|
|
|
|
|
I found an addin called Selenium that will do this, but then I have to have additional dlls to my executable and it's 5mb, which is 10 times my exe's size and way overkill.
No one has ever opened a page and then posted data to the input id's?
|
|
|
|
|
turbosupramk3 wrote: No one has ever opened a page and then posted data to the input id's? Google will show quite some hits.
If you want to manipulate IE, you will have to launch IE and manipulate that.
If you want to fill in values in a webpage, you use a WebBrowser control.
If you want to submit the data without any browser, use the WebRequest.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi, thanks for the response.
I've been trying with webbrowser for the past hour or so. Depending on my code that I'm using, it will read the page and set the value, but not open the page with the set value. Or it will open the page but not set the value. I'm missing something that allows the two to work in harmony. Can you tell what I'm doing wrong?
I believe I need to open the page, download the source, update the elements and reopen it in my browser, is this correct?
I started with this: http://stackoverflow.com/questions/8425593/c-sharp-httpwebrequest-post-login-to-facebook/15772387#15772387[^]
string email = "firstlast@gmail.com";
string password = "12345678";
string url = @"https://www.url.net/v4/ee/ee-login.php";
WebBrowser webbrowser1 = new WebBrowser();
webbrowser1.Navigate(url);
Application.DoEvents();
webbrowser1.Document.GetElementById("txtlogin").SetAttribute("value", email);
|
|
|
|
|
turbosupramk3 wrote: Can you tell what I'm doing wrong? Using "DoEvents"; it is almost always a hint that there is something wrong.
The "Navigate" method is not blocking, and DoEvents will return before the page is completely loaded. You want to wait with setting values until the document completes loading[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm trying but I can't get it, I feel like this is going to have to be spoon fed to me or I'm not going to get it?
I've been trying an event based method (link to code below) as well. Stepping through the code, I can either get it to accept my element data and not open the page, or not accept my element data and open the default page, never can I get it to do both.
Is the order of operations to load the page first and then submit the data, or do I need to ingest the data, update the elements and then load the page from the modified version?
http://www.dreamincode.net/forums/topic/152297-c%23-log-in-to-website-programmatically/page__view__findpost__p__1229505[^]
|
|
|
|
|
Like this?
private void editPage(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("txtlogin").SetAttribute("value", "my login");
webBrowser1.Document.GetElementById("txtpass").SetAttribute("value", "my password");
}
private void btnTestCalculate_Click(object sender, EventArgs e)
{
string email = "firstlast@gmail.com";
string password = "12345678";
string url = @"https://www.url.net/v4/ee/ee-login.php";
webBrowser1 = new WebBrowser();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(editPage);
webBrowser1.Navigate(url, true);
}
|
|
|
|
|
Looks correct; open a browser, load a document, wait until loaded, adapt it's contents.
Any redirections should be handled by the Webbrowser control. Do take in account that if you submit the page (ie, press login in the UI after this code runs) then it will navigate to another page, and the "document completed" event (or editpage) will be called again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|