Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › How to read inside value with out doing this?
New Posts  All Forums:Forum Nav:

How to read inside value with out doing this?

post #1 of 5
Thread Starter 
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:

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
    }
}
Super Athlon
(13 items)
 
Ultra Intel
(14 items)
 
 
CPUMotherboardGraphicsRAM
Athlon 64 FX-62 Windsor GIGABYTE GA-M59SLI-S5 AM2 ATI RADEON HD 5770 SUPER TALENT 4GB (4 x 1GB) 240-Pin DDR2 800 
Hard DriveOSMonitorKeyboard
SCSI 15000 RPM OS + 250GB 7200 SATA II Linux 9.10 Karmic Kaola EMPTY ATM Saitek Ultra 
PowerCaseMouseMouse Pad
750W cheap one Custom Made DYNEX DELL 
CPUMotherboardGraphicsRAM
Intel I7 2600K S 1155 046MHW 1 x GTX 980 8GB DDR3 Cas9 1866Mhz 
Hard DriveHard DriveCoolingOS
2x Vertex 3 Raid 0 2x TB Raid 0 Hitachi Storage Hydro H70 7 Ultimage + Linux Gutsy 7.10 
MonitorKeyboardPowerCase
VX2268WM Saitek Ultra 875 WATTS Alien Aurora R3 Modded 
MouseMouse Pad
G9X Xtrac RIPPER 
CPUMotherboardGraphicsRAM
PHENOM II X4 955 4.0 GHZ 790FX-GD70 GTX 480 8192 
Hard DriveOSMonitorKeyboard
2 SSD Vertex 2 @ Raid 0. 2 250HDD's @ Raid 0 1 350 Linux 7.10 Gutsy + Windows 7 Ultimate 64 Samsung 21.5 Saitek Ultra 
PowerCaseMouseMouse Pad
Thermaltake Black Widow W0319RU 850W ATX 12V v2.3 Thermaltake Armor A90 Black Steel DYNEX DELL 
  hide details  
Reply
Super Athlon
(13 items)
 
Ultra Intel
(14 items)
 
 
CPUMotherboardGraphicsRAM
Athlon 64 FX-62 Windsor GIGABYTE GA-M59SLI-S5 AM2 ATI RADEON HD 5770 SUPER TALENT 4GB (4 x 1GB) 240-Pin DDR2 800 
Hard DriveOSMonitorKeyboard
SCSI 15000 RPM OS + 250GB 7200 SATA II Linux 9.10 Karmic Kaola EMPTY ATM Saitek Ultra 
PowerCaseMouseMouse Pad
750W cheap one Custom Made DYNEX DELL 
CPUMotherboardGraphicsRAM
Intel I7 2600K S 1155 046MHW 1 x GTX 980 8GB DDR3 Cas9 1866Mhz 
Hard DriveHard DriveCoolingOS
2x Vertex 3 Raid 0 2x TB Raid 0 Hitachi Storage Hydro H70 7 Ultimage + Linux Gutsy 7.10 
MonitorKeyboardPowerCase
VX2268WM Saitek Ultra 875 WATTS Alien Aurora R3 Modded 
MouseMouse Pad
G9X Xtrac RIPPER 
CPUMotherboardGraphicsRAM
PHENOM II X4 955 4.0 GHZ 790FX-GD70 GTX 480 8192 
Hard DriveOSMonitorKeyboard
2 SSD Vertex 2 @ Raid 0. 2 250HDD's @ Raid 0 1 350 Linux 7.10 Gutsy + Windows 7 Ultimate 64 Samsung 21.5 Saitek Ultra 
PowerCaseMouseMouse Pad
Thermaltake Black Widow W0319RU 850W ATX 12V v2.3 Thermaltake Armor A90 Black Steel DYNEX DELL 
  hide details  
Reply
post #2 of 5
You should be able to just save it as a variable. No need to use textboxes in the first place.
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:
int serverV;
serverV = Convert.ToInt32(TBserver.Text);
serverV = int.Parse(TBserver.Text);
You should be able to accomplish the same thing with:
Code:
int serverV;
serverV = int.Parse(TBserver.Text);
The Beast
(12 items)
 
  
CPUCPUMotherboardGraphics
Xeon x5670 Xeon X5670 Supermicro X8DT3-LN4F NVIDIA Quadro FX 580 
RAMHard DriveMonitorKeyboard
96GB DDR3 RDIMM Corsair Force GT HP LP2480zx Corsair K95 RGB with Brown switches 
PowerCaseMouseAudio
Corsair RM1000i Corsair Obsidian 750D Logitech MX1100 Creative X-Fi Platinum 
  hide details  
Reply
The Beast
(12 items)
 
  
CPUCPUMotherboardGraphics
Xeon x5670 Xeon X5670 Supermicro X8DT3-LN4F NVIDIA Quadro FX 580 
RAMHard DriveMonitorKeyboard
96GB DDR3 RDIMM Corsair Force GT HP LP2480zx Corsair K95 RGB with Brown switches 
PowerCaseMouseAudio
Corsair RM1000i Corsair Obsidian 750D Logitech MX1100 Creative X-Fi Platinum 
  hide details  
Reply
post #3 of 5
Thread Starter 
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:
//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:
int serverV;
serverV = Convert.ToInt32(TBserver.Text);
serverV = int.Parse(TBserver.Text);
You should be able to accomplish the same thing with:
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:
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
Super Athlon
(13 items)
 
