not code error in vba, vba not read exce data

not code error in vba, vba not read exce data

Anonymous
Not applicable
507 Views
4 Replies
Message 1 of 5

not code error in vba, vba not read exce data

Anonymous
Not applicable
it's believale thing happen
ever if vba code has not error, basic program did not read excel file
vba not read excel file and to run and to terminate
what is problem? who is know reason?
code following
data attached is vba code,and excel file
following is code


Dim xlapp As Excel.Application
Dim xlbook As Excel.Application
Dim xlsheet As Excel.worksheet
Dim xlrange As Excel.Range
Dim pointobj As AcadPoint
Dim location(0 To 2) As Long
Dim ra, dec As Double

Dim radegree As Double
Dim decdegree As Double


Dim dist As Double
Dim indx As Double

Dim jndx As Double
Dim lngrows As Double


Dim lngcols As Long
Dim mas As Long

Dim sign As String
Dim coeff As Integer
Dim cof As Integer

Dim radtrad As Long
Dim decdtrad As Long


MsgBox "be patience,works slowly"

On Error Resume Next
Err.Clear
Set xlapp = GetObject(, "excel.application")

Set xlapp = CreateObject("excel application")






Const pi = 3.141592



xlapp.Display.alerts = False
xlapp.Visible = True
xlapp.WindowState = xlMinimized
Set xlbook = xlapp.Workbooks.Open(FileName:="c:\200mas.xls")



xlsheet.Activate
'get excel data
lngrows = xlbook.activesheet.usedrange.Rows.Count
lngcols = xlbook.activesheet.usedrange.Columns.Count

AcadApplication.widowstate = acMax
Set xlsheet = xlbook.worksheet(1)


ReDim dataarr(lngrows - 1, lngcols - 1)

For indx = 1 To lngcols
For jndx = 11 To lngrows

dataarr(indx - 1, jndx) = xlsheet.Cells(indx, jndx):
dataarr(indx - 1, jndx + 1) = xlsheet.Cells(indx, jndx + 1):
dataarr(indx - 1, jndx + 2) = xlsheet.Cells(indx, jndx + 2):



ra = dataarr(indx, jndx)
dec = dataarr(indx, jndx + 1)
mas = dataarr(indx, jndx + 2)

If xlsheet.Cells(indx, jndx) = "ra" Then
indx = indx + 1
End If



sign = Left("dec", 1)
If sign = "-" Then
coeff = -1
Else
coeff = 1

End If
sign = Left(dec, 1)
If sign = "+" Then
cof = 1


End If





radegree = 15 * Val(Mid("ra", 1, 2)) + 15 * Val(Mid("ra", 4, 2)) / 60 + 15 *
Val(Mid("ra", 7, 6)) / 3600


decdegree = Val(Mid("dec", 2, 2)) * coeff * cof + Val(Mid("dec", 5, 2)) * coeff * cof /
60 + Val(Mid("dec", 8, 6)) * coeff * cof / 3600









'in hipparcos,distance display mas(mili-arcs-econd), so must do 1000/mas
dist = (1000 / Val(mas)) * 3.26 'dist is parsec 5*3.26 light year

radtrad = (radegree / 180) * pi 'ra transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian

'cosmic 3-D point (x,y,z)- sine cosine is used
'modelspace command is dist
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
ZoomAll
xlapp.DisplayAlerts = True

xlbook.Close savechanges:=False
xlapp.Quit
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
DoEvents
0 Likes
508 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Hi,

Why not use the editing tools in the VBA editor to step through your code
and see where the error is occurring yourself?

Simply open the file with your code, put the cursor in the Sub routine and
press F8 to step through one line of code each time you press F8

--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5434632@discussion.autodesk.com...
it's believale thing happen
ever if vba code has not error, basic program did not read excel file
vba not read excel file and to run and to terminate
what is problem? who is know reason?
code following
data attached is vba code,and excel file
following is code


Dim xlapp As Excel.Application
Dim xlbook As Excel.Application
Dim xlsheet As Excel.worksheet
Dim xlrange As Excel.Range
Dim pointobj As AcadPoint
Dim location(0 To 2) As Long
Dim ra, dec As Double

