Function return value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #1

    Function return value

    Hi jus messing round with some simple encryption here...

    main problem is my return value does not get returned to the main process...

    --------------------------------------------------------------------------
    [CODE=vb] Public Function SimpleCrypt( _
    ByVal myVal As String) As String

    Dim strTempChar As String, i As Integer

    Dim tempval As String
    Dim a As Integer
    a = len(myVal)

    For i = 1 To Len(myVal)

    strTempChar = asc(mid(myVal, i, 1))
    strTempChar = CInt(strTempCha r) '---
    strTempChar = strTempChar * 5
    strTempChar = strTempChar / 10
    strTempChar = strTempChar - 50
    strTempChar = strTempChar + 25

    tempval = CStr(tempval) + strTempChar '---

    Next i
    myVal = tempval
    Return myVal
    End Function[/CODE]----------------------------------------------------------------------

    My button-------------------------------------
    Dim MyVal As String
    MyVal = TextBox1.Text
    SimpleCrypt(MyV al)

    TextBox2.Text = MyVal
    -------------------------------------------

    i put "a" in the textbox1. it goes thru my function and myval get the value 63.xxxxxxx

    but it neva returns it. am i missing something?
    textbox2 always gets the same value as textbox1 before the function was called.

    Cheers
    Last edited by debasisdas; Oct 4 '07, 10:43 AM. Reason: Formatted using code tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Like other programming languages, in VB6, "Return" keyword does not mean the same, Function name itself should be populated with the return result:
    Remove the return at the end of function
    Check this :

    [code=vb]
    Public Function SimpleCrypt( _
    ByVal myVal As String) As String

    Dim strTempChar As String, i As Integer

    Dim tempval As String
    Dim a As Integer
    a = len(myVal)

    For i = 1 To Len(myVal)

    strTempChar = asc(mid(myVal, i, 1))
    strTempChar = CInt(strTempCha r) '---
    strTempChar = strTempChar * 5
    strTempChar = strTempChar / 10
    strTempChar = strTempChar - 50
    strTempChar = strTempChar + 25

    tempval = CStr(tempval) + strTempChar '---

    Next i
    myVal = tempval
    SimpleCrypt = myVal

    End Function
    [/code]

    Regards
    Veena

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Thanks i didnt realise that was the case.

      fixed it sorry...

      button needed

      TextBox2.Text = SimpleCrypt(MyV al)

      instead of
      SimpleCrypt(myV al)
      TextBox2.Text = MyVal

      Comment

      Working...