Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 variables into different private statements
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
diqua




PostPosted: 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
Sponsor
sponsor
GlobeTrotter




PostPosted: Mon Apr 04, 2005 8:52 pm   Post subject: (No subject)

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




PostPosted: 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




PostPosted: 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




PostPosted: Tue Apr 05, 2005 1:23 pm   Post subject: here is my code so far

my code


frmcalc.frm
 Description:

Download
 Filename:  frmcalc.frm
 Filesize:  5.85 KB
 Downloaded:  197 Time(s)

Tony




PostPosted: Tue Apr 05, 2005 1:34 pm   Post subject: (No subject)

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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
diqua




PostPosted: 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]



calculator.zip
 Description:

Download
 Filename:  calculator.zip
 Filesize:  3.87 KB
 Downloaded:  141 Time(s)

Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: