Author |
Message |
diqua
|
Posted: 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
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
GlobeTrotter
|
Posted: Mon Apr 04, 2005 8:52 pm Post subject: (No subject) |
|
|
Declare it in the general declarations rather than in a Sub.
|
|
|
|
|
|
diqua
|
Posted: Tue Apr 05, 2005 7:10 am Post subject: (No 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?
|
|
|
|
|
|
Tony
|
Posted: Tue Apr 05, 2005 9:24 am Post subject: (No 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
|
|
|
|
|
|
diqua
|
Posted: Tue Apr 05, 2005 1:23 pm Post subject: here is my code so far |
|
|
my code
Description: |
|
Download |
Filename: |
frmcalc.frm |
Filesize: |
5.85 KB |
Downloaded: |
205 Time(s) |
|
|
|
|
|
|
Tony
|
Posted: Tue Apr 05, 2005 1:34 pm Post subject: (No subject) |
|
|
version 5.0? as in VB5?
What is this archaic language you're using.. VB6 has been discontinued.
|
|
|
|
|
|
diqua
|
Posted: Tue Apr 05, 2005 5:32 pm Post subject: (No 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
|
|
|
|
|
|
Brightguy
|
Posted: 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 |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
diqua
|
Posted: Thu Apr 07, 2005 1:39 pm Post subject: (No subject) |
|
|
i got it to work!!
used exacly as u said using a controll array 4 the numbbers and the operators
[/quote]
Description: |
|
Download |
Filename: |
calculator.zip |
Filesize: |
3.87 KB |
Downloaded: |
148 Time(s) |
|
|
|
|
|
|
|