Message 1 of 1
method of exit in for next in vba,3d pointing

Not applicable
12-26-2006
07:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
follow ing code is 3-d map our galaxy arm drawed autocad 2005
distance is by data of 16.3 light year from the Earth
if when code is runed, in screen, output is displayed but during debuging, some
strange logic error discovered ,
how think about thiw logic problem
in briefly, first problem:
to quit second(inner) for next, if I use "for exit", vba is quit all of for next
how to I must do, use do while, do until I do not know help me
second problem:
in middle of vba code ,if use jndx=jndx+1(colums) ,only outputed one of dot as
finally value
in arrry method , if use jndx+1 ,in output data, all of array data outputed
is that correct why please autodesk engineer repry this non reasonable problem oh
my god
third problem
in first running I don't know,when to end data processing , and in end of next, konw
must to exist output command and then output command must exist in second for next
of data processing
help me I do not know other method what is it
forth problem
in during debugging some stange thing found
if compare computer's caculating value with electric calculater'vaule ,
1 or 2 value is exist different , my caculator is casio fx-570s
is orginally different between computer and caculator
following is that's vba code
attached file is vba code and excel file( data of 16.3 light year from earth of our
galaxy's arm)
excel data is query from http://archive.ast.cam.ac.uk/hipp/
Private Sub UserForm_Initialize()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim coeff As Integer '+1 or -1
Dim location(0 To 2) As Double
Dim pointobj As AcadPoint
Dim lngRows As Integer
Dim lngCols As Integer
Dim indx As Integer
Dim jndx As Intege
Dim ra As Double 'orbit coordiate of earth
Dim dec As Double 'declination (elevater)
Dim mas As Double ' palallax(use to distance)
Dim radegree As Double 'ra degree
Dim decdegree As Double 'dec degree
Dim radtrad As Double 'ra degree to radian
Dim decdtrad As Double 'dec degree to radian
Dim dist As Double 'distance
MsgBox "Be patience, works slowly"
On Error Resume Next
Err.Clear ' clear any errors
Set xlApp = GetObject(, "Excel.application") ' See if Excel is running
If Err 0 Then ' ' If Excel not running start a new session
Err.Clear
Set xlApp = CreateObject("Excel.application") ' Start Excel if excel is not running
If Err 0 Then
MsgBox " Could not start Excel ! , Is Excel Installed ? ", vbCritical, " Excel Error ! "
Err.Clear
End If
End If
Err.Clear
xlApp.DisplayAlerts = False
xlApp.Visible = True ' Make excel application visible
xlApp.WindowState = xlMinimized ' Minimize application window so we don't see it
Set xlBook = xlApp.Workbooks.Open(FileName:="c:\200mas.xls")
' Make Autocad window maximum
AcadApplication.WindowState = acMax
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Activate ' make sheet 1 the active sheet
ListBox1.ColumnCount = 2
ListBox1.BoundColumn = 2
ListBox1.ColumnWidths = "5cm;3cm"
'
' get Excel data
'
lngRows = xlBook.ActiveSheet.UsedRange.Rows.Count
lngCols = xlBook.ActiveSheet.UsedRange.Columns.Count
'
' populate listbox
Const pi = 3.141592
ReDim dataarr(lngCols, lngRows)
For indx = 2 To lngRows
line1:
For jndx = 11 To lngCols
If xlSheet.Cells(indx, jndx) = "RA" Then GoTo line1
If xlSheet.Cells(indx, jndx) = "RA" Then GoTo line1
dataarr(indx, jndx) = xlSheet.Cells(indx, jndx):
dataarr(indx, jndx + 1) = xlSheet.Cells(indx, jndx + 1):
dataarr(indx, jndx + 2) = xlSheet.Cells(indx, jndx + 2):
If Mid(xlSheet.Cells(indx, jndx + 1), 1, 1) = "-" Then coeff = -1 Else: coeff = 1
mas = 1000 / xlSheet.Cells(indx, jndx + 2) ' caluclateing distance
dist = 3.26 * mas
'calculating ra degree
radegree = 15 * Mid(dataarr(indx, jndx), 1, 2) + 15 * Mid(dataarr(indx, jndx), 4, 2) / 60 + 15 * Mid(dataarr(indx, jndx), 7, 6) / 3600
'caculating dec degree
decdegree = Mid(dataarr(indx, jndx + 1), 2, 2) * coeff + Mid(dataarr(indx, jndx + 1), 5, 2) * coeff / 60 + Mid(dataarr(indx, jndx + 1), 8, 6) * coeff / 3600
'transfering ra degree to radian
radtrad = (radegree / 180) * pi 'ra transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian
'position of x,y z of location0=x,location1=y,location2=z
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) * Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location)
Next
Next
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) * Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location())
ListBox1.List() = dataarr
xlApp.DisplayAlerts = True
xlBook.Close Savechanges:=False
xlApp.Quit
' clean up
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
DoEvents
frmReadAstro.Caption = dataarr(0, 0)
ZoomAll
End Sub
distance is by data of 16.3 light year from the Earth
if when code is runed, in screen, output is displayed but during debuging, some
strange logic error discovered ,
how think about thiw logic problem
in briefly, first problem:
to quit second(inner) for next, if I use "for exit", vba is quit all of for next
how to I must do, use do while, do until I do not know help me
second problem:
in middle of vba code ,if use jndx=jndx+1(colums) ,only outputed one of dot as
finally value
in arrry method , if use jndx+1 ,in output data, all of array data outputed
is that correct why please autodesk engineer repry this non reasonable problem oh
my god
third problem
in first running I don't know,when to end data processing , and in end of next, konw
must to exist output command and then output command must exist in second for next
of data processing
help me I do not know other method what is it
forth problem
in during debugging some stange thing found
if compare computer's caculating value with electric calculater'vaule ,
1 or 2 value is exist different , my caculator is casio fx-570s
is orginally different between computer and caculator
following is that's vba code
attached file is vba code and excel file( data of 16.3 light year from earth of our
galaxy's arm)
excel data is query from http://archive.ast.cam.ac.uk/hipp/
Private Sub UserForm_Initialize()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim coeff As Integer '+1 or -1
Dim location(0 To 2) As Double
Dim pointobj As AcadPoint
Dim lngRows As Integer
Dim lngCols As Integer
Dim indx As Integer
Dim jndx As Intege
Dim ra As Double 'orbit coordiate of earth
Dim dec As Double 'declination (elevater)
Dim mas As Double ' palallax(use to distance)
Dim radegree As Double 'ra degree
Dim decdegree As Double 'dec degree
Dim radtrad As Double 'ra degree to radian
Dim decdtrad As Double 'dec degree to radian
Dim dist As Double 'distance
MsgBox "Be patience, works slowly"
On Error Resume Next
Err.Clear ' clear any errors
Set xlApp = GetObject(, "Excel.application") ' See if Excel is running
If Err 0 Then ' ' If Excel not running start a new session
Err.Clear
Set xlApp = CreateObject("Excel.application") ' Start Excel if excel is not running
If Err 0 Then
MsgBox " Could not start Excel ! , Is Excel Installed ? ", vbCritical, " Excel Error ! "
Err.Clear
End If
End If
Err.Clear
xlApp.DisplayAlerts = False
xlApp.Visible = True ' Make excel application visible
xlApp.WindowState = xlMinimized ' Minimize application window so we don't see it
Set xlBook = xlApp.Workbooks.Open(FileName:="c:\200mas.xls")
' Make Autocad window maximum
AcadApplication.WindowState = acMax
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Activate ' make sheet 1 the active sheet
ListBox1.ColumnCount = 2
ListBox1.BoundColumn = 2
ListBox1.ColumnWidths = "5cm;3cm"
'
' get Excel data
'
lngRows = xlBook.ActiveSheet.UsedRange.Rows.Count
lngCols = xlBook.ActiveSheet.UsedRange.Columns.Count
'
' populate listbox
Const pi = 3.141592
ReDim dataarr(lngCols, lngRows)
For indx = 2 To lngRows
line1:
For jndx = 11 To lngCols
If xlSheet.Cells(indx, jndx) = "RA" Then GoTo line1
If xlSheet.Cells(indx, jndx) = "RA" Then GoTo line1
dataarr(indx, jndx) = xlSheet.Cells(indx, jndx):
dataarr(indx, jndx + 1) = xlSheet.Cells(indx, jndx + 1):
dataarr(indx, jndx + 2) = xlSheet.Cells(indx, jndx + 2):
If Mid(xlSheet.Cells(indx, jndx + 1), 1, 1) = "-" Then coeff = -1 Else: coeff = 1
mas = 1000 / xlSheet.Cells(indx, jndx + 2) ' caluclateing distance
dist = 3.26 * mas
'calculating ra degree
radegree = 15 * Mid(dataarr(indx, jndx), 1, 2) + 15 * Mid(dataarr(indx, jndx), 4, 2) / 60 + 15 * Mid(dataarr(indx, jndx), 7, 6) / 3600
'caculating dec degree
decdegree = Mid(dataarr(indx, jndx + 1), 2, 2) * coeff + Mid(dataarr(indx, jndx + 1), 5, 2) * coeff / 60 + Mid(dataarr(indx, jndx + 1), 8, 6) * coeff / 3600
'transfering ra degree to radian
radtrad = (radegree / 180) * pi 'ra transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian
'position of x,y z of location0=x,location1=y,location2=z
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) * Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location)
Next
Next
location(0) = dist * Cos(decdtrad) * Cos(radtrad): location(1) = dist * Sin(radtrad) * Cos(decdtrad): location(2) = dist * Sin(decdtrad)
Set pointobj = ThisDrawing.ModelSpace.AddPoint(location())
ListBox1.List() = dataarr
xlApp.DisplayAlerts = True
xlBook.Close Savechanges:=False
xlApp.Quit
' clean up
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
DoEvents
frmReadAstro.Caption = dataarr(0, 0)
ZoomAll
End Sub