473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Export code from Excel 2003 to VB 2008

3
Hello,

I have some trouble to export this code which works fine to VB 2008
This code is intented to work with datalogger.
Expand|Select|Wrap|Line Numbers
  1. Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Integer) As Long
  2. Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByVal handle As Integer, ByVal S As String, ByVal lth As Integer, ByRef requiredSize As Integer, ByVal info As Integer) As Integer
  3. Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Integer, ByVal enabled As Integer, ByVal enable_auto As Integer, ByVal auto_ms As Integer, ByVal channel As Integer, ByVal dir As Integer, ByVal threshold As Integer, ByVal hysterisis As Integer, ByVal delay As Single) As Integer
  4. Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Long, ByVal ideal_no_of_samples As Long, channels As Integer, ByVal No_of_channels As Integer) As Long
  5. Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Integer, values As Integer, no_of_values As Long, overflow As Integer, triggerIndex As Long) As Long
  6. Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Integer, ByVal no_of_values As Long, ByVal method As Integer) As Integer
  7. Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Integer, ByRef ready As Integer) As Long
  8. Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Integer, ByRef maxValue As Integer) As Long
  9.  
  10. Dim status As Long
  11. Dim handle As Integer
  12. Dim values(200) As Integer
  13. Dim channels(22) As Integer
  14. Dim nValues As Long
  15. Dim ok As Integer
  16. Dim ready As Integer
  17. Dim requiredSize As Integer
  18. Dim S As String * 255
  19. Public port As Integer
  20. Public product As Integer
  21. Dim maxValue As Integer
  22.  
  23. Function adc_to_mv(value As Integer) As Integer
  24.   adc_to_mv = value / maxValue * 2500
  25. End Function
  26.  
  27. Sub GetPl1000()
  28.  
  29. ' Open device
  30.     status = pl1000OpenUnit(handle)
  31.     opened = handle <> 0
  32.  
  33. If opened Then
  34.  
  35.   'Get the maximum ADC value for this variant
  36.   status = pl1000MaxValue(handle, maxValue)
  37.  
  38. ' Get the unit information
  39.   Cells(6, "E").value = "Unit opened"
  40.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 3)
  41.   Cells(7, "E").value = S
  42.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 4)
  43.   Cells(8, "E").value = S
  44.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 1)
  45.   Cells(9, "E").value = S
  46.  
  47.   ' No Trigger
  48.   Call pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)
  49.  
  50.   ' Say that we want to take 100 readings in 1 s
  51.   ' from channels 1 and 2
  52.     nValues = 100
  53.     channels(0) = 1
  54.     channels(1) = 2
  55.     Dim sampleInterval As Long
  56.     Dim us_for_block As Long
  57.  
  58.     us_for_block = 1000000
  59.     status = pl1000SetInterval(handle, us_for_block, nValues, channels(0), 2)
  60.  
  61.     status = pl1000Run(handle, nValues, 0)
  62.  
  63.     ready = 0
  64.     Do While ready = 0
  65.         status = pl1000Ready(handle, ready)
  66.     Loop
  67.  
  68.   ' Get a block of 100 readings...
  69.   ' we can call this routine repeatedly
  70.   ' to get more blocks with the same settings
  71.   Dim triggerIndex As Long
  72.   Dim overflow As Integer
  73.   status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)
  74.  
  75.   ' Copy the data into the spreadsheet
  76.   For i = 0 To nValues - 1
  77.      Cells(i + 4, "A").value = adc_to_mv(values(2 * i))
  78.      Cells(i + 4, "B").value = adc_to_mv(values(2 * i + 1))
  79.   Next i
  80.  
  81.   ' Close the unit when finished to drop the driver
  82.   Call pl1000CloseUnit(handle)
  83.  
  84. Else
  85.   Cells(17, "E").value = "Unable to open unit"
  86. End If
  87.  
  88. End Sub
  89.  
  90.  
  91.  

At line :
Expand|Select|Wrap|Line Numbers
  1.  ready = 0
  2.   Do While ready = 0
  3.       status = pl1000Ready(handled, ready)
  4.    Loop
  5.  
it looops for ever instead in Excel it work fine
In order to export it to Vb 98 I have changed my declarations in

Expand|Select|Wrap|Line Numbers
  1. Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Integer) As Long
  2.     Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByRef handle As Integer) As Long
  3.     Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByRef handle As Integer, ByRef S As String, ByRef lth As Integer, ByRef requiredSize As Integer, ByRef info As Integer) As Integer
  4.     Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByRef handle As Integer, ByRef enabled As Integer, ByRef enable_auto As Integer, ByRef auto_ms As Integer, ByRef channel As Integer, ByRef dir As Integer, ByRef threshold As Integer, ByRef hysterisis As Integer, ByRef delay As Single) As Integer
  5.     Declare Function pl1000SetInterval Lib "pl1000.dll" (ByRef handle As Integer, ByRef us_for_block As Long, ByRef ideal_no_of_samples As Long, ByRef channels As Integer, ByRef No_of_channels As Integer) As Long
  6.     Declare Function pl1000GetValues Lib "pl1000.dll" (ByRef handle As Integer, ByRef values As Integer, ByRef no_of_values As Long, ByRef overflow As Integer, ByRef triggerIndex As Long) As Long
  7.     Declare Function pl1000Run Lib "pl1000.dll" (ByRef handle As Integer, ByRef no_of_values As Long, ByRef method As Integer) As Integer
  8.     Declare Function pl1000Ready Lib "pl1000.dll" (ByRef handle As Integer, ByVal ready As Integer) As Long
  9.     Declare Function pl1000MaxValue Lib "pl1000.dll" (ByRef handle As Integer, ByRef maxValue As Integer) As Long
  10.  
may be it is hard help me cause the software is too long , anyway i try to ask you
Thanks in advance
Sep 9 '09 #1
4 2585
petro
3
more info:

That code works fine in Vb6 too
There are some differences i dont know VBA Excel/Vb6 Vs VB2008
Sep 9 '09 #2
tlhintoq
3,525 Expert 2GB
I have some trouble to export this code which works fine to VB 2008
This code is intented to work with datalogger.
Could you be a little more specific about the problem(s)? "Some trouble" is very vague.
Sep 9 '09 #3
petro
3
Hello
Declarations's module updated based on difference between vb6 and vb2008
Expand|Select|Wrap|Line Numbers
  1. Module Module1
  2.     Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Short) As Integer
  3.     Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByRef handle As Short) As Integer
  4.     Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByRef handle As Short, ByVal S As String, ByVal lth As Short, ByRef requiredSize As Short, ByVal info As Short) As Short
  5.     Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByRef handle As Short, ByVal enabled As Short, ByVal enable_auto As Short, ByVal auto_ms As Short, ByVal channel As Short, ByVal dir As Short, ByVal threshold As Short, ByVal hysterisis As Short, ByVal delay As Single) As Short
  6.  
  7. Declare Function pl1000SetInterval Lib "pl1000.dll" (ByRef handle As Short, ByRef us_for_block As Integer, ByVal ideal_no_of_samples As Integer, ByVal channels As Short, ByVal No_of_channels As Short) As Integer
  8.  
  9.     Declare Function pl1000GetValues Lib "pl1000.dll" (ByRef handle As Short, ByVal values As Short, ByVal no_of_values As Integer, ByVal overflow As Short, ByVal triggerIndex As Integer) As Integer
  10.     Declare Function pl1000Run Lib "pl1000.dll" (ByRef handle As Short, ByVal no_of_values As Integer, ByVal method As Short) As Short
  11.     Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Short, ByRef ready As Short) As Integer
  12.     Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Short, ByRef maxValue As Short) As Integer
  13. End Module
  14.  
