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).
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
Re: question on flow of things
Quote:
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.
Quote:
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.
Quote:
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?
Re: question on flow of things
Quote:
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().
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
Re: question on flow of things
Quote:
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.)
Quote:
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.
Quote:
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.)
Re: question on flow of things
Al42 thanks for your replys.
Quote:
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!