Dim radegree As Double
Dim dec
degree As Double


Dim dist As Double
Dim indx As Double

Dim jndx As Double
Dim lngrows As Double


Dim lngcols As Long
Dim mas As Long

Dim sign As String
Dim coeff As Integer
Dim cof As Integer

Dim radtrad As Long
Dim decdtrad As Long


MsgBox "be patience,works slowly"

On Error Resume Next
Err.Clear
Set xlapp = GetObject(, "excel.application")

Set xlapp = CreateObject("excel application")







Const pi = 3.141592



xlapp.Display.alerts = False
xlapp.Visible = True
xlapp.WindowState = xlMinimized
Set xlbook = xlapp.Workbooks.Open(FileName:="c:\200mas.xls")



xlsheet.Activate
'get excel data
lngrows = xlbook.activesheet.usedrange.Rows.Count
lngcols = xlbook.activesheet.usedrange.Columns.Count

AcadApplication.widowstate = acMax
Set xlsheet = xlbook.worksheet(1)


ReDim dataarr(lngrows - 1, lngcols - 1)


For indx = 1 To lngcols
For jndx = 11 To lngrows

dataarr(indx - 1, jndx) = xlsheet.Cells(indx, jndx):
dataarr(indx - 1, jndx + 1) = xlsheet.Cells(indx, jndx +
1):
dataarr(indx - 1, jndx + 2) = xlsheet.Cells(indx, jndx +
2):



ra = dataarr(indx, jndx)
dec = dataarr(indx, jndx + 1)
mas = dataar
r(indx, jndx + 2)

If xlsheet.Cells(indx, jndx) = "ra" Then
indx = indx + 1
End If



sign = Left("dec", 1)
If sign = "-" Then
coeff = -1

Else
coeff = 1

End If
sign = Left(dec, 1)
If sign = "+" Then
cof = 1


End If






radegree = 15 * Val(Mid("ra", 1, 2)) + 15 * Val(Mid("ra", 4, 2)) / 60 + 15 *
Val(Mid("ra", 7, 6)) / 3600


decdegree = Val(Mid("dec", 2, 2)) * coeff * cof + Val(Mid("dec", 5, 2)) *
coeff * cof /
60 + Val(Mid("dec", 8, 6)) * coeff * cof / 3600









'in hipparcos,distance display mas(mili-arcs-econd), so must do 1000/mas
dist = (1000 / Val(mas)) * 3.26 'dist is parsec 5*3.26 light year

radtrad = (radegree / 180) * pi 'r
a transferring from degree to radian
decdtrad = (decdegree / 180) * pi 'dec tranfering from degree to radian

'cosmic 3-D point (x,y,z)- sine cosine is used
'modelspace command is dist
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
ZoomAll
xlapp.DisplayAlerts = True

xlbook.Close savechanges:=False
xlap
p.Quit
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
DoEvents
0 Likes
Message 3 of 5

Anonymous
Not applicable
I do not unnerstanding error about looping for-next sentence
see and see do not undenstand
it is difficulty problem
it's 3d map of galaxy's arm' (pointing method)
attachted file is vba code file and excel data file
0 Likes
Message 4 of 5

Anonymous
Not applicable
thanks to your advice about f8 ,it is so useful
I do not unnerstanding error about looping for-next sentence
see and see do not undenstand
it is difficulty problem
it's 3d map of galaxy's arm' (pointing method)
attachted file is vba code file and excel data file
0 Likes
Message 5 of 5

Anonymous
Not applicable
Hi,

Until you build your own skills up to the stage where you are capable of
identifying where your errors are occurring and searching the newsgroups for
answers which have been posted to similar problems and interpreting the
answers so as to apply to your problem, you should not be trying to code
such a complex project.

Why don't you write a simpler program and get it to work first so as to
build your skills?

Also, you should read the help file each time you get an error, so as you
can understand why you are getting the error.


--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5434707@discussion.autodesk.com...
thanks to your advice about f8 ,it is so useful
I do not unnerstanding error about looping for-next sentence
see and see do not undenstand
it is difficulty problem
it's 3d map of galaxy's arm' (pointing method)
attachted file is vba code file and excel data file
0 Likes