Stumped again

Stumped again

Anonymous
Not applicable
556 Views
17 Replies
Message 1 of 18

Stumped again

Anonymous
Not applicable
So I'm writing this routine to draw a structural grid still, and I've got
everything working honky-dory so far (thanks to all of you) except for the
fact that it never gets to the second Do...Until loop below. I get the
dimensions from the lettered grids fine and it fills the array perfectly
but when I hit enter and the blnCheck variable clears the test it just
quits. It never even gets to setting "intGrid1 = 1", I've tried making
intGrid1 a double and I've tried making intIndex an independent variable in
each loop. I've posted the entire routine as it is right now because I
have no clue where the error might be (I don't get any messages). Of
course any and all help is greatly appreciated, I hope this isn't too much
code to post:

Option Explicit

Public Sub DrawGridSystem()

Dim varXDims() As Variant
Dim varYDims() As Variant
Dim dblOrigin(2) As Double
Dim dblDwgScale As Double
Dim dblCurDist As Double
Dim strDirection As String
Dim strLocation As String
Dim strGridA As String
Dim intGrid1 As Integer
Dim intIndex As Integer
Dim blnCheck As Boolean



With ThisDrawing.Utility
.InitializeUserInput 1, "Vert Horiz"
strDirection = .GetKeyword(vbCr & "Letters should be [Vert/Horiz]:
")
Select Case UCase(strDirection)
Case "VERT"
.InitializeUserInput 1, "Top Bottom"
strLocation = .GetKeyword(vbCr & "A is at the [Top/Bottom]:
")

Case "HORIZ"
.InitializeUserInput 1, "Left Right"
strLocation = .GetKeyword(vbCr & "A is at the [Left/Right]:
")

Case Else
MsgBox "Invalid Input"
End Select

strGridA = "A"
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " &
strGridA & " to grid " _
& Chr(Asc(strGridA) + 1) & " [Enter to end]: ")
ReDim Preserve varXDims(intIndex)
varXDims(intIndex) = .DistanceToReal(dblCurDist,
acArchitectural)
strGridA = Chr(Asc(strGridA) + 1)
blnCheck = IsEmpty(varXDims(intIndex))
intIndex = intIndex + 1
Loop Until blnCheck = True

intGrid1 = 1
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " &
intGrid1 & " to grid " _
& intGrid1 + 1 & " [Enter to end]: ")
ReDim Preserve varYDims(intIndex)
varYDims(intIndex) = .DistanceToReal(dblCurDist,
acArchitectural)
intGrid1 = intGrid1 + 1
blnCheck = IsEmpty(varYDims(intIndex))
intIndex = intIndex + 1
Loop Until blnCheck = True
End With
End Sub

--
matthew g.
0 Likes
557 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable
try setting a different test for
> blnCheck = IsEmpty(varXDims(intIndex))
It makes no sense to me but acad vba says an empty array is not empty!
(try creating an array with nothing in it and you'll see what I mean)
The IsEmpty test just sees if the variable has been assigned to an array,
not whether there is anything in the array,
I haven't had time to look at your code to figure what your test should be
but I remember having that problem in the past with the IsEmpty test.
I'm sure you can use the original size of the array and your index variable
to create a test that will get you out of the loop.
If no one has better help than that I'll try to look at it closer after
work, got to jam now!
good luck
Mark

"Matthew Gonzalez" wrote in message
0 Likes
Message 3 of 18

Anonymous
Not applicable
Some hints for locating errors or to see if a part of the code is being
skipped.

1) Run the macro step-by-step. Put your cursor in the Sub you want to run
and hit F8. Keep hitting F8 to step through line by line and see if loops
get executed or skipped.

1a) Set breakpoints right before a line of interest and run your Sub. When
VBA pauses, use F8 to step through the part your interested in. Might be
quicker than stepping through your whole subroutine.

2) Use Debug.Print in loops and If statements to see if they get executed
and to see what values your loop counter goes through.

3) I don't use it, there is a Watch window so you can see variable values
change as the program goes along

Hope this helps.


> I have no clue where the error might be (I don't get any messages).
0 Likes
Message 4 of 18

Anonymous
Not applicable
OK, I figured out where the problem is, in this area:

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " &
strGridA & " to grid " _
& Chr(Asc(strGridA) + 1) & " [Enter to
end]: ")
ReDim Preserve varXDims(intIndex)
varXDims(intIndex) = .DistanceToReal(dblCurDist,
acArchitectural)
......


