Excel adding digits when logging with VBA script - Page 1
Forum section: electronics / general

author: veedub565
author_rank: Frequent Contributor
timestamp: February 18, 2024, 05:46:01 pm
content: Not sure if this is the correct part of the forum.I'm using a VBA script to control a Datron 1281A DMM, take a reading every 15min, and dump it into Excel. And it works... except Excel keeps putting numbers in that are different to what the DMM has reported on the GPIB bus (I'm using message capture). this is with 8.5 digit resolution on the DMM, but even when I set 4 digit resolution Excel still puts in the same number of digits.Excel formatting for the cells is "general", I tried setting to number with a specific number of decimal places, and it still makes figures up, just less of them.Read from DMM =13.080466213.080447913.080432213.0804354Logged in Excel13.0804662713.0804481513.0804319413.08043575Not a clue why it is doing this, I'm not a programmer by any means, someone sent me this script that they wrote for a 34401A originally, I'm trying to alter it to my purposes. ANds they aren't sure why it's doing this either.

author: veedub565
author_rank: Frequent Contributor
timestamp: February 18, 2024, 05:49:01 pm
content: Here's some of the codeClass Module C1281Public Property Let Mode(Value As String)pMode = ValueIf pMode = "AC" ThenCall Talkto(pGPIB, "ACV AUTO,FILT-ON,RESL4" & Chr$(10), 100)ElseIf pMode = "DC" Then Call Talkto(pGPIB, "DCV AUTO,RESL8", 100)ElseIf pMode = "FREQ" Then Call Talkto(pGPIB, " ", 100)ElseIf pMode = "RES" Then Call Talkto(pGPIB, "OHMS AUTO,TWR,RESL6", 100)ElseIf pMode = "4RES" Then Call Talkto(pGPIB, "OHMS AUTO,FWR,RESL6", 100)ElseIf pMode = "IDC" Then Call Talkto(pGPIB, "DCI AUTO,FILT-ON,RESL6", 100)ElseIf pMode = "IAC" Then Call Talkto(pGPIB, "ACI AUTO,FILT-ON,RESL6", 100)Else:Call Talkto(pGPIB, "DCV AUTO,RESL8" & Chr$(10), 100)pMode = "DC"End IfEnd PropertyTestSub MeasVolts()Sheet = "Sheet1"Row = 1'OPC = 0tInput = Sheets(Sheet).Range("C1").ValueMColumn = Sheets(Sheet).Range("C2").ValueRdgs = Sheets(Sheet).Range("C3").ValueSet DVM = New C1281DVM.Mode = "DC"For Reading = 1 To RdgsFor tDelay = 1 To tInputCall Wait(10)DoEventsNext tDelay'While Sheets(Sheet).Cells(1, Column).Value > 1While Sheets(Sheet).Range(MColumn & Row).Value <> 0Row = Row + 1'Column = Column + 1DoEventsWendSheets(Sheet).Range(MColumn & Row).Value = DVM.LevelDoEventsNext ReadingSet DVM = NothingCall CloseAllEnd SubCommand LibrarySub Readlong(Device, Command, Answer)'Check to see if Addresses of kit loadedIf (addresslist(Device) < 1) ThenCall SetAddress(Device)End IfDim Buffer As String * 30'MsgBox ("Command Length " & Len(Command))Call viWrite(addresslist(Device), Command, Len(Command), Len(Command))'Call viVPrintf(addresslist(Device), Command & "\n", 0) 'Chr$(10), 0)Call Sleep(120000)Call viVScanf(addresslist(Device), "%t", Buffer)Buffer = Replace(Buffer, Chr$(10), "") '"\n", "") Line feedBuffer = Replace(Buffer, Chr$(13), "") '"\l", "") Carriage returnBuffer = Replace(Buffer, Chr$(32), "") '"\r", "") SpaceAnswer = Buffer * 1End Sub

author: golden_labels
author_rank: Super Contributor
timestamp: February 21, 2024, 07:20:28 am
content: The crucial part of the code, the one that calculates the value ofLevelin classC1281, is missing from your post. Also, please put code in[﻿code﻿]tags.Seems like the improper handling offloating point numbers. Either somebody is usingSingletype instead ofDoublefor storing values, or in some way messes up conversion from DMM’s raw data.Note that “additional digits” themselves arenotthe problem. Neither is the value being slightly different from what you expect. Floating point numbers represent values with limited precision, which aligns well with how measurements work. The problem here is that they are way off — below what one would expect from Excel’s storage format (64-bit IEEE-754).

author: veedub565
author_rank: Frequent Contributor
timestamp: February 23, 2024, 04:50:46 pm
content: Thanks for the explanation, I'll have another look at code and see if I can find the missing parts. And I'll have a look into single type and double type, see if I can see which is in use here.I could attached the

author: golden_labels
author_rank: Super Contributor
timestamp: February 23, 2024, 08:00:18 pm
content: “The” was not attached.

author: veedub565
author_rank: Frequent Contributor
timestamp: February 24, 2024, 10:07:19 am
content: Doh, I was going to attach whole VBA script file, but then I thought it isn't my work and don't really want it made public in it's entirety. Then I forgot to edit my post too