3 Replies - 9187 Views - Last Post: 01 January 2012 - 06:40 PM Rate Topic: -----

#1 galexu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-December 11

sum question/problem in c#

Posted 01 January 2012 - 03:17 PM

Hello,

bellow you can see 2 programs, that on right side is the original program and that on the left side is program developed by me..
the original program still works, but the developer stopped to update it.. that's why i try to create a new one.

Posted Image

well,problem is that I don't know how to cumulate some values
for example see on the right side on MCB-25: 920, and on left side 240 if i click on my program button start and another value comes at MCB-25: it replaces the old one, i want to cumulate those values.


bellow is the code of this form..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Web;
using System.Net;
using System.IO.Compression;
using System.Text.RegularExpressions;
using System.Net.Sockets;

namespace account_manager
{
    public partial class Form5 : Form
    {

        static string sServer = "", sURL = "", uid = "", sid = "";
        static string aid = "", item_type = "", item_id = "", gate_id = "", state = "";
        static string responseFromServer = string.Empty, amount = "";
        static string sCookDosId = string.Empty, sSID = string.Empty;
        static WebRequest reqPOST;
        static System.Net.WebResponse result;
        static StreamReader reader;



        public Form5(string s, string s1, string s2, string s3)
        {
            InitializeComponent();

            uid = s;
            sid = s1;
            sServer = s2;
            aid = s3;
        }
        
