FoxPro table didn't open in X# FoxPro Console

This forum is meant for questions about the Visual FoxPro Language support in X#.

User avatar
cecilchamp
Posts: 49
Joined: Wed Jun 12, 2019 1:44 pm

FoxPro table didn't open in X# FoxPro Console

Post by cecilchamp »

Still looking for Project Options...
Chris wrote:Hi Matt,
FoxProMatt_MattSlay wrote:Use

Code: Select all

FIELD LastName
Just like you do for LOCAL


This is because the X# compiler requires everything referred to in your code to be identified.

You can turn this off with a compiler option if you want to use non-declared variables.
You just need to enable the options "Enable Memvar Support" and "Enable Undeclared variables support" (in the Language page of the Project options) and then the compiler will allow using it also undeclared. It will still report a warning though, just in case you did that accidentally in code, so make sure you do not have "warnings as errors" also enabled, because this will turn the warning into an error.
FoxProMatt

FoxPro table didn't open in X# Foxo Console

Post by FoxProMatt »

Without SET DEFAULT working, you will need to specify the full path to where the DBF is located.

Just because you put it in your project folder that is not good enough. In Visual Studio developer sessions, when you run the app, it actually compiles to an EXE located and running from the Bin folder in your project, which is not your root project folder that’s why I cannot find the DBF file.
User avatar
Chris
Posts: 4845
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

FoxPro table didn't open in X# FoxPro Console

Post by Chris »

cecilchamp wrote:Still looking for Project Options...
Chris wrote:Hi Matt,
FoxProMatt_MattSlay wrote:Use

Code: Select all

FIELD LastName
Just like you do for LOCAL


This is because the X# compiler requires everything referred to in your code to be identified.

You can turn this off with a compiler option if you want to use non-declared variables.
You just need to enable the options "Enable Memvar Support" and "Enable Undeclared variables support" (in the Language page of the Project options) and then the compiler will allow using it also undeclared. It will still report a warning though, just in case you did that accidentally in code, so make sure you do not have "warnings as errors" also enabled, because this will turn the warning into an error.
Right-click on the Project name in the Solution Explorer in VS and select "Properties" from the context menu. Then navigate to the "Language" page on the left, you will find the two options there.

As for SET DEFAULT, you can simply use for now

SetDefault("C:addrdata")

or, define this in the top of your .prg file

#command SET DEFAULT TO <path> => SetDefault(<path>)

and then use in your code

SET DEFAULT TO "C:addrdata"
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
cecilchamp
Posts: 49
Joined: Wed Jun 12, 2019 1:44 pm

FoxPro table didn't open in X# FoxPro Console

Post by cecilchamp »

Okay, now I am starting to get somewhere, sort of.

Found the Language properties under the application. These were set already to the below values. Still have an issue with the USE command.

Memory Variables
Enable Memvar Support - TRUE
Enable Undeclared Variables support - TRUE

I will do the other things you mentioned with SET DEFAULT. Still need to determine why USE won't open the table.
Thanks Chris!

My entire code follows:

Code: Select all

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text

#command SET DEFAULT TO <path> => SetDefault(<path>)
#command USE <(db)>                                                     ;
             [VIA <rdd>]                                                ;
             [ALIAS <a>]                                                ;
             [<new: NEW>]                                               ;
             [<ex: EXCLUSIVE>]                                          ;
             [<sh: SHARED>]                                             ;
             [<ro: READONLY,NOUPDATE>]                                  ;
             [INDEX <(index1)> [, <(indexn)>]]                          ;
                                                                        ;
      => dbUseArea(                                                     ;
                    <.new.>, <rdd>, <(db)>, <(a)>,                      ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>        ;
                  )                                                     ;
                                                                        ;
      [; dbSetIndex( <(index1)> )]                                      ;

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
    Field LastName
    
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE address Index lfname
    FOR i = 1 to 3
        ? LastName    
    ENDFOR
	RETURN	
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

FoxPro table didn't open in X# FoxPro Console

Post by Karl-Heinz »

Hi Cecil,

About your open problem: Check via RddSetDefault() which Dbf engine is used. When i select the Foxpro dialect the default driver is still "DBFNTX". What you need is the "DBFVFP" driver.

Code: Select all

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
//    Field LastName

   ? RddSetDefault()  //  // <---- does it show"DBFNTX" ?
    
     RddSetDefault ( "DBFVFP" )  // <---- Foxpro driver 

  ? RddSetDefault()  //  // <---- must show "DBFVFP"
    
   
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE address Index lfname
    FOR i = 1 to 3
        ? LastName    
    ENDFOR
	RETURN	

