User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS Access and FileMaker Pro section within the Web Development category of DaniWeb, a massive community of 426,901 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,347 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS Access and FileMaker Pro advertiser: Programming Forums
Views: 1368 | Replies: 7 | Solved
Reply
Join Date: Mar 2008
Posts: 34
Reputation: clueless101 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
clueless101 clueless101 is offline Offline
Light Poster

Pass arguments to a Function

  #1  
Mar 31st, 2008
I am to create a form with 2 text boxes to receive numbers as input and 1 command button that displays a message box containing the larger of the two numbers. To do so, I need to write code in the Click event of the command to call a user-defined function named FindLargestNumber. Pass it 2 arguments(textboxvalues) and display the result in a message box. Write code in the FindLargestNumber function to determine the larger number and return result to the calling procedure(command button Click event).

Can anyone help me out on this? Here's my code thus far, which isn't working:
Option Compare Database

Private Sub cmdCompare_Click()

If Number1 > Number2 Then
MsgBox "txt.Number1.value"
ElseIf Number2 > Number1 Then
MsgBox "txt.Number2.value"
End If

End Sub

Public Function FindLargestNumber(Number1 As Double, Number2 As Double)


End Function
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 29
Reputation: boblarson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
boblarson's Avatar
boblarson boblarson is offline Offline
Light Poster

Re: Pass arguments to a Function

  #2  
Mar 31st, 2008
This is roughly what you want. Don't know what you want for the result so I returned the value that was the largest.

Option Compare Database

Private Sub cmdCompare_Click()
   MsgBox "The largest number is " & FindLargestNumber(Me.Text1,Me.Text2)
End Sub

Public Function FindLargestNumber(dblNumber1 As Double, dblNumber2 As Double) As Double
  If dblNumber1 > dblNumber2 Then
     FindLargestNumber = dblNumber1
  End If

  If dblNumber2 > dblNumber1 Then
     FindLargestNumber = dblNumber2
  End If

End Function
Bob Larson
____________________________________
Access MVP
For Quick Tutorials and Samples for Microsoft Access: BTAB Development
Reply With Quote  
Join Date: Mar 2008
Posts: 34
Reputation: clueless101 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
clueless101 clueless101 is offline Offline
Light Poster

Re: Pass arguments to a Function

  #3  
Apr 1st, 2008
Thank you so much. I guess I had it somewhat backwards and mixed up.

I was just wondering about 1 more thing. What if the numbers were equal?

How would you handle that?

thanks, again.
Reply With Quote  
Join Date: Jan 2008
Posts: 29
Reputation: boblarson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
boblarson's Avatar
boblarson boblarson is offline Offline
Light Poster

Re: Pass arguments to a Function

  #4  
Apr 1st, 2008
I guess you'd have to add an:
If dblNumber 1 = dblNumber2 Then
  FindLargestNumber = dblNumber1
End If
or you can assign it whatever value you want.
Bob Larson
____________________________________
Access MVP
For Quick Tutorials and Samples for Microsoft Access: BTAB Development
Reply With Quote  
Join Date: Apr 2008
Posts: 38
Reputation: Yogesh Sharma is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Pass arguments to a Function

  #5  
Apr 7th, 2008
hey I know how to Create a form Using Wizard. Can somebody plz tell me how to create from on which u place controls like Textbox,CommandButton.
Plz reply.
Reply With Quote  
Join Date: Apr 2008
Posts: 38
Reputation: Yogesh Sharma is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Pass arguments to a Function

  #6  
Apr 7th, 2008
U all r talking in this thread abt the form In MS Acess or anyelse.
Reply With Quote  
Join Date: Jan 2008
Posts: 29
Reputation: boblarson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
boblarson's Avatar
boblarson boblarson is offline Offline
Light Poster

Re: Pass arguments to a Function

  #7  
Apr 7th, 2008
Originally Posted by Yogesh Sharma View Post
U all r talking in this thread abt the form In MS Acess or anyelse.

We weren't talking about a form. We were talking about a function. You should probably post a new thread for your questions.
Bob Larson
____________________________________
Access MVP
For Quick Tutorials and Samples for Microsoft Access: BTAB Development
Reply With Quote  
Join Date: Apr 2008
Posts: 38
Reputation: Yogesh Sharma is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Pass arguments to a Function

  #8  
Apr 8th, 2008
hi clue,plz tell me I also want to create a form that add two nos, but I do not know form where to place Textboxes & command button on the form.plz tell me I will be very thankfulto you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS Access and FileMaker Pro Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS Access and FileMaker Pro Forum

All times are GMT -4. The time now is 11:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC