|
|
|
Dear ALL
now i have a LAN + router , and i want to make a software in a certain PC to be able to access the router & get its Configuration & save it to the PC harddisk every a pre-defined period
how could i do that?? the diff. point is how to get the conf. from the router ??
i though of using telnet but i failed to get the router CLI commands to be able comm. with it ( its DLINK ADSL router - DSL-520T - )
any tips
thanks
bye
|
|
|
|
|
I have a representation of a byte stored in a string e.g. "0x08" which I want to convert to a byte.
I must be missing something really obvious here even after googling for 45 minutes.
I have not been able to use byte.Parse("0x08") as this requires an integer.
I tried int.Parse("0x08") but the string cannot be converted so that I could then use the previous method.
Any help appreciated.
Guy
You always pass failure on the way to success.
|
|
|
|
|
You could try:
var number = "0x08";
var integer = int.Parse(number.Substring(number.IndexOf("x") + 1), NumberStyles.HexNumber);
|
|
|
|
|
Thanks - that worked a treat.
All I need to then is:
byte byteCode = byte.Parse(integer.ToString());
and it works.
Thanks again
You always pass failure on the way to success.
|
|
|
|
|
Why do you go via a string? Just convert the integer to a byte:
byte byteCode = (byte)integer;
or:
byte byteCode = Convert.ToByte(integer);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Good point - I just discovered I get an exception when I try and get an integer above 127.
string tmpByte = "0x80H"
int integer = int.Parse(tmpByte.Substring(tmpByte.IndexOf("x") + 1), System.Globalization.NumberStyles.HexNumber);
Gives me a A first chance exception of type 'System.FormatException' occurred in mscorlib.dll exception.
It's gonna be a late night...
You always pass failure on the way to success.
|
|
|
|
|
Because 08H is not a valid hex number, in any language that I know of . The best way to convert this to a byte (which can hold 0-255) is:
byte converted = 0x00;
bool successful = byte.TryParse(inputString.Substring(inputString.IndexOf("x")), out converted);
if (!successful)
{
MessageBox.Show("Problem!");
}
else
{
}
|
|
|
|
|
Ed.Poore wrote: Because 08H is not a valid hex number, in any language that I know of
It was 80H and it seems valid to a hex converter clickety.
Basically what I am doing is reading in a list of Hex values, provided by Microsoft, of keycodes to be used by keybd_event .
You always pass failure on the way to success.
|
|
|
|
|
The H can be used as a suffix for some programming languages (can't remember which), 0x is the standard C, C++, C# prefix etc. It's just used by the compiler to determine whether it's a hex number or a decimal number. You're getting beyond the range of simple .Substring stuff and moving dangerously close to Regular Expression territory.
|
|
|
|
|
Thanks - I think I've been hit by the stupid stick today.
Been doing too much high level programming and forgot how hex works
I fixed it by limiting the substring to 2 characters.
int integer = int.Parse(tmpByte.Substring(tmpByte.IndexOf("x") + 1,<big>2</big>), System.Globalization.NumberStyles.HexNumber);
Thank you to everyone for their help
You always pass failure on the way to success.
|
|
|
|
|
You could use something like the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
namespace HexNumbers
{
class Program
{
private static void Main(string[] args)
{
var regex = new Regex(@"(%|&?#|\\x|U\+|=|H'|16#|8'h|#|16r|16#|#x|#16r|&H|&h|$|&|0h|0H)?(?<number>[\d|A-F|a-f]+)('?|#)?(h|H)?", RegexOptions.Compiled);
var numbers = new string[] { "%20", "ꯍ", "#FF", "0x5A3", "\\x1B", "U+20AC", "=D1a", "FFh", "0A3CH", "$5A3", "H'ABCD'", "16#5A3#", "8'hFF", "#01AF", "16r6EF7", "16#ABCD", "#xABC", "&H5A3", "&5A3", "0hA3", "X'5A3'" };
foreach (var number in numbers)
{
var isMatch = regex.IsMatch(number);
if (isMatch)
{
Console.WriteLine("{0} is a match and it's value is {1}", number, int.Parse(regex.Match(number).Groups["number"].Value, NumberStyles.HexNumber));
}
else
{
Console.WriteLine("{0} is not a hex number", number);
}
}
}
}
} Sorry about the length of the expression but is should handle all types of hex number as dictated by the Wikipedia listing for prefixes and suffixes. You could change the + symbol after the (\d|A-F)+ bracket to {2} if you want to limit it to two hex digits.
|
|
|
|
|
|
Well if I knew the restrictions that you're placing on the data it could be greatly simplified but thought I'd cater for as much as I could.
|
|
|
|
|
Out of interest Ed (and forgive me, I'm a little bit pissed), but why the "var" on Regex and numbers?
|
|
|
|
|
It's a new feature in C# version 3.
It's needed for when you are using anonymous types in LINQ.
It can also be used to make the code easier to read if the data type that you are declaring is obvious from the context, like:
var cmd = new System.Data.SqlClient.SqlCommand(query, connection);
instead of repeating the data type:
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, connection);
However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
That's what I thought
|
|
|
|
|
Guffa wrote: However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
Cos me is lazy
Besides It's very rare anyone else looks at my code so I tend to use it out of habit because I don't have a problem remembering what type a variable is. The name is usually enough if I don't remember straight away. Besides the IDE makes it easy enough to check.
|
|
|
|
|
That's fine when you are playing with yourself, but it doesn't make good example code.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Meh, saves my poor fingers from wearing down with extraneous key-strokes. Besides makes the transition to JavaScript easier
|
|
|
|
|
Hello,
I have a problem...
In designer I have set data source to "subjektBindingSource" (without "").
Then on click on a button I delete a selected row from a database, and it works ok, but my datagridview doesn't show the changes...
<br />
SqlConnection conn = new SqlConnection();<br />
<br />
conn.ConnectionString = connStr;<br />
String naredbaSql = null;<br />
naredbaSql = "DELETE from Subjekt WHERE ID = " + idUser;<br />
<br />
conn.Open();<br />
<br />
SqlCommand comand = new SqlCommand(naredbaSql, conn);<br />
comand.ExecuteNonQuery(); <br />
<br />
conn.Close();<br />
<br />
So, all I want is to refresh my datagridview so it shows data from database without that row I erased. I tried with Refresh and Update methods, but it doesn't work...
can you help me?
Thank you,
Niksa
|
|
|
|
|
Check where you are binding your datagridview
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
Hy,
I'm really new to C# programming and I have a few problems with data binding.
I am building a Windows application.
I have two tables in my database and they are related.
First table is named Author (and has these fields: AuthorID, AuthorName),
and the other one is named Books (BooksID, AuthorID -> this is a Foreign Key, and BookTitle).
My question is: How can I (using a form) change the data in my database?
I have found a lot of tutorials, but they didn't really helped me. All they suggest is that I can relate tables on a form by dragging AuthorName from the Author table on AuthorID from the Books table. But if I do that, Authors are displayed in combobox so I can't enter a new author if I want to enter new data...
I know that I probably made it sound really confusing, so I apologize in advance
Thanks
|
|
|
|
|
Alessandra77 wrote: I'm really new to C# programming
Alessandra77 wrote: I have two tables in my database and they are related.
If you're REALLY new, then you're probably diving in a little too deep.
Alessandra77 wrote: How can I (using a form) change the data in my database?
Your form should ideally just display the data, and call a middle tier that knows about books and authors, and which then calls a data layer that knows how to persist your data to the DB.
There's two UI approachs to take, one is to show your data in a grid and support entering new data which is then saved, the other is to have a seperate form that shows your fields and you enter them to have them entered into your DB.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|