        static void setHeaders(ref WebRequest reqPOST, string sServer, string sURL)
        {
            

            reqPOST = System.Net.WebRequest.Create(sURL);
            reqPOST.Method = "GET";
            ((HttpWebRequest)reqPOST).UserAgent = "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.60";
            ((HttpWebRequest)reqPOST).Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight, */*";
            reqPOST.Headers.Add("Accept-Language", "en-US,en;q=0.9");
            reqPOST.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
            reqPOST.Headers.Add("Accept-Encoding", "gzip, deflate");
            reqPOST.Headers.Add("Cookie2", "$Version=1");
            
        }

        static void setHeaders1(ref WebRequest reqPOST, string sServer, string sURL)
        {


            reqPOST = System.Net.WebRequest.Create(sURL);
            reqPOST.Method = "GET";
            ((HttpWebRequest)reqPOST).UserAgent = "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.60";
            reqPOST.Headers.Add("Accept-Language", "en-US,en;q=0.9");
            reqPOST.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
            reqPOST.Headers.Add("Accept-Encoding", "gzip, deflate");
            ((HttpWebRequest)reqPOST).KeepAlive = true;
            
            
        }
        static void getResponse(ref WebRequest reqPOST, ref WebResponse result, ref StreamReader reader, ref string responseFromServer)
        {
            result = reqPOST.GetResponse();
            if (result.Headers.Get("Content-Encoding") != null && result.Headers.Get("Content-Encoding").ToLower() == "gzip")
                reader = new System.IO.StreamReader(new GZipStream(result.GetResponseStream(), CompressionMode.Decompress));
            else
                reader = new System.IO.StreamReader(result.GetResponseStream());
            responseFromServer = reader.ReadToEnd();
        }
 
        static void getResponse_new()
        {
            result = reqPOST.GetResponse();
            if (result.Headers.Get("Content-Encoding") != null && result.Headers.Get("Content-Encoding").ToLower() == "gzip")
                reader = new System.IO.StreamReader(new GZipStream(result.GetResponseStream(), CompressionMode.Decompress));
            else
                reader = new System.IO.StreamReader(result.GetResponseStream());
            responseFromServer = reader.ReadToEnd();
        }
        static string find_str_from_to(string sMain, string sFrom, string sTo)
        {
            int iBegSubstr = sMain.IndexOf(sFrom);
            if (iBegSubstr == -1) return "-1";
            int iEndSubstr = sMain.IndexOf(sTo, iBegSubstr);
            if (iEndSubstr == -1) return "-1";
            return sMain.Substring(iBegSubstr, iEndSubstr - iBegSubstr);
        }

 
        static string find_str_from_to2(string sMain, string sFrom, string sTo)
        {
            int iBegSubstr = sMain.IndexOf(sFrom);
            if (iBegSubstr == -1) return "-1";
            iBegSubstr += sFrom.Length;
            int iEndSubstr = sMain.IndexOf(sTo, iBegSubstr);
            if (iEndSubstr == -1) return "-1";
            return sMain.Substring(iBegSubstr, iEndSubstr - iBegSubstr);
        }
        private void button1_Click(object sender, EventArgs e)
        {

            do_click();

        }

        public void do_click()
        {
            WebRequest reqPOST = null;
            System.IO.StreamReader reader = null;
            string sURL;
            System.Net.WebResponse result = null;

            sURL = "http://" + sServer + ".darkorbit.bigpoint.com/flashinput/galaxyGates.php?userID=" + uid + "&action=multiEnergy&sid=" + sid + "&sample=1";
            setHeaders1(ref reqPOST, sServer, sURL);
            reqPOST.Headers.Add("Cookie", "aid=" + aid + "; " + "dosid=" + sid);
            getResponse(ref reqPOST, ref result, ref reader, ref responseFromServer);
            result = reqPOST.GetResponse();

            item_type = find_str_from_to2(responseFromServer, "<item type=\"", "\"");
            if (item_type == "battery" || item_type == "rocket" || item_type == "ore")
            {
                item_id = find_str_from_to2(responseFromServer, "item_id=\"", "\"");
                amount = find_str_from_to2(responseFromServer, "amount=\"", "\"");
            }
            else if (item_type == "logfile" || item_type == "hitpoints" || item_type == "voucher")
            {
                amount = find_str_from_to2(responseFromServer, "amount=\"", "\"");
            }
            else if (item_type == "part")
            {
                state = find_str_from_to(responseFromServer, "\" date=", "\"");

                gate_id = find_str_from_to2(responseFromServer, "gate_id=\"", "\"");
            }
            if (state == "in progress")
            {
                amount = "1";
            }
            else if (state == "-1")
            {
                amount = "0";
            }

            if (item_type == "battery" & item_id == "2")
            {
                label18.Text = amount;
            }
            else if (item_type == "battery" & item_id == "3")
            {
                label19.Text = amount;
            }
            else if (item_type == "battery" & item_id == "4")
            {
                label20.Text = amount;
            }
            else if (item_type == "battery" & item_id == "5")
            {
                label21.Text = amount;
            }
            else if (item_type == "rocket" & item_id == "3")
            {
                label22.Text = amount;
            }
            else if (item_type == "rocket" & item_id == "11")
            {
                label23.Text = amount;
            }
            else if (item_type == "ore" & item_id == "4")
            {
                label27.Text = amount;
            }
            else if (item_type == "logfile")
            {
                label24.Text = amount;
            }
            else if (item_type == "hitpoints")
            {
                label25.Text = amount;
            }
            else if (item_type == "voucher")
            {
                label26.Text = amount;
            }
            else if (item_type == "part" && gate_id == "1")
            {
                label28.Text = amount;
            }
            else if (item_type == "part" && gate_id == "2")
            {
                label29.Text = amount;
            }
            else if (item_type == "part" && gate_id == "3")
            {
                label30.Text = amount;
            }
            else if (item_type == "part" && gate_id == "4")
            {
                label31.Text = amount;
            }
            else if (item_type == "part" && gate_id == "5")
            {
                label32.Text = amount;
            }
            else if (item_type == "part" && gate_id == "6")
            {
                label33.Text = amount;
            }
         //   MessageBox.Show(state);
          //  MessageBox.Show(responseFromServer);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }      
    }
}



thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: sum question/problem in c#

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: sum question/problem in c#

Posted 01 January 2012 - 03:25 PM

Quote

i want to cumulate those values.


That doesn't really mean much in English. What is you want to do when a new value comes in?
Add the new and the old?
Replace the old with the new?
Average all the values as they come in?
Was This Post Helpful? 0
  • +
  • -

#3 divaricatorn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-January 12

Re: sum question/problem in c#

Posted 01 January 2012 - 04:26 PM

If cumulate means add, you should

1) save your current value
2) add the new value to the saved value
3) put the result in the textbox

 
double myCurrentValue = double.Parse(txtMCB25.Text);
myCurrentValue += myAddedValue;
txtMCB25.Text = myCurrentValue.ToString();


Was This Post Helpful? 0
  • +
  • -

#4 RexGrammer   User is offline

  • Coding Dynamo
  • member icon

Reputation: 183
  • View blog
  • Posts: 785
  • Joined: 27-October 11

Re: sum question/problem in c#

Posted 01 January 2012 - 06:40 PM

By 'cumulate' you mean to add the values up?

You can do this with a simple addition assignment operator:
myValue += valueToIncrementItBy;



Also maybe consider why the author has stopped updating it: Maybe it has outlived it's use (meaning: it doesn't serve a purpose anymore, or there is a better way of doing that), or is there some big design flaw... :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1