Do... While Loop Question

Do... While Loop Question

Anonymous
Not applicable
586 Views
13 Replies
Message 1 of 14

Do... While Loop Question

Anonymous
Not applicable
Hello, I'm pretty new to VBA so go easy on me but here's my question. The
code below doesn't work, no error, nothing. It just seems to never get
there or it skips it completely, I'm not sure which. There is a
Select...Case function right above it that runs exactly how it should but
then it just ends, thanks. I'm trying to get dimensions in the X direction
for a grid system that I'm going to draw with the provided input. I put
each given dimension into an array of Variants called varXdims, here's the
code:

strGridA = "A"
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " &
strGridA & " to grid " & strGridA + 1)
ReDim Preserve varXDims(UBound(varXDims) + 1)
varXDims(intIndex) = .DistanceToReal(dblCurDist,
acArchitectural)
strGridA = strGridA + 1
intIndex = intIndex + 1
Loop Until blnCheck = IsEmpty(varXDims(intIndex))



--
matthew g.
0 Likes
587 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Matthew Gonzalez had this to say
:
> There is a Select...Case function right above it that runs exactly how
it
> should but then it just ends, thanks.

We're gonna need to see that.

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

Anonymous
Not applicable
Here is the entire thing so far, obviously not complete but I was trying to
do it in chunks and check myself for basic functionality along the way.
Here you go, I hope word wrap doesn't murder it too badly:

Option Explicit

Public Sub DrawGridSystem()

Dim varXDims() As Variant
Dim varYDims() As Variant
Dim intADirection As Integer
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 strGrid1 As String
Dim intIndex As Integer
Dim blnCheck As Boolean


On Error Resume Next

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 at [Top/Bottom]: ")

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

Case Else
MsgBox "Invalid Input"
End Select

strGridA = "A"
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " &
strGridA & " to grid " & strGridA + 1)
ReDim Preserve varXDims(UBound(varXDims) + 1)
varXDims(intIndex) = .DistanceToReal(dblCurDist,
acArchitectural)
strGridA = strGridA + 1
intIndex = intIndex + 1
Loop Until blnCheck = IsEmpty(varXDims(intIndex))

End With
End Sub
0 Likes
Message 4 of 14

Anonymous
Not applicable
Here is the first part of your problem

strGridA = "A"
intIndex = 0

Do
dblCurDist = .GetDistance(, "Enter the distance from grid " & strGridA & " to grid " & strGridA + 1)

You are setting strGridA to a literal then trying to adding the numeral "1" to it.

If you comment out the "On Error Resume Next" line you will have more success finding errors - since you're really not doing any error checking - just skipping right on ...
0 Likes
Message 5 of 14

Anonymous
Not applicable
This line will not work either


ReDim Preserve varXDims(UBound(varXDims) + 1)


since varXDims has yet to be dimensioned it has no UBound value.
0 Likes
Message 6 of 14

Anonymous
Not applicable
I already tried it without the "On Error Resume Next" and there was no
difference. Are you saying that in VBA I cannot increment a String? If
that is the case then how do I change an "A" to a "B" to a "C" and so
forth?


--
matthew g.
0 Likes
Message 7 of 14

Anonymous
Not applicable
> This line will not work either
>
>
> ReDim Preserve varXDims(UBound(varXDims) + 1)
> since varXDims has yet to be dimensioned it has no UBound value.
>

So what is common practice to get around that? Fill in the first slot with
a zero and then just skip that one when I go to get my actual numbers from
the array or is there something cleaner?


--
matthew g.
0 Likes
Message 8 of 14

Anonymous
Not applicable
"Matthew Gonzalez" wrote in message
news:C5A9D4906DD79B22A70035C32E159439@in.WebX.maYIadrTaRb...
> > This line will not work either
> >
> >
> > ReDim Preserve varXDims(UBound(varXDims) + 1)
> > since varXDims has yet to be dimensioned it has no UBound value.
> >
>
> So what is common practice to get around that? Fill in the first slot
with
> a zero and then just skip that one when I go to get my actual numbers from
> the array or is there something cleaner?

In your case, wouldn't

ReDim Preserve varXDims(intIndex)

work?
0 Likes
Message 9 of 14

Anonymous
Not applicable
>
> In your case, wouldn't
>
> ReDim Preserve varXDims(intIndex)
>
> work?
>

I don't see why not, and that's a whole lot cleaner looking too. Thanks
adam.


--
matthew g.
0 Likes
Message 10 of 14

Anonymous
Not applicable
"Matthew Gonzalez" wrote in message
news:8E7FDA9CEDF6C5DE9229FED7DCF76756@in.WebX.maYIadrTaRb...
> >
> > In your case, wouldn't
> >
> > ReDim Preserve varXDims(intIndex)
> >
> > work?
> >
>
> I don't see why not, and that's a whole lot cleaner looking too. Thanks
> adam.

Better thank Frank, too. I had the same question a few weeks back, and
that's how he straightened me out.
0 Likes
Message 11 of 14

Anonymous
Not applicable
function increment_string(char) as string
increment_string = chr(asc(char) + 1)
end function
ofcourse you will have to check for the end of the alphabet.

Tom Craft
Matthew Gonzalez wrote:

> I already tried it without the "On Error Resume Next" and there was no
> difference. Are you saying that in VBA I cannot increment a String? If
> that is the case then how do I change an "A" to a "B" to a "C" and so
> forth?
>
> --
> matthew g.
0 Likes
Message 12 of 14

Anonymous
Not applicable
Thanks Tom, I wasn't turning anything up in the help files.


--
matthew g.
0 Likes
Message 13 of 14

Anonymous
Not applicable
>
> Better thank Frank, too. I had the same question a few weeks back, and
> that's how he straightened me out.
>

Thanks Frank.


--
matthew g.
0 Likes
Message 14 of 14

Anonymous
Not applicable
> function increment_string(char) as string
> increment_string = chr(asc(char) + 1)
> end function
> ofcourse you will have to check for the end of the alphabet.
>


And it works great! Thanks again.


--
matthew g.
0 Likes