|
-
Sep 21st, 2007, 04:37 PM
#1
Thread Starter
Addicted Member
question on flow of things
I am starting to connect my program to the visual basic gui and I have a couple of questions.
1) do you have to have a command that "runs" the actual code of the program?
2) if you call a variable out of the main program will that make the program run to find the correct value?
3) how do you tie all the objects together so that it happens all the same time. EX: i hit the run button (after ive put in my inputs which ill get to later) and then a sort of console window displays and write statements that in the program but at the same time 5 or 6 variables are displayed in text boxes(the results of the program).
-
Sep 21st, 2007, 08:14 PM
#2
Re: question on flow of things
1) You don't have to have a command button to run all the code. In fact far from it. To run code you merely have to trigger an event and put the code you want under that event.
2) What do you mean out of the main program? Does your program consist of several exes or do you mean forms?
3) To tie all the objects together there are endless possibilities. All you have to do is put everything you want to do in a single sub.
Ex:
Code:
Private Sub Form_Load()
text1=me.caption
text2=me.left
text3=me.top
text4=text1 & "/" & text2 & "/" & text3
end sub
If a post has been helpful please rate it. 
If your question has been answered, pull down the tread tools and mark it as resolved.
-
Sep 24th, 2007, 11:03 AM
#3
Re: question on flow of things
 Originally Posted by Armageddon85
1) do you have to have a command that "runs" the actual code of the program?
Whatever code you need to run when the program starts would be put in the Form_Load of your startup form.
 Originally Posted by Armageddon85
2) if you call a variable out of the main program will that make the program run to find the correct value?
Same question as Mxjerrett.
 Originally Posted by Armageddon85
3) how do you tie all the objects together so that it happens all the same time. EX: i hit the run button (after ive put in my inputs which ill get to later) and then a sort of console window displays and write statements that in the program but at the same time 5 or 6variables are displayed in text boxes(the results of the program).
Displays and writes statements in what program?
-
Sep 24th, 2007, 01:25 PM
#4
Re: question on flow of things
 Originally Posted by Hack
Whatever code you need to run when the program starts would be put in the Form_Load of your startup form.
Except for things that aren't there until Form_Load finishes (like setting some controls up), which can be done in Form_Activate.
I think the basic confusion here stems from the difference between linear programs (like DOS programs) and event-driven programs (like Windows GUIs). In a VB program, the code that's running once the program loads is a dispatch loop - the program sits and waits for events (like keypresses or button clicks) to occur. Your code handles these events in subs that execute when the events occur, like Command1_Click().
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Sep 25th, 2007, 03:21 PM
#5
Thread Starter
Addicted Member
Re: question on flow of things
Awesome, thanks for the replys. Ok got the answer for one; that makes sense.
For two; I think i might of worded it wrong but on top of that I think the answer two question one answers question two. But just to make sure; if you call variable A from "program hpsim3" (only one program, sorry) in an event will the variable be set to the initial value or will the whole program execute to find the end value ( this is assuming I have not put a run program from an earlier statement).
For three; I understand the answer but that leads to another question. Can you set the outputs of the program (say var A, B, C) to text1,2,3 in a form and get the right numbers?
And one more question. How do you execute a program in a form? Is it like this:
Code:
Private Sub Form_Load()
call hpsim3
text1=hpsim3.A (is this right?)
text2=hpsim3.B
text3=hpsim3.C
text4=text1 & "/" & text2 & "/" & text3
end sub
-
Sep 26th, 2007, 11:49 AM
#6
Re: question on flow of things
 Originally Posted by Armageddon85
Awesome, thanks for the replys. Ok got the answer for one; that makes sense.
For two; I think i might of worded it wrong but on top of that I think the answer two question one answers question two. But just to make sure; if you call variable A from "program hpsim3" (only one program, sorry) in an event will the variable be set to the initial value or will the whole program execute to find the end value ( this is assuming I have not put a run program from an earlier statement).
You can't call a variable. If you reference (use) a variable it will have no value (a string with no characters in it for a string variable, 0 for a numeric variable, 12:00:00 AM for a date variable, etc.)
Can you set the outputs of the program (say var A, B, C) to text1,2,3 in a form and get the right numbers?
If the variables have "the right numbers" the text boxes will.
And one more question. How do you execute a program in a form? Is it like this:
Code:
Private Sub Form_Load()
call hpsim3
text1=hpsim3.A (is this right?)
text2=hpsim3.B
text3=hpsim3.C
text4=text1 & "/" & text2 & "/" & text3
end sub
Is hpsim3 a function? A sub? A variable? Whichever it is, the code isn't quite right.
Do you want the code to run as soon as the program loads? When someone clicks on a button? When something else happens? (Windows programs do things in response to events.)
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Sep 26th, 2007, 03:33 PM
#7
Thread Starter
Addicted Member
Re: question on flow of things
Al42 thanks for your replys.
You can't call a variable. If you reference (use) a variable it will have no value (a string with no characters in it for a string variable, 0 for a numeric variable, 12:00:00 AM for a date variable, etc.)
If we reference the variable from the program after calling it, (hpsim3 is a "program", not a function, sub, or variable. And "call hpsim3" is working; more on that in a second) in this form:
Code:
call hpsim3
text1=hpsim3.A
Will the var A still have no value? or will it have changed to match the value of the end value of var A?
Is that the "correct" way to reference a variable from a "program"?
Last thing, is call hpsim3 the right way to call a "program"?
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|