| | #1 |
| Senior Member Join Date: Jan 2010 Location: Missoura
Posts: 322
| 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:
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. |
| | |
| | #2 |
| Administrator Join Date: Jun 2009 Location: USA
Posts: 6,768
| 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. |
| | |
| | #3 |
| Super Moderator | 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
}
To call this method, you would type... (2) Code: int myInt = 5;
myMethod(myInt);
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
}
![]() If I need to elaborate more, let me know.
__________________ Last edited by Nghtmr9999; 02-22-2011 at 02:19 PM. |
| | |
| | #4 |
| Senior Member Join Date: Jan 2010 Location: Missoura
Posts: 322
| 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 |
| | |
| | #6 |
| Senior Member Join Date: Jan 2010 Location: Missoura
Posts: 322
| 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 |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick programming question | Nghtmr9999 | Off Topic | 3 | 06-04-2010 06:05 AM |