|
It seems you split dataString[i] to form stringArray , but then don't access that. Your call to dataString[0].Substring(j,2) should probably be for stringArray , but I don't think you need to deal with the digits separately anyway (I think what you're doing with them is probably wrong); how about something like:
wBuf[line++] = System.Byte.Parse
(
stringArray [ j ]
,
System.Globalization.NumberStyles.HexNumber
,
null
) ;
|
|
|
|
|
Sorry about the mis-naming of my variables. myStringArr is the same as dataString. Yes, when I do the Convert.ToByte, I should be using stringArray instead. I had to re-name things to put on the website and I made mistakes.
|
|
|
|
|
Here is a quick and dirty way:
...
string[] dataString = { "40 A8", "AA A8", "00 4E" };
byte[] bytes = ConvertToBytes(dataString);
...
private byte[] ConvertToBytes(string[] data)
{
List<byte> bytes = new List<byte>();
foreach (string line in data)
{
string[] values = line.Split(' ');
foreach (string value in values)
{
bytes.Add(byte.Parse(value, System.Globalization.NumberStyles.HexNumber));
}
}
return bytes.ToArray();
}
In the real world, you'd want error checking, and probably to look at the efficiency a bit if it is going to be used a fair amount - that isn't very efficient at all.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you so much! This works great. I just had to access values[0] and values[1] to store separately into the buffers. Plus I added some exception catching. Thanks!!!
Mich
|
|
|
|
|
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
What about if I'm going in the opposite direction? I want to take a string or byte array and each value which is shown in decimal, I want to convert to hex notation? wBuf is a byte[]. I tried this, but it's complaining:
int i = 0;
string[] values = new string[wBuf.Length];
foreach (byte value in wBuf)
{
string temp = wBuf[0].ToString();
values[i] = (temp, (System.Globalization.NumberStyles.HexNumber));
i++;
}
says "cannot convert lambda expression to type string because it is not delegate type".
I also tried:
foreach (byte value in wBuf)
{
values[i] = (byte.Parse(wBuf[i], (System.Globalization.NumberStyles.HexNumber)));
i++;
}
but it says "the best overloaded method match for 'byte.parse(string, system.iformatProvider)' has some invalid arguments".
Any ideas?? Thanks for your help.
modified 17-Apr-12 13:52pm.
|
|
|
|
|
Try:
byte[] wBuf = new byte[] { 23, 0xff, 17, 16 };
string[] values = new string[wBuf.Length];
int i = 0;
foreach (byte b in wBuf)
{
values[i++] = string.Format("{0:X00}", b);
}
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks!! That works really well. The only problem is that when I have a 0, it's showing it as 0 instead of 00. Any thoughts?
|
|
|
|
|
My fault - change the X00 to X02:
values[i++] = string.Format("{0:X02}", b);
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
|
friend give some example about a small project.that must be unique.plz say what type of project is best for me.in C#..//(small project)becz its my first
|
|
|
|
|
Write an app to take over the world.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
That might be a bit ambitious, "becz its my first." [sic]
Besides, I've been working on that for a couple of years now!
BDF
I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff
|
|
|
|
|
Clearly you have not finished, or we would have known by now.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Narf.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hello world with a twist. Can't guarantee it's unique though.
public class Goodbye
{
public static void Main()
{
System.Console.WriteLine("Goodbye, cruel world!");
}
}
"You get that on the big jobs."
|
|
|
|
|
Hi all !
I want o export 2 datagridview in 2 sheets of An Excel File .
some code for one DataGridView is Here :
...
Microsoft.Office.Interop.Excel.Worksheet mySheetInputData = null;
try
{
mySheetInputData = (Microsoft.Office.Interop.Excel.Worksheet)ExWorkBookInputData.Sheets["Sheet1"];
mySheetInputData = (Microsoft.Office.Interop.Excel.Worksheet)ExWorkBookInputData.ActiveSheet;
mySheetInputData.Name = "First Sheet";
for (int i = 1; i < dgv.Columns.Count + 1; i++)
{
mySheetInputData.Cells[1, i + 1] = dgv.Columns[i - 1].HeaderText;
}
for (int j = 1; j < dgv.Rows.Count + 1; j++)
{
mySheetInputData.Cells[j + 1, 1] = dgv.Rows[j - 1].HeaderCell.Value.ToString();
}
for (int i = 0; i < dgv.Rows.Count; i++)
{
for (int j = 0; j < dgv.Columns.Count; j++)
{
mySheetInputData.Cells[i + 2, j + 2] = dgv.Rows[i].Cells[j].Value.ToString();
}
}
string fileNameInputData = String.Empty;
SaveFileDlgInputData.Filter = "Excel Files (*.xlsx)|*.xlsx";
SaveFileDlgInputData.FilterIndex = 2;
SaveFileDlgInputData.RestoreDirectory = true;
if (SaveFileDlgInputData.ShowDialog() == DialogResult.OK)
{
fileNameInputData = SaveFileDlgInputData.FileName;
ExWorkBookInputData.SaveAs(fileNameInputData, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
else
return;
...
thanks for any help
|
|
|
|
|
Hello again CodeProject I'm having trouble integrating this codeproject barcode project code with my own barcode project. Heres the codeproj: Creating EAN-13 Barcodes with C#[^]
I have extreme difficulty when trying to create EAN13 barcodes myself so I wanted to use rainman_63's code with my project for my product's labels. Problem is I have no idea how to integrate it with mine, or ANY project.
1st) I add a class, and call it Ean13. Then I add 4 textboxes(name them appropriately like in rainman's project) then add buttons and the picturebox where you draw the barcode in the form1[Design].
2nd) I add partial class frmEan13 : Form to form1.cs
but I get this error when trying to build it: "The type or namespace name Ean13; could not be found (are you missing a using directive or an assembly reference?)"
Please help because I have NO idea how to integrate his Ean13 code with my project. Please don't flame me for being pretty new to C#
|
|
|
|
|
aquahoya wrote: The type or namespace name Ean13; could not be found (are you missing a using directive or an assembly reference?
This simply means that you have referenced a class or namespace that is not part of your project. It seems you need to add the class(es) from the article, or create your own class and add the necessary parts of the code.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hello aquahoya,
It sounds like the class Ean13 that you created in step 1 is in a different project from your main form that you created in step 2. If that is the case you need to do something like the following:
Find the "Solution Explorer" in Visual Studio and expand the project that contains your main form. Right click on "References" under that project and select "Add reference..." from the menu. Select the "Projects" tab from the dialog box that opens. It should contain "Ean13" in the list of projects. Select it and press the "OK" button.
This is based on Visual Studio 2010, if you have a different version it might be slightly different but the same process. Good luck.
BDF
I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff
|
|
|
|
|
I believe you're both right, but there isn't any projects once I click "ADD REFERENCE" even tho I added a new class called Ean13.cs
Since you can't attach screenshots I think, I uploaded it to a friends domain:
http://www.thewalkingdeadseason3.com/problem1.jpg
if you want me to upload the pic anywhere else let me know, or if u want me to make more screenshots so you can further help me I will.
Please help me guys
|
|
|
|
|
It looks like Ean13 is in the same project as the form, unlike what I had assumed. That's OK. Moving on, let's go back to the error message: "The type or namespace name Ean13; could not be found (are you missing a using directive or an assembly reference?)" We have ruled out the assembly reference reference so let's focus on the using directive.
Look in your source files, you'll see "namespace WindowsFormsApplication5" in the Form1.Designer.cs file. See what namespace is in the Ean13.cs file. In the article you're using, it's "namespace Ean13Barcode2005" or you might have changed it to something else. In the file where you're trying to use the Ean13 class, you'll need a using directive such as,
using Ean13Barcode2005;
This is to help the compiler can "find" the Ean13 class.
BDF
I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff
|
|
|
|
|
Thanks Farang for the help, but after I added 'using Ean13Barcode2005;' it DID in fact build, however when I try to use the button to create the barcode, it won't draw at all
Am I missing something in my new code that prevents the barcode from drawing to the picturebox?
So far thanks very much for your help you almost have this figured out for me
EDIT: wait I think it's a button_click problem. One second =)
modified 11-Apr-12 15:54pm.
|
|
|
|
|
Thanks so much everyone especially you Farang. If I have any further problems with this issue I'll be sure to let you know
thanks again!
|
|
|
|