?
Solved

Subroutines and Functions - New VB User

Posted on 2003-03-12
2
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes
Suggested Courses

765 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