
-----------------------------------
diqua
Mon Apr 04, 2005 7:12 pm

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

-----------------------------------
GlobeTrotter
Mon Apr 04, 2005 8:52 pm


-----------------------------------
Declare it in the general declarations rather than in a Sub.

-----------------------------------
diqua
Tue Apr 05, 2005 7:10 am


-----------------------------------
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?

-----------------------------------
Tony
Tue Apr 05, 2005 9:24 am


-----------------------------------
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

-----------------------------------
diqua
Tue Apr 05, 2005 1:23 pm

here is my code so far
-----------------------------------
my code

-----------------------------------
Tony
Tue Apr 05, 2005 1:34 pm


-----------------------------------
version 5.0? as in VB5? :?
What is this archaic language you're using.. VB6 has been discontinued.

-----------------------------------
diqua
Tue Apr 05, 2005 5:32 pm


-----------------------------------
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

-----------------------------------
Brightguy
Wed Apr 06, 2005 8:47 pm

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: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

-----------------------------------
diqua
Thu Apr 07, 2005 1:39 pm


-----------------------------------
i got it to work!!
used exacly as u said using a controll array 4 the numbbers and the operators
[/quote]
