|
I have solved the issue I was having, thank you, I have learned two lessons from this
"Never Use Cut & Paste Code Directly" always look at what you are doing!,
when in stuck "have a coffee, deal with a grateful customer (they do exist at times)"
and then return to piece of code that is causing trouble. What was causing the issue
Console.WriteLine("Driver name: {0} - Version : [1} - Date {2}",
driver.DeviceName, driver.DriverVersion ?? "No version", driver.DriverDate ?? "No date"); I had stupidly copied across not really paying attention [ not {, stupid, stupid, dunces cap on! sorry Pete and thanks for the help answering my stupid questions.
|
|
|
|
|
My apologies for the bum steer. I just knocked this up in the CP message box, so I missed that. Good job though.
|
|
|
|
|
No worries, how do I up vote you as you have gone overboard helping I owe you a beer! (if you are ever in Bristol)
|
|
|
|
|
There's no need to upvote me. I'm not really that bothered about rep points. Simply mark the thread as SOLVED (edit your original post and put SOLVED at the end of the title) and that will do me.
Now, the beer on the other hand...
|
|
|
|
|
|
|
DataSet testvalue = getdata();
testvalue.Relations.Add(new DataRelation("parentChildCategories", testvalue.Tables[0].Columns["lob_parent_id"], testvalue.Tables[0].Columns["lob_id"], false));
TreeView1.DataSource = testvalue;
TreeView1.DataBind();
|
|
|
|
|
|
Was that an existential query?
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace multiplication
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[2, 2] { { 1, 2 }, { 3, 4 } };
int[,] b = new int[2, 2] { { 1, 2 }, { 3, 4 } };
int[,] c = new int[2, 2];
for (int i = 0; i <= a.Length; i++)
{
for (int j = 0; j <= b.Length; j++)
{
c[i, j] = (a[i, j] * b[i, j])+(a[i,,j+1]*b[i+1,,j]);
Console.Write(c[i, j]+ " " );
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
erorr is like
Index was outside the bounds of the array.
j somasekhar
modified 4-Jul-12 8:36am.
|
|
|
|
|
Please include the error-text, and the result that you were aiming for - ie, what should the code do?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
At first glance, there's a syntax error here (...) (a[i,,j+1]*b[i+1,,j]) (...) - note the consecutive commas, lose one of each.
Like this:
c[i, j] = (a[i, j] * b[i, j])+(a[i,j+1]*b[i+1,j]);
2A
|
|
|
|
|
For those who can't read minds, the exception you are getting is an out of bounds exception. The area that you are hitting this exception is here:
(a[i, j + 1] * b[i + 1, j]) The reason you are hitting this is because j+1 is 2 after the first iteration of j, which is outside of the bounds of the array. As I'm not sure what effect you are aiming at here, I can't really offer any concrete solution other than to say that you need to think through your logic here.
BTW - what length do you think is represented as a.Length or b.Length . It's not the 2 you're expecting; it's 4. Also, you are using <= in your conditions and it should be < only.
|
|
|
|
|
Nice catch! Have a five.
After spotting the syntax error in the code sample, I directly assumed that was the problem and stopped thinking right there...
2A
|
|
|
|
|
I spotted that error and figured it was just an error putting it into the CP editor. As soon as I saw that it was arrays and looping, I knew he'd have an out of bounds error in there somewhere. The rest was just figuring out where it was.
|
|
|
|
|
.
If that is meant to perform a matrix multiplication, then:
1.
it would require 3 nested loops, not 2, as each element (that is 2 loops) of the result matrix is to equal the inner product of one row and one column (that is the third loop, dealing with both the row of a and the column of b)
2.
I would not waste time on doing a specific case; instead use variable dimensions to make it general-purpose.
3.
And unless you want this as an exercise, there is a Matrix class that does it all for you, no hassle.
See e.g. here[^]
|
|
|
|
|
I have a stream object coming from mobile client in binary fromat as follows
name=tony&image=....raw binary representation of an image.....
I would like to extract the image out of the stream. I can extract the image and show it fine as long as string size preceding the binary image data is 16 chars or less! ("name=tony&image=") is 16 chars long
bool PostData(Stream stream)
{
using (FileStream filetoUpload = new FileStream(filePath + "ImageFromBytes.jpg", FileMode.Create))
{
byte[] byteArray = new byte[10000];
int bytesRead = 0;
bytesRead = stream.Read(byteArray, 0, byteArray.Length);
if (bytesRead > 0)
filetoUpload.Write(byteArray, 16, bytesRead-16);
....
}
}
If I do("name=randy&image=") = 17 chars long, it doesn't work, the image shows the right size, but can't be opened.
name=randy&image=....raw binary representation of an image.....
filetoUpload.Write(byteArray, 17, bytesRead-17);
Any ideas what in the world is going on?
|
|
|
|
|
I answered this question yesterday and explained that you need to parse the input stream. You cannot assume that every name will be only 4 characters long. You already have the marker characters that separate your objects (& ) and keyword value pairs (= ), so you should be scanning your input stream for those characters to split the data into its constituent parts.
|
|
|
|
|
Software2007 wrote: Any ideas what in the world is going on?
Sure - you have a randy image.
As you've discovered, you can't rely on fixed lengths in your string here - instead, you need to find the index of the second =. You can do this with string.IndexOf to find it. The good news is that you know where the first = is based on your key here, so all you need to do is use IndexOf starting on the value 5 (the position after name= in your string).
|
|
|
|
|
Pete O'Hanlon wrote: use IndexOf starting on the value 5 Not really a good suggestion based on the original question[^]. I get the impression he is trying to solve the problem by modifying the input data rather than getting to grips with the concept of parsing it.
|
|
|
|
|
Ah. I wasn't aware that he'd had an original question. Ho hum.
|
|
|
|
|
Another one that's probably going to run and run ...
|
|
|
|
|
|
Software2007 wrote: the image shows the right size
where? how?
Software2007 wrote: but can't be opened
when? by what program?
has your app exited already? did you wait a full minute and try again?
Please start taking the answers you get more seriously, and provide more detailed accurate information, so we all can help you more effectively.
|
|
|
|
|
Luc: The image doesn't open up on disk, meaning I can't view the image.
I have split the stream based on '&'. The bytes array apparently is full of them when it comes to image raw binary data. So, I decided to parse the string to the left of "image=". This is not where the problem is, the problem is after parsing, for the remaining image bytes, why can't I open the image correctly if the preceding string happens to be more than 16 chars long? The code above is only psuedo code, in reality this will be much longer string.
modified 4-Jul-12 13:24pm.
|
|
|
|