Ultra Intel
(14 items)
 
 
CPUMotherboardGraphicsRAM
Athlon 64 FX-62 Windsor GIGABYTE GA-M59SLI-S5 AM2 ATI RADEON HD 5770 SUPER TALENT 4GB (4 x 1GB) 240-Pin DDR2 800 
Hard DriveOSMonitorKeyboard
SCSI 15000 RPM OS + 250GB 7200 SATA II Linux 9.10 Karmic Kaola EMPTY ATM Saitek Ultra 
PowerCaseMouseMouse Pad
750W cheap one Custom Made DYNEX DELL 
CPUMotherboardGraphicsRAM
Intel I7 2600K S 1155 046MHW 1 x GTX 980 8GB DDR3 Cas9 1866Mhz 
Hard DriveHard DriveCoolingOS
2x Vertex 3 Raid 0 2x TB Raid 0 Hitachi Storage Hydro H70 7 Ultimage + Linux Gutsy 7.10 
MonitorKeyboardPowerCase
VX2268WM Saitek Ultra 875 WATTS Alien Aurora R3 Modded 
MouseMouse Pad
G9X Xtrac RIPPER 
CPUMotherboardGraphicsRAM
PHENOM II X4 955 4.0 GHZ 790FX-GD70 GTX 480 8192 
Hard DriveOSMonitorKeyboard
2 SSD Vertex 2 @ Raid 0. 2 250HDD's @ Raid 0 1 350 Linux 7.10 Gutsy + Windows 7 Ultimate 64 Samsung 21.5 Saitek Ultra 
PowerCaseMouseMouse Pad
Thermaltake Black Widow W0319RU 850W ATX 12V v2.3 Thermaltake Armor A90 Black Steel DYNEX DELL 
  hide details  
Reply
Super Athlon
(13 items)
 
Ultra Intel
(14 items)
 
 
CPUMotherboardGraphicsRAM
Athlon 64 FX-62 Windsor GIGABYTE GA-M59SLI-S5 AM2 ATI RADEON HD 5770 SUPER TALENT 4GB (4 x 1GB) 240-Pin DDR2 800 
Hard DriveOSMonitorKeyboard
SCSI 15000 RPM OS + 250GB 7200 SATA II Linux 9.10 Karmic Kaola EMPTY ATM Saitek Ultra 
PowerCaseMouseMouse Pad
750W cheap one Custom Made DYNEX DELL 
CPUMotherboardGraphicsRAM
Intel I7 2600K S 1155 046MHW 1 x GTX 980 8GB DDR3 Cas9 1866Mhz 
Hard DriveHard DriveCoolingOS
2x Vertex 3 Raid 0 2x TB Raid 0 Hitachi Storage Hydro H70 7 Ultimage + Linux Gutsy 7.10 
MonitorKeyboardPowerCase
VX2268WM Saitek Ultra 875 WATTS Alien Aurora R3 Modded 
MouseMouse Pad
G9X Xtrac RIPPER 
CPUMotherboardGraphicsRAM
PHENOM II X4 955 4.0 GHZ 790FX-GD70 GTX 480 8192 
Hard DriveOSMonitorKeyboard
2 SSD Vertex 2 @ Raid 0. 2 250HDD's @ Raid 0 1 350 Linux 7.10 Gutsy + Windows 7 Ultimate 64 Samsung 21.5 Saitek Ultra 
PowerCaseMouseMouse Pad
Thermaltake Black Widow W0319RU 850W ATX 12V v2.3 Thermaltake Armor A90 Black Steel DYNEX DELL 
  hide details  
Reply
post #4 of 5
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.
The Beast
(12 items)
 
  
CPUCPUMotherboardGraphics
Xeon x5670 Xeon X5670 Supermicro X8DT3-LN4F NVIDIA Quadro FX 580 
RAMHard DriveMonitorKeyboard
96GB DDR3 RDIMM Corsair Force GT HP LP2480zx Corsair K95 RGB with Brown switches 
PowerCaseMouseAudio
Corsair RM1000i Corsair Obsidian 750D Logitech MX1100 Creative X-Fi Platinum 
  hide details  
Reply
The Beast
(12 items)
 
  
CPUCPUMotherboardGraphics
Xeon x5670 Xeon X5670 Supermicro X8DT3-LN4F NVIDIA Quadro FX 580 
RAMHard DriveMonitorKeyboard
96GB DDR3 RDIMM Corsair Force GT HP LP2480zx Corsair K95 RGB with Brown switches 
PowerCaseMouseAudio
Corsair RM1000i Corsair Obsidian 750D Logitech MX1100 Creative X-Fi Platinum 
  hide details  
Reply
post #5 of 5
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?
Edited by Sunriselad - 1/11/11 at 12:23pm
    
CPUMotherboardGraphicsRAM
I7 920 Gigabyte EX58 XFX Radeon 4870 X2 6GB Corsair 
Hard DriveOptical DriveOSMonitor
500GB Maxtor LG DVDRW Vista Ultimate x64 2 x Edge IO 22" 
KeyboardPowerMouseMouse Pad
Razer Arctosa XFX 800w BTC Cheetah Gaming Mouse None 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
I7 920 Gigabyte EX58 XFX Radeon 4870 X2 6GB Corsair 
Hard DriveOptical DriveOSMonitor
500GB Maxtor LG DVDRW Vista Ultimate x64 2 x Edge IO 22" 
KeyboardPowerMouseMouse Pad
Razer Arctosa XFX 800w BTC Cheetah Gaming Mouse None 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › How to read inside value with out doing this?