When the user hits Enter to exit the loop, that empty entry then tries to
go through the .DistanceToReal conversion and it doesn't like trying to
convert nothing. Thanks again guys, I'm working up a workaround,
suggestions are always welcome.


--
matthew g.
0 Likes
Message 5 of 18

Anonymous
Not applicable
"Matthew Gonzalez" wrote in message
news:827D57DC8A26E849ED921EB2C6EF075C@in.WebX.maYIadrTaRb...
> OK, I figured out where the problem is, in this area:
>
> Do
> dblCurDist = .GetDistance(, "Enter the distance from grid " &
> strGridA & " to grid " _
> & Chr(Asc(strGridA) + 1) & " [Enter to
> end]: ")
> ReDim Preserve varXDims(intIndex)
> varXDims(intIndex) = .DistanceToReal(dblCurDist,
> acArchitectural)
> ......
>
>
> When the user hits Enter to exit the loop, that empty entry then tries to
> go through the .DistanceToReal conversion and it doesn't like trying to
> convert nothing. Thanks again guys, I'm working up a workaround,
> suggestions are always welcome.
>

I think you are misinterpreting what is occurring. You say that
DistanceToReal can't convert "nothing". Yet you are passing DistanceToReal a
double variable type. That can't be Null or Empty. At worst it could be
zero. Also you say that no error is thrown. Are you sure you don't have an
error handler in effect in a higher sub that calls DrawGridSystem. If so
temporarilly set VB to "break on all errors" under Options.

--Art


> --
> matthew g.
>
>
0 Likes
Message 6 of 18

Anonymous
Not applicable
>
> I think you are misinterpreting what is occurring. You say that
> DistanceToReal can't convert "nothing". Yet you are passing
DistanceToReal a
> double variable type. That can't be Null or Empty. At worst it could be
> zero. Also you say that no error is thrown. Are you sure you don't have
an
> error handler in effect in a higher sub that calls DrawGridSystem. If so
> temporarilly set VB to "break on all errors" under Options.
>

I am feeding DistanceToReal Doubles until I want out of the loop, my prompt
tells the user to hit Enter to exit the loop and that would feed
DistanceToReal either a Null or Empty variable, I'm not sure which as I
don't know the difference. Everything works grand until the point where
the user hits Enter instead of entering a number. I'm thinking that I need
a new strategy for exiting the loop. DrawGridSystem is the only VBA module
loaded so there is no Error Handler loaded any higher up. I'll try the
"break on all errors" setting anyways though, just to see if I can glean
some more info. Thanks.


--
matthew g.
0 Likes
Message 7 of 18

Anonymous
Not applicable
> 1) Run the macro step-by-step. Put your cursor in the Sub you want to
run
> and hit F8. Keep hitting F8 to step through line by line and see if
loops
> get executed or skipped.
>

F8 is very helpful and insightful, thank you.


> 1a) Set breakpoints right before a line of interest and run your Sub.
When
> VBA pauses, use F8 to step through the part your interested in. Might be
> quicker than stepping through your whole subroutine.
>

Breakpoints I've used, F8 I hadn't, it's a nice thing to know.


> 2) Use Debug.Print in loops and If statements to see if they get executed
> and to see what values your loop counter goes through.
>

I will try this.


> 3) I don't use it, there is a Watch window so you can see variable values
> change as the program goes along
>

The Immediate window seems useful too, but I don't know how to use it.
More reading for later I guess.


> Hope this helps.
>

It did, thanks again.


--
matthew g.
0 Likes
Message 8 of 18

Anonymous
Not applicable
"Matthew Gonzalez" wrote in message
news:CE412181592215177BD951B309033A96@in.WebX.maYIadrTaRb...
> >
> > I think you are misinterpreting what is occurring. You say that
> > DistanceToReal can't convert "nothing". Yet you are passing
> DistanceToReal a
> > double variable type. That can't be Null or Empty. At worst it could be
> > zero. Also you say that no error is thrown. Are you sure you don't have
> an
> > error handler in effect in a higher sub that calls DrawGridSystem. If so
> > temporarilly set VB to "break on all errors" under Options.
> >
>
> I am feeding DistanceToReal Doubles until I want out of the loop, my
prompt
> tells the user to hit Enter to exit the loop and that would feed
> DistanceToReal either a Null or Empty variable, I'm not sure which as I
> don't know the difference. Everything works grand until the point where
> the user hits Enter instead of entering a number. I'm thinking that I
need
> a new strategy for exiting the loop. DrawGridSystem is the only VBA
module
> loaded so there is no Error Handler loaded any higher up. I'll try the
> "break on all errors" setting anyways though, just to see if I can glean
> some more info. Thanks.


