Overclock.net banner

1 - 5 of 5 Posts

·
Registered
Joined
·
323 Posts
Discussion Starter · #1 ·
Hello there guys ! ... I have a few questions about this code... Maybe some one could help? ... The code below works flowlessly ... but, I dont want to run it the way it is... it is like a Noob MickeyMouse what I got in it...

even though it works...

What does the code below do:
It is for software update pruporses...

1) It downloads versionS.txt from the server,
2) It transfers versionS.txt to textbox1 (which is number 2)
3) It transfer versionL.txt to textbox 2 (which is number 1)
4) convert string inside textbox to integer.

if versionS.txt has a greater value than the local one, the it will update the program...

it works FINE...

**Note that, the 2 textboxes that carries the values 2 and 1, are invisible...

How would you do the same thing, with out having those 2 invisible textboxes?


Thanks guys

Code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace Authenticate
{
    public partial class Authenticate : Form
    {
        public Authenticate()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int serverV;
            serverV = Convert.ToInt32(TBserver.Text);
            serverV = int.Parse(TBserver.Text);

            int localV;
            localV = Convert.ToInt32(TBlocal.Text);
            localV = int.Parse(TBlocal.Text);

            if (serverV > localV)
            { //DO THE UPDATE CODE }

            else
            { //DO NOT DO THE UPDATE CODE }

        }

        private void Authenticate_Load(object sender, EventArgs e)
        {

            WebClient Client = new WebClient();
            Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            Client.DownloadFileAsync(new Uri("http://98.118.57.8/anti/version.txt"), "versionS.txt");

        }

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            //progressBar1.Value = e.ProgressPercentage;
        }

        private void Completed(object sender, AsyncCompletedEventArgs e) {

StreamReader SRlocal = new StreamReader("versionL.txt");
TBlocal.Text = SRlocal.ReadToEnd();
SRlocal.Close();

StreamReader SLserver = new StreamReader("versionS.txt");
TBserver.Text = SLserver.ReadToEnd();
SLserver.Close();

        }//what ever to do after completed
    }
}
 

·
Programmer
Joined
·
350 Posts
You should be able to just save it as a variable. No need to use textboxes in the first place.

Code:
Code:
//Replace this:
TBlocal.Text = SRlocal.ReadToEnd();

//With this:
String tblocal; //declare this globally in the form
tblocal = SRlocal.ReadToEnd();
Basically, you're using a string variable instead of a whole textbox. (The Text property of a textbox essentially acts as a string variable.)

What's the point of the following code, if I may ask?

Code:
Code:
int serverV;
serverV = Convert.ToInt32(TBserver.Text);
serverV = int.Parse(TBserver.Text);
You should be able to accomplish the same thing with:

Code:
Code:
int serverV;
serverV = int.Parse(TBserver.Text);
 
  • Rep+
Reactions: thiagocosta85

·
Registered
Joined
·
323 Posts
Discussion Starter · #3 ·
Quote:


Originally Posted by nookkin
View Post

You should be able to just save it as a variable. No need to use textboxes in the first place.

Code:
Code:
//Replace this:
TBlocal.Text = SRlocal.ReadToEnd();

//With this:
String tblocal; //declare this globally in the form
tblocal = SRlocal.ReadToEnd();
Basically, you're using a string variable instead of a whole textbox. (The Text property of a textbox essentially acts as a string variable.)

What's the point of the following code, if I may ask?

Code:
Code:
int serverV;
serverV = Convert.ToInt32(TBserver.Text);
serverV = int.Parse(TBserver.Text);
You should be able to accomplish the same thing with:

Code:
Code:
int serverV;
serverV = int.Parse(TBserver.Text);

hey... Thank you so much bro...

yeah, that string really does the job...

What's the point of the following code, if I may ask?

Code:
Code:
int serverV;
serverV = Convert.ToInt32(TBserver.Text);
serverV = int.Parse(TBserver.Text);
I had to use this code because, I am using a bool below, and it won't allow strings to do it... so I had to convert it to int ! It worked !!!..

But should I skip Convert.ToInt32 ?

------EDIT----------

Came to edit this to thank you one more time.. !!!!

THANKS 1000x bro !.. TY TY
 

·
Programmer
Joined
·
350 Posts
You'd skip Convert.ToInt32 because the int.Parse() line immediately below it will overwrite it.

If you're trying to convert a string to a bool, try using Convert.toBoolean() instead. A non-zero int will be evaluated as a bool in an If statement, but it's better coding practice to use types for their intended purposes.
 
  • Rep+
Reactions: thiagocosta85

·
Registered
Joined
·
74 Posts
I know this might be slightly off topic but if this is a method you are using for updating your app if a newer one is on the url, you may find "One Click Deployment" an option worth looking at.

p.s. What do you use IMP REC for? Rebuilding Import table from upacked files?
 
1 - 5 of 5 Posts
Top