Multiboxing.com - Multiboxing in World of Warcraft and more!
          

Go Back   Multiboxing in World of Warcraft and Beyond! > All Gaming Forums > Off Topic

Reply
 
LinkBack Thread Tools Display Modes
Old 02-22-2011, 11:38 AM   #1
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 322
Default Programming help

I just need some clarification

1. Will a variable defined in a subprogram be usable with that same string/data in the main or another sub?

2. Do I write a bunch of subprograms to monitor each conceivable error, one sub to monitor the whole thing, or a separate program altogether?

I have been reading my Beginning Programming for Dummies book and I just got to the section about Arrays. The book teaches you the basics of LibertyBASIC, REALBasic, Revolution, and C++.

a list of what I know now:
  • PRINT
  • PROMPT
  • FOR-NEXT loops
  • WHILE-WEND loops
  • FUNCTIONS
  • Subprograms
  • ARRAY (kind of)
  • and how to comment

Ill add more if I think of any

EDIT- I lost the CD with all the compilers on it soooo I have no way of writing anything other than C++ right now.
__________________

MY LOCKS BEAT YOUR LOCKS

Last edited by supamario00; 02-22-2011 at 05:08 PM.
supamario00 is offline   Reply With Quote
Old 02-22-2011, 12:16 PM   #2
Tim
Administrator
 
Tim's Avatar
 
Join Date: Jun 2009
Location: USA
Posts: 6,768
Default Re: Programming help

For both questions, the answer is the same: It depends

When you develop something, you literally create life in the form of the program. How you create that is up to you. There are probably a million ways to output "Hello World" if not more.
Tim is offline   Reply With Quote
Old 02-22-2011, 02:16 PM   #3
Super Moderator
 
Nghtmr9999's Avatar
 
Join Date: Aug 2009
Location: Minnesota, US
Posts: 1,662
Blog Entries: 6
Default Re: Programming help

Hmm, we'll see if I'm interpreting this correctly, and I'll do the best I can to explain it in "beginner speak"

By 'subprogram' I assume you mean a subroutine/method/function. If that's the case, then no, you cannot access a variable in another method. It will be out 'scope'

The way around this would be to pass in the value where you need it.


Lets say this is the method you want to access the value of some variable i.

(1)
Code:
public int myMethod(int i)
{
    System.out.println(i); //prints out i
}
This method takes in an integer "i" and prints it out.

To call this method, you would type...

(2)
Code:
    int myInt = 5;
    myMethod(myInt);
By doing this, you pass in a value to a variable to use in that function.

Let me expand a bit by adding more to method (1)

Code:
public int myMethod(int i)
{
    System.out.println(i); //prints out i
    int add = i+i;
    int sub = i-i;
    int mult = i*i;

    System.out.println(add); //prints out i+i, or 5+5. 10
    System.out.println(sub); //prints out i-i, or 5-5. 0
    System.out.println(mult); //prints out i*i, or 5*5. 25
}
As for your second question, most (good) compilers will catch programming errors for you. I would highly recommend Visual Studio's line of programs. As for runtime errors... write working code in the first place


If I need to elaborate more, let me know.
__________________

Last edited by Nghtmr9999; 02-22-2011 at 02:19 PM.
Nghtmr9999 is offline   Reply With Quote
Old 02-22-2011, 05:07 PM   #4
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 322
Default Re: Programming help

Quote:
Originally Posted by Nghtmr9999 View Post
As for your second question, most (good) compilers will catch programming errors for you. I would highly recommend Visual Studio's line of programs. As for runtime errors... write working code in the first place
.
I meant that when I'm writing a program and its all running, the message to display if an error occurred, how do I monitor those possible errors across the whole program
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Old 02-22-2011, 05:32 PM   #5
Super Moderator
 
Nghtmr9999's Avatar
 
Join Date: Aug 2009
Location: Minnesota, US
Posts: 1,662
Blog Entries: 6
Default Re: Programming help

you would want to use try/catch statements

Code:
try
{
    //do code stuff here
}
catch (Exception e)
{
     //output error message here
}
__________________
Nghtmr9999 is offline   Reply With Quote
Old 02-22-2011, 08:55 PM   #6
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 322
Default Re: Programming help

Quote:
Originally Posted by Nghtmr9999 View Post
you would want to use try/catch statements

Code:
try
{
    //do code stuff here
}
catch (Exception e)
{
     //output error message here
}
hehe not that far along in the book yet :P ill probably be there in the next two hours or so.
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick programming question Nghtmr9999 Off Topic 3 06-04-2010 06:05 AM


SEO by vBSEO 3.3.2