Solved

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

Posted on 2001-08-02
9
703 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

691 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