Link to home
Start Free TrialLog in
Avatar of msmouse
msmouse

asked on

Changing Strings to Char in a DataBase

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;
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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
Avatar of msmouse
msmouse

ASKER

Thanks for the input.  Now How can I get one Drive letter at a time.
Avatar of msmouse

ASKER

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

ie  cdefg
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;



?

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
ASKER CERTIFIED SOLUTION
Avatar of lgmm
lgmm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Listening
? did lgmm answer really helped you by your problem ?
Avatar of msmouse

ASKER

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.
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 ;-)