Results 1 to 11 of 11

Thread: passing arguments

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7
    hi,
    can someone tell me how to do passing arguments?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Do you mean how to pass arguments to subs and functions?

    Subname Argument1, Argument2

    variable = Function(Argumen1, Argument2)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7

    passing arguments

    should I be using passing arguments to use the output from one sub function in another sub function?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    depends on what you want to do, it's not impossible:

    Sub Function(Argument)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7

    passing arguments

    ok..this is what i want to do..
    I have a
    Private Function DisplayResult ()
    To output a caption to a label
    This function requires the array strname and 2 integer values from
    Private Function FindType

    how do i get the values from FindType into DisplayResult?

    thanks for your help...

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hmm, you should have posted the arguments too, well i'm going to tell you what to do.
    You pass both the strname string array and the 2 integers byref (by reference, you can omit this keyword since it's default) to the FindType function. They should not be expressions or results from other functions, they have to be variables. Pass the same variables to DisplayResult now, they should contain the values you need.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7

    passing arguments

    does this look right? sorry for making you read the code, but it might make it easier..i'm trying to pass strname, intindex and intindex2 into the diplayresult function..

    Private Function FindType(strname as string, intindex as integer, intindex2 as integer)

    'declare variables
    Dim StrType As String 'search criteria for type
    Dim IntIndex As Integer 'index for filling the array
    Dim IntIndex2 As Integer 'total no. of matching animals found
    Dim strname(0 To 4) As String 'define array to hold matches

    'Assign values to variables
    IntIndex = 0
    IntIndex2 = 0
    StrType = TxtType.Text


    'condition if only type criteria have been entered
    DatName.Recordset.MoveFirst
    Do
    If StrType = DatName.Recordset!Type Then 'if criteria matches _
    'record type
    If IntIndex = IntMaxName Then 'do this if all array spaces have been filled _
    to get total no. of animals found
    IntIndex2 = IntIndex2 + 1
    DatName.Recordset.MoveNext
    Else
    strname(IntIndex) = DatName.Recordset!Name
    IntIndex = IntIndex + 1
    IntIndex2 = IntIndex2 + 1
    DatName.Recordset.MoveNext
    End If
    Else
    DatName.Recordset.MoveNext 'if match was not made, _
    'program moves to next record
    End If
    Loop Until DatName.Recordset.EOF ' continue until end _
    ' of database
    End If
    End Function



    Private Sub DisplayResult(strname as string, intindex as integer, intindex2 as integer)

    If IntIndex = 0 Then
    LblSearchResult.Caption = "No Animals Match The Criteria"
    ElseIf IntIndex = 1 Then
    LblSearchResult.Caption = "Found " & strname(0)
    ElseIf IntIndex = 2 Then
    LblSearchResult.Caption = "Found " & IntIndex & " animals with names " _
    & strname(0) & " ," & strname(1)
    ElseIf IntIndex = 3 Then
    LblSearchResult.Caption = "Found " & IntIndex & " animals with names " _
    & strname(0) & " ," & strname(1) & " ," & strname(2)
    ElseIf IntIndex = 4 Then
    LblSearchResult.Caption = "Found " & IntIndex & " animals with names " _
    & strname(0) & ", " & strname(1) & ", " & strname(2) & ", " & strname(3)
    ElseIf IntIndex = 5 Then
    LblSearchResult.Caption = "Found " & IntIndex2 & " animals with names " _
    & strname(0) & ", " & strname(1) & ", " & strname(2) & ", " & strname(3) _
    & strname(4) & ", ..."
    End If

    End Sub

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Don't declare the variables you passed, also strname was the array right?
    Change this
    Code:
    Private Function FindType(strname as string, intindex as integer, intindex2 as integer) 
    
    'declare variables 
    Dim StrType As String 'search criteria for type 
    Dim IntIndex As Integer 'index for filling the array 
    Dim IntIndex2 As Integer 'total no. of matching animals found 
    Dim strname(0 To 4) As String 'define array to hold matches
    into this:
    Code:
    Private Function FindType(strname() as string, intindex as integer, intindex2 as integer) 
    Dim StrType As String 'search criteria for type
    Now you call Findtype and DisplayResult, with variables:
    Code:
    Dim IntIndex As Integer 'index for filling the array 
    Dim IntIndex2 As Integer 'total no. of matching animals found 
    Dim strname(0 To 4) As String 'define array to hold matches 
    FindType strname(), intindex, intindex2
    
    DisplayResult(strname(0), intindex, intindex2)
    Now i'm not sure what you want to do with the rest of the strname array? Well you could pass the whole array too, but then you would have to do as like in FindType.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7

    passing arguments

    wow..i'll give it a shot..
    i'm only meant to display a maximum of 5 names, so i only declared the 5 spaces in the array..
    and yes, strname was the name of the array.

    so do i declare the variables in the cmdclick procedure, and then call up findtype then displayresult?

    sorry for sounding like a dweeb...my uni lecturer didn't explain things very well..

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    exactly
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    7
    thanks so much for your help kedaman, hopefully it will work, otherwise you'll see me on the board again!
    :-)
    B

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width