Jump to content

Javascript - help getting variable out of function [solved]


Recommended Posts

I'm using this node module, dbffile to try and get a count of records in a database.

I want to modify their existing example:

DBFFile.open('[full path to .dbf file]')
    .then(dbf => {
        console.log(`DBF file contains ${dbf.recordCount} rows.`);
        console.log(`Field names: ${dbf.fields.map(f => f.name)}`);
        return dbf.readRecords(100);
    })
    .then(rows => rows.forEach(row => console.log(row)))
    .catch(err => console.log('An error occurred: ' + err));
 
to just simply return the dbf.recordCount to be used later in the script.
 
if I do:
DBFFile.open(dbfFilePath + '/' + csvData.DATANAME)
   .then(dbf => {
        qty = dbf.recordCount;
    })
   .catch(err => console.log('An error occurred: ' + err));
 
I simply get "undefined" later in my script.
 
If I try:
qty = DBFFile.open(dbfFilePath + '/' + csvData.DATANAME)
    .then(dbf => {
       return dbf.recordCount;
   })
   .catch(err => console.log('An error occurred: ' + err));
 
Then I get Promise {pending}
Edited by kaotkbliss
Marking as solved as I didn't end up needing this code

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to post
Share on other sites

I ended up going a different route. To actually do what I need to do later with the records I'm using a different dbf module and while it's helpfile didn't say anything about it, I found where it does in fact log the number of records in it's processing so I was able to use that.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...