Click here to Skip to main content
16,020,182 members
Home / Discussions / C#
   

C#

 
Generali Pin
bigchump12-Jun-08 12:31
bigchump12-Jun-08 12:31 
GeneralRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
bigchump12-Jun-08 12:53
bigchump12-Jun-08 12:53 
QuestionRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
Michael Schubert12-Jun-08 20:47
Michael Schubert12-Jun-08 20:47 
GeneralRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
#realJSOP12-Jun-08 10:52
professional#realJSOP12-Jun-08 10:52 
GeneralRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
bigchump12-Jun-08 12:37
bigchump12-Jun-08 12:37 
AnswerRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
Simon P Stevens12-Jun-08 22:01
Simon P Stevens12-Jun-08 22:01 
GeneralRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
bigchump13-Jun-08 5:33
bigchump13-Jun-08 5:33 
GeneralRe: AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION Pin
Simon P Stevens15-Jun-08 23:34
Simon P Stevens15-Jun-08 23:34 
With serialzation, all public members of the object are serialized. Is this what you want? If you have some members you don't want to be serialized you can mark them with attributes to prevent this.

Check that your problem is not with your code logic. Step through carefully and check that you aren't accidently serializing more than you meant too. (Like the same object twice).

If you switch to xml serialization you can look at the data and check that only the correct stuff is there. Then once your happy with the data being outputed, switch back to binary again.

Comments on the code (Numbers indicate line in code I'm talking about):
1) The for loop here is incomplete. I'm assuming you just want to loop through all objects in the array h, buy maybe more code is missing.
2) the variable a is never assigned a value other than 0. What is it's purpose?
3) For every line read in that starts with JJGENDRACE you are serializing the whole of the array h. I don't know whats in this array as you haven't included it's defination or population code, but why are you serializing the same array every time? This will be a huge waste of space if you are just serializing the same data over and over again.

General comment: The variable names c, s, b, t, a, x and y are not very useful. If you used more descriptive veriable names that would help other people to read your code.

        public void SerializeNow()
        {
            header c = new header();
            Stream s = File.Open(@"C:\baduga\manure.tmp", FileMode.Append);
            BinaryFormatter b = new BinaryFormatter();
            FileStream hread = new FileStream(@"c:\baduga\races.txt", FileMode.Open); //read races.txt
            StreamReader hread1 = new StreamReader(hread);
            string temp;
            string[] t = new string[1435];
            int a = 0, x = 0, y;
            while ((temp = hread1.ReadLine()) != null)
            {
                if (temp.StartsWith("JJGENDRACE"))
                {
2)                  c.entries = a;
                    b.Serialize(s, c);
1)                  for (y = 0; y
                    {
3)                      b.Serialize(s, h[y]);
                    }
                    a = x = 0;
                }
                else
                {
                    t[x] = temp;
                    if (t[x] == "")
                        t[x] = "0";
                    x++;
                    if (x == 1435)
                    {
                        if (a == 0)
                        {
                            c.track = t[0];
                            c.date = t[1];
                            c.race = t[2];
                            c.distance = int.Parse(t[5].Trim('-'));
                            c.distanceD = c.distance / 220;
                            c.surface = t[6];
                            c.type = t[8];
                            c.sex = t[9];
                            c.formtype = t[10];
                            c.purse = int.Parse(t[11]);
                            c.purseD = c.purse / 5000;
                            if (c.purseD > 50)
                                c.purseD = 50;
                            c.claimprice = int.Parse(t[12]);
                            c.trackrecord = float.Parse(t[14]);
                            c.simulT = t[20];
                            c.simulR = t[21];
                            c.breed = t[22];
                            c.poly = t[24];
                            c.par2f = int.Parse(t[213]);
                            c.par4f = int.Parse(t[214]);
                            c.par6f = int.Parse(t[215]);
                            c.parspeed = int.Parse(t[216]);
                            c.parLf = int.Parse(t[217]);
                        }
                    }
                }
            }
        }


Simon

QuestionWebservice question Pin
johland12-Jun-08 5:42
johland12-Jun-08 5:42 
AnswerRe: Webservice question Pin
Christian Graus12-Jun-08 6:05
protectorChristian Graus12-Jun-08 6:05 
GeneralRe: Webservice question Pin
johland12-Jun-08 6:37
johland12-Jun-08 6:37 
GeneralRe: Webservice question Pin
Christian Graus12-Jun-08 6:40
protectorChristian Graus12-Jun-08 6:40 
AnswerRe: Webservice question Pin
Christian Graus12-Jun-08 6:36
protectorChristian Graus12-Jun-08 6:36 
GeneralRe: Webservice question Pin
johland12-Jun-08 7:09
johland12-Jun-08 7:09 
GeneralRe: Webservice question Pin
Christian Graus12-Jun-08 7:26
protectorChristian Graus12-Jun-08 7:26 
GeneralRe: Webservice question Pin
johland12-Jun-08 10:02
johland12-Jun-08 10:02 
QuestionHow to find some value in HashTable ? Pin
Yanshof12-Jun-08 5:08
Yanshof12-Jun-08 5:08 
AnswerRe: How to find some value in HashTable ? PinPopular
Christian Graus12-Jun-08 5:11
protectorChristian Graus12-Jun-08 5:11 
AnswerRe: How to find some value in HashTable ? Pin
Brady Kelly12-Jun-08 5:38
Brady Kelly12-Jun-08 5:38 
QuestionWrite to PDF file Pin
Verghese12-Jun-08 5:03
Verghese12-Jun-08 5:03 
AnswerRe: Write to PDF file Pin
Christian Graus12-Jun-08 5:10
protectorChristian Graus12-Jun-08 5:10 
QuestionTimeSpan beginners question Pin
NewToAspDotNet12-Jun-08 3:45
NewToAspDotNet12-Jun-08 3:45 
AnswerRe: TimeSpan beginners question Pin
Simon P Stevens12-Jun-08 3:57
Simon P Stevens12-Jun-08 3:57 
QuestionHow to Remove the Duplicate Key(Repeated data) in CSV or Excel file using C# . Pin
bruze12-Jun-08 2:38
bruze12-Jun-08 2:38 
AnswerRe: How to Remove the Duplicate Key(Repeated data) in CSV or Excel file using C# . Pin
Simon P Stevens12-Jun-08 4:02
Simon P Stevens12-Jun-08 4:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.