FORM1:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  Dim status As Integer
  3.     Dim handled As Short
  4.     Dim opened As Short
  5.     Dim values(200) As Short
  6.     Dim channels(22) As Short
  7.     Dim nValues As Integer
  8.     Dim ok As Short
  9.     Private ready As Short
  10.     Dim requiredSize As Short
  11.  
  12.     Dim s As String     'in VB6 it was string*255
  13.     Public port As Short
  14.     Public product As Short
  15.     Dim maxValue As Short
  16.     Dim Slenght As String
  17.  
  18.  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  19.  
  20.     End Sub
  21.  
  22.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  23.  
  24.         ' Open device
  25.         status = pl1000OpenUnit(handled)
  26.         opened = handled <> 0
  27.  
  28.  
  29.         If opened Then
  30.  
  31.             status = pl1000MaxValue(handled, maxValue)
  32.  
  33.             ' Slenght = pl1000GetUnitInfo(handled, s, 255, requiredSize, 3)
  34.  
  35.             Call pl1000SetTrigger(handled, False, 0, 0, 0, 0, 0, 0, 0)
  36.             nValues = 100
  37.             channels(0) = 1
  38.             channels(1) = 2
  39.  
  40.             Dim sampleInterval As Integer
  41.             Dim us_for_block As Integer
  42.  
  43.             us_for_block = 1000000
  44.             status = pl1000SetInterval(handled, us_for_block, nValues, channels(0), 2)
  45.  
  46.             status = pl1000Run(handled, nValues, 0)
  47.  
  48.  
  49.             ready = 0
  50.             Do While ready = 0
  51.                 status = pl1000Ready(handled, ready)
  52.             Loop
  53.  
  54.             MsgBox("ok")
  55.         End If
  56.     End Sub
  57.  
  58.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  59.         pl1000CloseUnit(handled)
  60.  
  61.     End Sub
  62. End Class
  63.  
The problem is this :
At position
Expand|Select|Wrap|Line Numbers
  1.             ready = 0
  2.             Do While ready = 0
  3.                 status = pl1000Ready(handled, ready)
  4.             Loop
  5.  
The var "ready" is always 0 (zero) so the loop is forever.
This is wrong because the hardware works fine and the program works fine in vb/excel 2003 too.
I dont know why it is always 0.
This software comes with datalogger which works perfectly

