473,396 Members | 2,010 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,396 software developers and data experts.

creating an XL Spreadsheet in VB 5.0

there is a an type mismatch error i am getting, when i want to creat an XL file for my code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command6_Click()
  3. ' Forward mode1
  4. Dim scanner As Integer
  5. Dim StrMsgn As Integer
  6. Dim Forwardn As Integer
  7. Dim StoreVal(20) As Integer
  8. 'StrMsgn = "forwardn" & vbCrLf
  9. For Forwardn = 0 To Text9.Text
  10.  If CInt(Text1.Text) > 0 And CInt(Text1.Text) < 1000 Then
  11.           For a = 1 To CInt(Text1.Text)
  12.           'For a = 1 To 20
  13.           'MsgBox ("Please set number of steps from 0 to 999.")
  14.               USB1.WR_P0 (1)
  15.               Sleep (Speed)
  16.               USB1.WR_P0 (2)
  17.               Sleep (Speed)
  18.               USB1.WR_P0 (4)
  19.               Sleep (Speed)
  20.               USB1.WR_P0 (8)
  21.               Sleep (Speed)
  22.           Next a
  23.       ' switch current to zero
  24.       USB1.WR_P0 (0)
  25.       Sleep (2)
  26.       'StrMsgn = StrMsgn & Forwardn & "," & vbCrLf
  27.    Else
  28.     MsgBox ("Please set number of steps from 0 to 999.")
  29.    End If
  30.    StoreVal(0) = USBvolt.VOLT_CH1
  31.                 For scanner = 1 To Text8.Text
  32.                     Sleep (500)
  33.                     StoreVal(scanner) = USBvolt.VOLT_CH1
  34.                     Text5.Text = StoreVal(scanner)
  35.                 Next scanner
  36. Next Forwardn
  37. 'Call WriteInfo(StrMsgn)
  38. End Sub
  39.  
  40. Private Function WriteInfo(WriteForwardn As String)
  41.  
  42.  
  43.     Dim Forwardn As Integer 'making forward n times
  44.     Dim fson, txtfile
  45.  
  46.     Set fso = CreateObject("Scripting.FileSystemObject")
  47.     Set txtfile = fso.CreateTextFile(App.Path & "\testn.csv", True)
  48.     txtfile.Write (WriteStr) ' Write a line.
  49.  
  50.     txtfile.Close
  51.  
  52. End Function
this is my code and i am trying to write XL file for the values i am scanning in the main code. can anybody please help me to get it through.
Apr 3 '09 #1
1 1633
kadghar
1,295 Expert 1GB
What i can see here is that you have a string and you try to write it into a CSV (coma separated values) text file.

You can actually, write it directly into an Excel File:

Instead of writing a single string with comas, write a 2d array.
When you have this array, lets say a 4x5 array (4 will be the rows, 5 the columns). Use the same method (active x) you use for a text file, but for an Excel file.

Google search some Excel's VBA functions, but, hoppefuly, something like this should do (if you have an 'Arr1(4,5)' array):

Expand|Select|Wrap|Line Numbers
  1. dim Obj1 as object
  2. set obj= createobject("excel.application")
  3. obj1.workbooks.add
  4. obj1.worksheets.add
  5. with obj1.worksheets(1)
  6.     .range(.cells(1,1),.cells(4,5)) = Arr1
  7. end with
  8. obj1.visible=true
HTH
Apr 4 '09 #2

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

Similar topics

4
by: shank | last post by:
I'm creating a spreadsheet online via ASP. I have the following at the page top... <% Response.contenttype = "application/vnd.ms-excel" %> <% Response.AddHeader "Content-Disposition",...
0
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We...
3
by: A.M | last post by:
Hi, Using ASP.NET/VB.NET and SQL Server backend, I need to return calculation results to user as an Access MDB file or Excel XLS sheet. What would be the best way to create a MDB or XLS file...
14
by: Raoul Snyman | last post by:
Hi, I need to be able to programatically create excel spreadsheets in ASP.NET (C#), WITHOUT having MS Office on the server. Does anybody have any advice/links/whatever for me? Thanks in...
9
by: Gordon | last post by:
Hello again, Sorry to repost this request, but I'm under a bit of pressure to find a quick solution. All I basically want is an automatically updating link (OLE, not DDE) between a control in...
3
by: Ken Hall | last post by:
Is it possible to create an Excel spreadsheet using VB.NET without opening the Excel application or having to have the Excel application on the operating computer? KH
1
by: Mitch | last post by:
I am using Access to create an Excel spreadsheets with graphs related to rows on the sheet1 to the graph on sheet2. I am using the same data but different subsets of the data to make different...
2
by: vijayarl | last post by:
Hi Everyone, Am trying to collate the individual xls files into a single xls file.i have written this code. use strict; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; use...
5
by: Lindie | last post by:
We use a spreadsheet to record attendance for pupils with special needs. They live-in so we need 365/365 attendance details. The spreadsheet is getting too cumbersome, a Db is needed. I would...
6
by: dillipkumar | last post by:
hi, i have one excel file, i want to create a hash of hash from the excel file, like: %hash= , sheet2 => , .... .... ];
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.