Solved

Changing Strings to Char in a DataBase

Posted on 2000-04-24
10
213 Views
Last Modified: 2010-04-04
I'm new to Delphi so any input will be a help.  The problem is that I have to access some Fields from an Access Database, then I need to put the fields into a ListBox.  The fields I'm interested in are Servers and Drives.  I can put all the fields in the Listbox but I only want the Fields that have a drive letter in the " drives " field.  The data base is rather large so changing it is not an option.

What I want is something to look like this

Servername
C
Servername
D
NextServer
C
Any servers without Drive letters I want to skip.

Here is some of the code.

procedure TForm1.ServersClick(Sender: TObject);
var
   S : string;
   D : string;
   L : string;
begin
    While not Table1.Eof do begin
    S := Table1.FieldByName ('ServerName').AsString + ', ';
    D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
      Table1.Next
      end;
0
Comment
Question by:msmouse
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2743225
hi msmouse,

this change should do it

procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;  
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;

you can also use a tquery instead of a ttable
the sql statement is then like
select servername,drives from Tablename where drives is not null

meikl
0
 
LVL 1

Author Comment

by:msmouse
ID: 2743245
Thanks for the input.  Now How can I get one Drive letter at a time.
0
 
LVL 1

Author Comment

by:msmouse
ID: 2743247
Sorry I didn't make myself clear, in the database the drives field may have multiple drive letters.

ie  cdefg
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2743269
if you mean, how to prevent the drive from being added more than once, then this will work:
procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;  
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      if Listbx1.IndexOf(d)=-1 then ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;



0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2743300
?

procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString[1]; //Cuts only the first letter
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;

meikl
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Accepted Solution

by:
lgmm earned 50 total points
ID: 2744205
i recomended that you use your list box with only the name of server, and in an edit box at right show the drive letter or the drive letter in your listbox and in the edit box the server name.

it is most easy

or in a combo box you can show two things in a row and you pick only the key that you need

lgmm
0
 

Expert Comment

by:Begli
ID: 2744821
Listening
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2746407
? did lgmm answer really helped you by your problem ?
0
 
LVL 1

Author Comment

by:msmouse
ID: 2746410
It helped somewhat but I couldn't get in to grade your answer.  I'm new here so I haven't figured out everything yet.  Is there a way to go back and accept an earlier answer?  Your advice helped the most.  Thanks.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2746456
hi msmouse,

no, there is no way back :-(
(maybe, the ex-ex customer-service can do something)
but that doesn't matter.

next time, if you've a similar situation, just reject the given (not wanted) answer, then you've the chance to grade and accept the comment as answer which helped you mostly.

for now, you've nothing to do,
i'm glad that it helped you a bit

good luck again

meikl ;-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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