CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: help

  1. #1
    Join Date
    May 2001
    Posts
    155

    help

    I have a module with this code:

    Sub insertfunc()
    Dim func as string
    Dim ch
    Dim func2 as string
    ch = Chr(10)
    func = InputBox("Enter function name")
    func2 = "function " & func & "()" & ch & "{" & ch & "" & ch & "}"
    End Sub



    I have that in a module because i'm going to use it on 7/8 different forms. In the form code, i want the user to be able to click a button and then the text of the variable func2 to be put in a richtextbox on that form. In the function itself i've tried richtextbox1.text = func2 because all the forms' richtextboxes are going to be called that. But when i do that it says object required. Someone help, please!!!

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: help

    It sounds like you need to specify which form you want to change the text on. If you are referencing richtextbox1 from a module outside of the form that contains an object called richtextbox1, you'll get that kind of error.

    If you use the syntax Form1!RichTextBox1.Text your function will know to use the control located on Form1.


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: help

    Make InsertFunc a function

    public Function InsertFunc() as string
    ...
    ...

    InsertFunc = func2
    End Function




    Then in the form code, assign the string that this function returns.


  4. #4
    Join Date
    May 2001
    Posts
    155

    Re: help

    Ok, i got calling the function now. I got my function like this:

    Function insertfunc()
    Dim func as string
    Dim ch
    Dim func2 as string
    ch = Chr(10)
    func = InputBox("Enter function name")
    func2 = "function " & func & "()" & ch & "{" & ch & "" & ch & "}"
    insertfunc = func2
    Exit Function
    End Function



    And the form code like this:

    private Sub fun_Click()
    insertfunc
    RichTextBox1.Text = Chr(10) & insertfunc
    Exit Sub
    End Sub



    but now when i run the program, it displays the inputbox twice, instead of once. How do i fix that?


    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  5. #5
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: help


    private Sub fun_Click()
    RichTextBox1.Text =RichTextBox1.Text & Chr(10) & insertfunc
    End Sub





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

Featured