PDA

View Full Version : problem with setfocus after point input in acad



Basp70
08-22-2008, 05:02 AM
Hello, i have a problem with the part of the code i have paste below

If InStr(regel1, "Point:") Then
'UserForm1.hide
'returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
'UserForm1.Show
textbox2.SetFocus
teller = TextBox2.LineCount
It works so okay.

But when i remove the ' in front off the 3 other lines it will not function anymore. It will then not set the variabele teller and stop there, it gives a error when i quit the application. The error is that the focus can not be set on textbox2.
textbox 2 is a part of userform1

Ow and this is part of more code what should happens as a button in userfomr1 is clicked. (so maybe it goes wrong because of this)

CreganTur
08-22-2008, 05:59 AM
Welcome, always good to see new users at the forum!

Are you sure that textbox2 is the name of the object you want to reference?

What is the exact error message that you're getting?

Basp70
08-22-2008, 06:32 AM
Thanks for the warm welcome and the very fast reply. :bow:

The exact error is runtime error '2110'
can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.

When i remove the 3 ' in the lines then first the form is hided, then the program asks me to enter a point in the screen, then the form is popped up again. After that it doesnt do anything anymore. So then i use the X or the cancel button and after that the error is coming up.

If i don't remove the ' the program just sets the variable teller and goes on. (that is why i think that i have to focus on the textbox2)

here is the complete subfunction
Private Sub CommandButton1_Click()
Set algemenedata = New DataObject
algemenedata.GetFromClipboard
If algemenedata.GetFormat(1) = True Then
TextBox2.Text = algemenedata.GetText(1)
Else
TextBox2.Text = "helemaal foute data, probeer het opnieuw"
End If

TextBox2.Text = algemenedata.GetText(1)
regel1 = GetLine(TextBox2.Text, 1)
'TextBox2.Text = regel1
If InStr(regel1, "Point:") Then
'UserForm1.hide
'returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
'UserForm1.Show
TextBox2.SetFocus
teller = TextBox2.LineCount
For regelnummer = 1 To teller
regel1 = GetLine(TextBox2.Text, regelnummer)
regel2 = Right(regel1, (Len(regel1) - InStr(regel1, "<")))
xstr = Left(regel2, (InStr(regel2, ",") - 1))
xr = CDbl(xstr)
regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
ystr = Left(regel2, (InStr(regel2, ",") - 1))
yr = CDbl(ystr)
regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
zstr = Left(regel2, (InStr(regel2, ">") - 1))
zr = CDbl(zstr)
MsgBox (zstr)
Next regelnummer
Else
MsgBox ("Foute data, veld leeggemaakt probeer het opnieuw")
TextBox2.Text = ""
End If
TextBox2.SetFocus

End Sub

Instead of msgbox (zstr) there will be circles drawn on the coordinates i get out of these text lines which were pasted into the textbox. But first i have to get the zeropoint from which the circle have to be drawn. And that is not functioning at the moment.

Tommy
08-22-2008, 08:15 AM
Hi Basp70, :hi:

I know this is a little lame but move the setfocus before the hide. Then do the hide and after that the show, this way the control already has the focus but the user can't do anything with it until the userform reapears. :devil2:

Private Sub CommandButton1_Click()
Set algemenedata = New DataObject
algemenedata.GetFromClipboard
If algemenedata.GetFormat(1) = True Then
TextBox2.Text = algemenedata.GetText(1)
Else
TextBox2.Text = "helemaal foute data, probeer het opnieuw"
End If

TextBox2.Text = algemenedata.GetText(1)
regel1 = GetLine(TextBox2.Text, 1)
'TextBox2.Text = regel1
If InStr(regel1, "Point:") Then
'moved to here set the focus before the hide
TextBox2.SetFocus
UserForm1.hide
returnPnt = ThisDrawing.Utility.GetPoint(, "click het nulpunt van het model aan ")
UserForm1.Show
teller = TextBox2.LineCount
For regelnummer = 1 To teller
regel1 = GetLine(TextBox2.Text, regelnummer)
regel2 = Right(regel1, (Len(regel1) - InStr(regel1, "<")))
xstr = Left(regel2, (InStr(regel2, ",") - 1))
xr = CDbl(xstr)
regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
ystr = Left(regel2, (InStr(regel2, ",") - 1))
yr = CDbl(ystr)
regel2 = Right(regel2, (Len(regel2) - InStr(regel2, ",")))
zstr = Left(regel2, (InStr(regel2, ">") - 1))
zr = CDbl(zstr)
MsgBox (zstr)
Next regelnummer
Else
MsgBox ("Foute data, veld leeggemaakt probeer het opnieuw")
TextBox2.Text = ""
End If
'removed this one
'TextBox2.SetFocus

End Sub

Basp70
08-25-2008, 01:55 AM
That also didn't do the trick. The workaround what i've used is to make an extra button (GET ZERO POINT)


Private Sub CommandButton4_Click()
Me.hide
returnPnt = ThisDrawing.Utility.GetPoint(, vbCr & "Line Start Point: ")
CommandButton1.Enabled = True 'button1 (de onderste) activeren
CommandButton4.Enabled = False 'button4 (de middelste) deactiveren
Me.Show
End Sub


And this code is working well. But the big question for me still is why didn't it work in the other way. (Could it be that it has to do with the nesting of this function? ) :dunno

rocheey
08-26-2008, 10:12 AM
try setting the form to non modal (in Properties, set "ShowModal" to false)

Basp70
08-27-2008, 07:35 AM
Thanks for the last tip that was it.:thumb