Solved

C++ Builder:   open file by command line and inputBox

Posted on 2001-08-02
9
695 Views
Last Modified: 2012-06-27

DBTable->DatabaseName=AnsiString InputBox"("File routine","routine","C:\");
DBTable->TableName=InputBox"("Filename","filename","filename");
DBTable->Open();

________________________
Above code dose not work. Below code work, but the filename can not be modified during running. How to modify above code?
________________________


DBTable->DatabaseName="c:\\temp\\temp2";
DBTable->TableName="temp.db";
DBTable->Open();
0
Comment
Question by:Johncili
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
ID: 6346466
>>Above code dose not work.
Exactly what does not work.  Please give details.

Try the following for the lower code:

char data1[] = "c:\\temp\\temp2";
char data2[] = "temp.db";
DBTable->DatabaseName=data1;
DBTable->TableName=data2;
0
 
LVL 22

Expert Comment

by:nietod
ID: 6346477
DBTable->DatabaseName=InputBox"("File routine","routine","C:\");

should be

DBTable->DatabaseName=AnsiString InputBox"("File routine","routine","C:\\");

the \ character is an escape character and it is treated specially in a string literal.  If you wish to include a single \ in a string, you must actually write two \s.  this does not cause two \s to be stored, only one.  

Also note that there was an extra "AnsiString" stuck in there.
0
 

Author Comment

by:Johncili
ID: 6346516
Still it did not work.

DBTable->DatabaseName=AnsiString InputBox("File routine","routine","C:\\");

I just want to pop-up an input box, and the filename can be input.

Any one know?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Axter
ID: 6346527
You still AnsiString after the equal sign.

See nietod's comment.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6346544
its that extra "AnsiString" in the middle of the line.

I'm not sure why you think you need it.  it is like doing

int x = 5;
int y = int x; // ERROR

You don't want that "int" thrown in before the "x" on the 2nd line.

On the 2nd line the compiler knows that x is an int.

In your code, the compilers knows that InputBox() returns an AnsiString..
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6347406
better use
..AnsiString InputBox("File routine","routine","");

0
 

Expert Comment

by:sant3000
ID: 6347881
hello, the real problem is what u can't modify DatabaseName in runtime...so, u have only one way to avoid this problem.. delete DBTable object and create new one with modified DatabaseName
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6349449
O, of course you can't change name during Databas is opened
Yur must close every
connection to the database before change the path. The code will look
something like : (example change ODBC name)

LoginDatabase->Close();

ODBC ODBCChange;
/*
 Don't forget that the name ODBC_NAME must be the same as under wich you
 created it
 */
 ODBCChange.ChangePath("ODBC_NAME","c:\\database.mdb");
 
 LoginDatabase->LoginPrompt=false;
 LoginDatabase->DatabaseName = "ODBC_NAME";
 LoginDatabase->KeepConnection = true;
 LoginDatabase->Open();



0
 
LVL 30

Expert Comment

by:Axter
ID: 6360540
Johncili,
A C grade???
Ooch, that hurts...

I notice that you have the following grading record:
C C C B

Most questions should be given an 'A' grade, unless the expert fails to answer any additional questions.

If you continue to grade answers with C's and B's, experts will not want to help you in the future.

Experts do not get paid for helping you.  Please show your graditue by giving them the grade they deserve.

Thank you for the points, but in the future, please be gentel with my grading record.

Thank you
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 160
C++ Class Serialization, Encapsulation and Formatted Output 8 78
VS2015 Redefinition errors 4 67
designing in object programming 12 94
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question