?
Solved

Subroutines and Functions - New VB User

Posted on 2003-03-12
2
Medium Priority
?
252 Views
Last Modified: 2010-04-17
I need to write a subroutine and a function that performs the same task.  The task is to input 2 #'s into textboxes and add them together & display in pic box with only one display routine.  Also nee a variable to control which pic box #'s are displayed in.

Can anyone help?

Thanks,

Yaya
0
Comment
Question by:Yaya
2 Comments
 
LVL 5

Expert Comment

by:yronnen
ID: 8125793
public sub AddNums (num1 as integer,num2 aqs integer,objPic as picturebox)
'Do your stuff

end function

You can then send the name of the picturebox you want to update in the function call.

BTW, this apply to any control in VB.
0
 

Accepted Solution

by:
errorx666 earned 220 total points
ID: 8126493
'Display routine
Public Function Display(ByVal Number As Integer, ByRef Picture As PictureBox) As Boolean

'Dimension variable
Dim S As String

'Convert argument to string and store in S
Let S = CStr(Number)
'Display the text
'[not sure how you want to display this - draw S to picturebox?]
'Return success
Let Display = True

End Sub

'Subroutine
Public Sub MySubroutine(ByRef Text1 As Textbox, ByRef Text2 As Textbox, ByRef Picture as PictureBox)

'Dimension variables
Dim X As Integer
Dim Y As Integer
Dim Result As Integer

'Input data from textboxes
Let X = Val(Text1.Text)
Let Y = Val(Text2.Text)

'Calculate result
Let Result = X + Y

'Call display routine
Call Display(Result, Picture)

End Sub

'Function
Public Function MyFunction(ByRef Text1 As Textbox, ByRef Text2 As Textbox, ByRef Picture as PictureBox) As Boolean

'Dimension variables
Dim X As Integer
Dim Y As Integer
Dim Result As Integer

'Input data from textboxes
Let X = Val(Text1.Text)
Let Y = Val(Text2.Text)

'Calculate result
Let Result = X + Y

'Return result of display routine
Let MyFunction = Display(Result, Picture)

End Function
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Screencast - Getting to Know the Pipeline

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question