I still think you're stating the problem wrong (though I don't use vb for
autocad). In your code DistanceToReal is *only* getting a value from a
double variable type, which cannot be null or empty. If GetDistance function
returns null or empty when the user presses enter then your error is in
trying to set the double variable type to that value. In that case you
should use a variant to receive the value from GetDistance, then test for
null or empty, if a normal value then pass it to DistanceToReal.

--Art
>
> --
> matthew g.
>
>
0 Likes
Message 9 of 18

Anonymous
Not applicable
Matthew Gonzalez had this to say
:
> So I'm writing this routine to draw a structural grid still,

Have you considered using MINSERT to insert a 1-unit square block to
your user's specifications?

--
Someone left the grass out in the yard all night.
http://www.acadx.com
0 Likes
Message 10 of 18

Anonymous
Not applicable
Frank Oquendo wrote in message

> Have you considered using MINSERT to insert a 1-unit square block to
> your user's specifications?

the grids I've seen have never been 'regular' or equal space, and even
rarely symmetrical, thus the need for Matthew's excellent efforts. Hang in
there Matthew, you'll get it.
0 Likes
Message 11 of 18

Anonymous
Not applicable
MP had this to say
:
> the grids I've seen have never been 'regular' or equal space, and even
> rarely symmetrical, thus the need for Matthew's excellent efforts.
> Hang in there Matthew, you'll get it.

The whole point of MINSERTing a unit-square block is that you can make a
grid of any spacing by simply using the appropriate X and Y scale
factors.

As for not being regular or symmetrical, that doesn't sound like much of
a grid. Are we talking about the same thing or is this some
industry-specific thing?

--
Someone left the grass out in the yard all night.
http://www.acadx.com
0 Likes
Message 12 of 18

Anonymous
Not applicable
Matthew Gonzalez had this to say
:
> So I'm writing this routine to draw a structural grid still, and I've
> got everything working honky-dory so far (thanks to all of you)
> except for the fact that it never gets to the second Do...Until loop
> below. I get the dimensions from the lettered grids fine and it
> fills the array perfectly but when I hit enter and the blnCheck
> variable clears the test it just quits. It never even gets to
> setting "intGrid1 = 1", I've tried making intGrid1 a double and I've
> tried making intIndex an independent variable in each loop

When I ran your code, it crashed with the error "User input was a
keyword". This occurred when I pressed Enter to end the input loop. Some
error trapping solved the issue and made both loops run. I also changed
the test you were using to end the loop.

--
Someone left the grass out in the yard all night.
http://www.acadx.com
0 Likes
Message 13 of 18

Anonymous
Not applicable
Matthew Gonzalez wrote in message
news:A49AA3F90CE355EAD49F7C1277F5CC0C@in.WebX.maYIadrTaRb...

>
> The Immediate window seems useful too, but I don't know how to use it.
> More reading for later I guess.

Matthew,
As you can see, Frank O beat me by a half hour on this one, but that's just
cause I took time to throw in a couple debug.print lines to show you how I
use the immediate window. 🙂 ha!
Looks like he's doing pretty much the same idea as me, though his is
infinitely to be preferred, but hopefully if you open the immediate window,
then run this test sub, then flip back to vbaide to look at immediate(or
have acadwindow and vbaide window sidebyside while you run the test) you
will see one way to use the immediate window with debug statements to see
what the value of variables has become at different points in your code.
Sub test()
Dim varXDims() As Variant
Dim varYDims() As Variant
Dim dblOrigin(2) As Double
Dim dblDwgScale As Double
Dim dblCurDist As Double
Dim strDirection As String
Dim strLocation As String
Dim strGridA As String
Dim intGrid1 As Integer
Dim intIndex As Integer
Dim blnCheck As Boolean

strGridA = "A"

With ThisDrawing.Utility
.InitializeUserInput 1
On Error Resume Next
Do
'Get the user input
Dim returnPnt As Variant
dblCurDist = .GetDistance(, "Enter the distance from grid " & strGridA
& " to grid " _
& Chr(Asc(strGridA) + 1) & " [Enter to end]: ")