regards
Karl-Heinz
FoxProMatt

FoxPro table didn't open in X# FoxPro Console

Post by FoxProMatt »

Cecil- are you sure your started with a VFP dialect project?

Right-click in the project in solution Explorer and click proprieties. You can see what the Dialect is.
User avatar
cecilchamp
Posts: 49
Joined: Wed Jun 12, 2019 1:44 pm

FoxPro table didn't open in X# FoxPro Console

Post by cecilchamp »

Yes. I picked FoxPro Console. However, I went to Dialect in Properties and found in "Visual FoxPro Compatibility- Inherit from Custom Class" was set to FALSE. Does that matter?
User avatar
cecilchamp
Posts: 49
Joined: Wed Jun 12, 2019 1:44 pm

FoxPro table didn't open in X# FoxPro Console

Post by cecilchamp »

Karl, did you mean for me to use that as a Function in the program? If yes, I got nothing back. Otherwise, I am not sure how to check which driver is being used.

Application under Properties shows:
Dialect - FoxPro
Output Type - Console Application
FoxProMatt

FoxPro table didn't open in X# FoxPro Console

Post by FoxProMatt »

Are you getting a compiler error or a runtime error?
User avatar
cecilchamp
Posts: 49
Joined: Wed Jun 12, 2019 1:44 pm

FoxPro table didn't open in X# FoxPro Console

Post by cecilchamp »

All I see is the Console black screen appear and then USE is highlighted with a Red background dot at the end of the code line with a white X in it. The note shows XSharp.RDD.RddError: 'Exception or type 'XSharp.RDD.RddError' was thrown.'

More Details follow:

XSharp.RDD.RddError
HResult=0x80131500
Message=Exception of type 'XSharp.RDD.RddError' was thrown.
Source=XSharp.RT
StackTrace:
at XSharp.RDD.DBF._dbfError(Exception ex, UInt32 iSubCode, UInt32 iGenCode, String strFunction, String strMessage, UInt32 iSeverity)
at XSharp.RDD.CDX.CdxTag.EvaluateExpressions()
at XSharp.RDD.CDX.CdxTag.Open()
at XSharp.RDD.CDX.CdxTag..ctor(CdxOrderBag oBag, Int32 nPage, String cName)
at XSharp.RDD.CDX.CdxTagList.ReadTags()
at XSharp.RDD.CDX.CdxOrderBag.Open(DbOrderInfo info)
at XSharp.RDD.CDX.CdxOrderBagList.Add(DbOrderInfo info, Boolean lStructural)
at XSharp.RDD.DBFCDX.Open(DbOpenInfo info)
at XSharp.CoreDb.<>c__DisplayClass111_0.<UseArea>b__0()
at XSharp.CoreDb.Do[T](Func`1 action)
at XSharp.CoreDb.UseArea(Boolean lNew, Type rddType, String cName, String cAlias, Boolean lShare, Boolean lReadOnly)
at XSharp.CoreDb.<>c__DisplayClass109_0.<UseArea>b__0()
at XSharp.CoreDb.Do[T](Func`1 action)
at XSharp.CoreDb.UseArea(Boolean lNew, _RddList rddList, String cName, String cAlias, Boolean lShare, Boolean lReadOnly)
at XSharp.RT.Functions.DbUseArea(__Usual[] Xs$Args)
at ConsoleApplication4.Exe.Functions.Start() in C:UserscecilsourcereposConsoleApplication4Program.prg:line 30

I think it is NOT handling the CDX file that is attached to the DBF file.

See below screen shot.

I finally figured it out. It was the CDX file. XSharp can't seem to handle it. I created a 2-record table without a CDX file and it worked just fine. Also, Since I was initially using FOR/ENDFOR, I should also have used SKIP to display the next record. It didn't matter anyway since the CDX file could not be handled. This must be part of ORDER in the USE statement that is not yet working. I had forgotten that using INDEX is for IDX individual indexes.

Here's the final code:

Code: Select all

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
    Field LastName
    
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE Names
    SCAN
        ? LastName, FirstName   
    ENDSCAN
    WAIT
    SELECT Names
    USE
	RETURN	
Attachments
X# Exception Error 2019-11-24_7-19-01.jpg
X# Exception Error 2019-11-24_7-19-01.jpg (91.81 KiB) Viewed 450 times
Post Reply