Click to See Complete Forum and Search --> : help


ant
July 2nd, 2001, 10:21 AM
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: christopherfolger@hotmail.com
for the address

Ghost308
July 2nd, 2001, 10:26 AM
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.

shree
July 2nd, 2001, 11:26 AM
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.

ant
July 2nd, 2001, 02:56 PM
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: christopherfolger@hotmail.com
for the address

shree
July 3rd, 2001, 08:16 AM
private Sub fun_Click()
RichTextBox1.Text =RichTextBox1.Text & Chr(10) & insertfunc
End Sub