Follows the program for vb6/excel 2003:
This woks fine in excel 2003/VB 6
Expand|Select|Wrap|Line Numbers
  1. Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Integer) As Long
  2. Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Integer) As Long
  3. Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByVal handle As Integer, ByVal S As String, ByVal lth As Integer, ByRef requiredSize As Integer, ByVal info As Integer) As Integer
  4. Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Integer, ByVal enabled As Integer, ByVal enable_auto As Integer, ByVal auto_ms As Integer, ByVal channel As Integer, ByVal dir As Integer, ByVal threshold As Integer, ByVal hysterisis As Integer, ByVal delay As Single) As Integer
  5.  
  6. This declarations must be changed in "Byval" otherwhise i get an "Accessviolation exceptions.."
  7. Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Long, ByVal ideal_no_of_samples As Long, channels As Integer, ByVal No_of_channels As Integer) As Long
  8.  
  9. Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Integer, values As Integer, no_of_values As Long, overflow As Integer, triggerIndex As Long) As Long
  10. Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Integer, ByVal no_of_values As Long, ByVal method As Integer) As Integer
  11. Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Integer, ByRef ready As Integer) As Long
  12. Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Integer, ByRef maxValue As Integer) As Long
  13.  
  14. Dim status As Long
  15. Dim handle As Integer
  16. Dim values(200) As Integer
  17. Dim channels(22) As Integer
  18. Dim nValues As Long
  19. Dim ok As Integer
  20. Dim ready As Integer
  21. Dim requiredSize As Integer
  22. Dim S As String * 255
  23. Public port As Integer
  24. Public product As Integer
  25. Dim maxValue As Integer
  26.  
  27. Function adc_to_mv(value As Integer) As Integer
  28.   adc_to_mv = value / maxValue * 2500
  29. End Function
  30.  
  31. Sub GetPl1000()
  32.  
  33. ' Open device
  34.     status = pl1000OpenUnit(handle)
  35.     opened = handle <> 0
  36.  
  37. If opened Then
  38.  
  39.   'Get the maximum ADC value for this variant
  40.   status = pl1000MaxValue(handle, maxValue)
  41.  
  42. ' Get the unit information
  43.   Cells(6, "E").value = "Unit opened"
  44.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 3)
  45.   Cells(7, "E").value = S
  46.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 4)
  47.   Cells(8, "E").value = S
  48.   SLegnth = pl1000GetUnitInfo(handle, S, 255, requiredSize, 1)
  49.   Cells(9, "E").value = S
  50.  
  51.   ' No Trigger
  52.   Call pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)
  53.  
  54.   ' Say that we want to take 100 readings in 1 s
  55.   ' from channels 1 and 2
  56.     nValues = 100
  57.     channels(0) = 1
  58.     channels(1) = 2
  59.     Dim sampleInterval As Long
  60.     Dim us_for_block As Long
  61.  
  62.     us_for_block = 1000000
  63.     status = pl1000SetInterval(handle, us_for_block, nValues, channels(0), 2)
  64.  
  65.     status = pl1000Run(handle, nValues, 0)
  66.  
  67.     ready = 0
  68.     Do While ready = 0
  69.         status = pl1000Ready(handle, ready)
  70.     Loop
  71.  
  72.   ' Get a block of 100 readings...
  73.   ' we can call this routine repeatedly
  74.   ' to get more blocks with the same settings
  75.   Dim triggerIndex As Long
  76.   Dim overflow As Integer
  77.   status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)
  78.  
  79.   ' Copy the data into the spreadsheet
  80.   For i = 0 To nValues - 1
  81.      Cells(i + 4, "A").value = adc_to_mv(values(2 * i))
  82.      Cells(i + 4, "B").value = adc_to_mv(values(2 * i + 1))
  83.   Next i
  84.  
  85.   ' Close the unit when finished to drop the driver
  86.   Call pl1000CloseUnit(handle)
  87.  
  88. Else
  89.   Cells(17, "E").value = "Unable to open unit"
  90. End If
  91.  
  92. End Sub
  93.  
Thank for any tips or help
Sep 10 '09 #4
tlhintoq
3,525 Expert 2GB
The problem is this :
At position
Expand|Select|Wrap|Line Numbers
  1.             ready = 0
  2.             Do While ready = 0
  3.                 status = pl1000Ready(handled, ready)
  4.             Loop
  5.  
The var "ready" is always 0 (zero) so the loop is forever.
Well... You set ready to zero, you then passed it to another method. But I see no place where you are trying to get that value back. I wouldn't have expected it to change value. Maybe I'm missing something.

When you pass a value as a parameter the receiving method receives into a new variable. A copy of the value you send, if you will.

I would expect you need to do something with the 'status' variable since this is returning results from the method you are calling (pl1000Ready)
Sep 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andre | last post by:
I'm not sure if this is the best place for this post or not, but I can't find many asp newsgroups anymore. I have an app that's 3-4 years old, and has been working just fine. One of the pages...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
8
by: DC Gringo | last post by:
I have a simple button that should open another window and export a datagrid to an Excel file. I'm getting: "Name 'window' is not declared." What do I need to declare or import? <INPUT...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
1
by: cehether | last post by:
Hello everyone. I am trying to export the contents of a DataGrid to MS Excel using VB.NET 2003. I read of a couple different ways of doing that here (though I couldn't tell which version of...
0
by: sandervanee | last post by:
Hello, I am trying to export several Access 2003 select queries to Excel 2003 using an Access macro. I'm using the macro command "TransferSpreadsheet" to export the queries. This going quit well,...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
6
Cintury
by: Cintury | last post by:
Using Access 2003 (Access 2000 file format) on Windows XP I have a query that pulls from 2 tables that includes a date as well as other data. What I need is code to put in the SQL view, if this is...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.