Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)
New Posts  All Forums:Forum Nav:

Programmers' lounge. (Programming-related discussions only) - Page 39

post #381 of 1143
Ok, I have a new problem. I was making a backspace button, and when I was testing it out it crashed after I used it. Since the textfield was blank and I hit the backspace it caused my program to crash.

here is the error.


Edited by andyroo89 - 1/28/13 at 9:31pm
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #382 of 1143
Length of of text was zero (empty text) and you subtracted one from zero = -1
That's illegal for that call smile.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #383 of 1143
Quote:
Originally Posted by tompsonn View Post

Length of of text was zero (empty text) and you subtracted one from zero = -1
That's illegal for that call smile.gif

Ya to keep my program from crashing, I decided if the textfield is 0 the backspace button will be grayed out until something has been typed in, and then it will be renabled.

edit; well thats fixed, but I felt like I did it inefficiently.

I put the if statements under

textBox1_TextChanged()
{

}

and I also put the if statement under form1_load

I tried to call my method under form1_load that way I didn't have to put that 2nd if statement, but I can't seem to get it to work? Any help?
Edited by andyroo89 - 1/29/13 at 9:13am
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #384 of 1143
You could do
Code:
textBox1.Text = textBox1.Text.Remove((textBox1.Text.Length <= 1 ? 0 : textBox1.Text.Length -1), 0);

I love ternary statements biggrin.gif
Edited by 3930K - 1/29/13 at 11:41am
post #385 of 1143
textBox1.Length would not work by itself, I had to use textBox1.Text.Length and even then it still caused my program to crash.
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #386 of 1143
Quote:
Originally Posted by andyroo89 View Post

textBox1.Length would not work by itself, I had to use textBox1.Text.Length and even then it still caused my program to crash.
Whoops :/

But did it crash with that? Odd.

EDIT: Fixed some of the code, the startIndex was off.
post #387 of 1143
Quote:
Originally Posted by 3930K View Post

Whoops :/

But did it crash with that? Odd.

EDIT: Fixed some of the code, the startIndex was off.

Still didn't work. I mean it works just fine if I use my if statement, and I kind of like using the if statement to disable the button when the textfield is empty. I wouldn't worry about it. I appreciate the help.
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
Collecting Dust
(13 items)
 
Server
(9 items)
 
 
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 none OCZ 2x 2gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
none none loonix ssh is my monitor 
KeyboardPowerCaseMouse
none Corsair 650 watts old pc case Logitech mx518 
Mouse Pad
none! 
CPUMotherboardGraphicsRAM
AMD Athlon 64 X2 Dual Core Processor 6000+ GX611AA-ABA m8300f onboard 1x 2GB OCZ RAM DDR 
Hard DriveOSMonitorPower
320gb + 1TB HDD xubuntu 14.04 SSH 350 watt 
Case
crappy HP case 
  hide details  
Reply
post #388 of 1143
Hey guys. I'm trying to code a Newton-Raphson iteration for Numerical Methods. So far so good, except for an issue.

This is my algorithm in Python
Code:
#!/usr/bin/env python
#coding=utf-8

e = 2.71828182845904523536028747135266249775724709369995
ans = 0

for i in range (0, 4):
    ans = ans - (((e**(-ans)) - ans) / ((-e**(-ans)) - 1));
        
print ans

raw_input()

The output should be 0.56714329041

Now, this is my code in C
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    double ans = 0;
    char ansc[25];
    int i;

    for (i=0; i<5; i++)
    {
        ans = ans - ( (pow(M_E,(-ans)) - ans) / (-pow((M_E),(-ans)) - 1) );
    }

    sprintf(ansc, "%lf", ans);

    printf("%s \n", ansc);

    getchar();

    return 0;
}

It "works", but to a certain extent. I need it to have a higher precision of at least 10 decimals.

How can I achieve this? I though using double would work, but so far, no luck.

EDIT: I changed the code to the following
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    double ans = 0;

    int i;

    for (i=0; i<5; i++)
    {
        ans = ans - ( (pow(M_E,(-ans)) - ans) / (-pow((M_E),(-ans)) - 1) );
    }

    printf("%.12lf\n", ans);

    getchar();

    return 0;
}

It works now as intended biggrin.gif
Edited by Icekilla - 1/31/13 at 9:11pm
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
post #389 of 1143
This is clever as hell. Has anybody tried it yet?
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
post #390 of 1143
Delete.
Edited by 3930K - 2/2/13 at 9:01am
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)