Computer Science Canada

variables into different private statements

Author:  diqua [ Mon Apr 04, 2005 7:12 pm ]
Post subject:  variables into different private statements

hi
im trying to write one of my own first calculator programs just to get the hang of vb
i would like to know how to make a variable available to all sub functions
if u need any more info please feel free to ask

Diqua

Author:  GlobeTrotter [ Mon Apr 04, 2005 8:52 pm ]
Post subject: 

Declare it in the general declarations rather than in a Sub.

Author:  diqua [ Tue Apr 05, 2005 7:10 am ]
Post subject: 

the thing is im trying to get it to work with only one textbox (kinda like the windows calculator) so i cant really declare it in the general declerations
is there an expression that i can use that will move the variable from one sub to another?

Author:  Tony [ Tue Apr 05, 2005 9:24 am ]
Post subject: 

diqua wrote:
i cant really declare it in the general declerations

what's stopping you?

otherwise (though I don't rememeber) you could make a variable to be public and do something like form1.textbox1.variableName = whatever

Author:  diqua [ Tue Apr 05, 2005 1:23 pm ]
Post subject:  here is my code so far

my code

Author:  Tony [ Tue Apr 05, 2005 1:34 pm ]
Post subject: 

version 5.0? as in VB5? Confused
What is this archaic language you're using.. VB6 has been discontinued.

Author:  diqua [ Tue Apr 05, 2005 5:32 pm ]
Post subject: 

i kinda have to have vb6 for school reasons but i think i could do it though a controll array

does that make sence?

if u can, could i have an example

thx a lot

Author:  Brightguy [ Wed Apr 06, 2005 8:47 pm ]
Post subject:  Re: variables into different private statements

Yeah, you'll want to use a control array for the numeral buttons, and for the operations as well if you're going to include ( + - * / ).

Something like this:
VisualBASIC:
Private lngDisplay As Long
Private bytOper As Byte

Private Sub cmdNum_Click(Index As Integer)
    lngDisplay = txtAns.Text & Index
    txtAns.Text = lngDisplay
End Sub

Private Sub cmdOper_Click(Index As Integer)
    bytOper = Index
    lblNum.Caption = txtAns.Text
    lblOper.Caption = cmdOper(Index).Caption
    lngDisplay = 0
    txtAns.Text = lngDisplay
End Sub

Author:  diqua [ Thu Apr 07, 2005 1:39 pm ]
Post subject: 

i got it to work!!
used exacly as u said using a controll array 4 the numbbers and the operators
[/quote]


: