Solved

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

Posted on 2001-08-02
9
685 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
 
LVL 30

Expert Comment

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

See nietod's comment.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now