If Err Then 'user hit enter or space bar
'we're done so set blncheck = t
blnCheck = True
'why it throws this error with bit 1 set, I have no idea!?
'(since 1 is supposed to disallow keywords)
If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
Err.Clear
Debug.Print "Input completed: "
Else
MsgBox "Unexpected Error: " & Err.Description
Err.Clear
End If
Else
'if not error, distance was entered
'send value to immediate window for inspection with Debug.Print
Debug.Print "Distance entered: " & dblCurDist
ReDim Preserve varXDims(intIndex)
varXDims(intIndex) = .DistanceToReal(dblCurDist, acArchitectural)
strGridA = Chr(Asc(strGridA) + 1)
intIndex = intIndex + 1
End If

Loop Until blnCheck = True

intGrid1 = 1
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " & intGrid1
& " to grid " _
& intGrid1 + 1 & " [Enter to end]: ")
If Err Then
'we're done so set blncheck = t
blnCheck = True
If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
Err.Clear
Debug.Print "Input completed: "
Else
MsgBox "Unexpected Error: " & Err.Description
Err.Clear
End If
Else
'if not error, distance was entered
Debug.Print "Distance entered: " & dblCurDist
ReDim Preserve varYDims(intIndex)
varYDims(intIndex) = .DistanceToReal(dblCurDist, acArchitectural)
intGrid1 = intGrid1 + 1
blnCheck = IsEmpty(varYDims(intIndex))
intIndex = intIndex + 1
End If
Loop Until blnCheck = True
End With
End Sub
0 Likes
Message 14 of 18

Anonymous
Not applicable
Frank Oquendo wrote in message
>
> As for not being regular or symmetrical, that doesn't sound like much of
> a grid. Are we talking about the same thing or is this some
> industry-specific thing?

must be industry specific (architectural cast stone/precast concrete) so
we're dealing mainly with commercial/institutional bldgs. There seems to be
a rule among the architects whose designs we work on to never repeat a
dimension between grid lines.(slight hyperbole)
Despite their dimensional variation they still anchor and provide reference
for all other bldg elements.
The worst are the ones with no grids! egads!
Unfortunately many of our grid designations are also less regular than
Matthew's seems to be. Instead of A, B, C, we'll have A, A.3, A.8, B, C,
C.4, D, etc...tough to get an automated incrementing algorithm there, but
I've been mulling over some lines to try to detect a pattern if one emerges,
like if A is entered, the next default will be B, but if the user selects
A.1 instead, for instance, then A.2 will be offered as the next default,
etc.
Good 'talking' to you again, been awhile.
(you must drink as much coffee as I do!) 🙂

Mark
ps (what industry are you in?)
0 Likes
Message 15 of 18

Anonymous
Not applicable
MP had this to say
:
> must be industry specific (architectural cast stone/precast concrete)
> so we're dealing mainly with commercial/institutional bldgs.

Sounds like a programming nightmare.

> Good 'talking' to you again, been awhile.
> (you must drink as much coffee as I do!) 🙂

Same here. And it's Diet Dr. Pepper. 😉

> ps (what industry are you in?)

Last drafting job I had was in preconstructed furniture. Before that, it
was sheetmetal.

--
Someone left the grass out in the yard all night.
http://www.acadx.com
0 Likes
Message 16 of 18

Anonymous
Not applicable
>
> Have you considered using MINSERT to insert a 1-unit square block to
> your user's specifications?
>

Nobody needs this at all, I'm just trying to learn how to use VBA and it
was something that I thought of to do. I'm hoping that it will prove
useful once I'm done though. What MP said is true though, the sizes and
grid designations vary quite a bit.


--
matthew g.
0 Likes
Message 17 of 18

Anonymous
Not applicable
>
> When I ran your code, it crashed with the error "User input was a
> keyword". This occurred when I pressed Enter to end the input loop.

I finally figured that out too, thanks.


> Some
> error trapping solved the issue and made both loops run. I also changed
> the test you were using to end the loop.
>

Thank you extremely, you gave me plenty of stuff to look up and read about.


--
matthew g.
0 Likes
Message 18 of 18

Anonymous
Not applicable
> Matthew,
> As you can see, Frank O beat me by a half hour on this one, but that's
just
> cause I took time to throw in a couple debug.print lines to show you how
I
> use the immediate window. 🙂 ha!
(snip)

Thanks a bunch. I am currently ever so slowly figuring out what both you
and Frank did, I appreciate the time that both of you put into it.
Eventually I'll ask better questions but for now thanks for the help with
my clueless questions.


--
matthew g.
0 Likes