Results 1 to 3 of 3

Thread: How to use functions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Location
    Norway
    Posts
    71

    How to use functions

    Hi,

    I am very very new to VB and have not yet learned to use functions and would very much like to learn this..

    Lets say for example I have a function like this:

    VB Code:
    1. Function HexToString(ByVal sText As String) As String
    2.     Dim saHex() As String, i As Long
    3.     saHex = Split(sText)
    4.     For i = 0 To UBound(saHex)
    5.         HexToString = HexToString & ChrW("&H" & saHex(i))
    6.     Next
    7. End Function

    Which are supposed to convert Hex to String, do I just put this randomly in the middle of my code and it will convert all Hex to Strings or..?

    For example if I have a textfield where I ask user to enter Hex and another box which shows the converted string, would I then do like Text1.Text = function something..?

    Please tell me a little more about functions, thanks alot to all possible repliers! :]

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to use functions

    You have this function:

    Function HexToString(ByVal sText As String) As String
    Dim saHex() As String, i As Long
    saHex = Split(sText)
    For i = 0 To UBound(saHex)
    HexToString = HexToString & ChrW("&H" & saHex(i))
    Next
    End Function
    You pass a hex string to it, say Hex.text (which is a textbox)
    You return it to text1.text (the answer textbox)

    You pass Hex.text ( or "AB0D0") like this:

    VB Code:
    1. text1.text = HexToString(Hex.text)
    or:

    VB Code:
    1. text1.text = HexToString("AB0D0")

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How to use functions

    Posted this in another thread.
    Have a look at
    http://www.vbforums.com/showthread.php?t=341409
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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